Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[angular] rework sorting with signal based sort state. #25047

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions generators/angular/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,18 @@ exports[`generator - angular gateway-jwt-skipUserManagement(true)-withAdminUi(fa
"clientRoot/src/main/webapp/app/shared/sort/sort-by.directive.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort-state.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.directive.spec.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.directive.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.service.spec.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.service.ts": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1366,12 +1372,18 @@ exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDepend
"clientRoot/src/main/webapp/app/shared/sort/sort-by.directive.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort-state.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.directive.spec.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.directive.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.service.spec.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.service.ts": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2019,12 +2031,18 @@ exports[`generator - angular microservice-jwt-skipUserManagement(false)-withAdmi
"clientRoot/src/main/webapp/app/shared/sort/sort-by.directive.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort-state.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.directive.spec.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.directive.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.service.spec.ts": {
"stateCleared": "modified",
},
"clientRoot/src/main/webapp/app/shared/sort/sort.service.ts": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2684,12 +2702,18 @@ exports[`generator - angular microservice-oauth2-withAdminUi(true)-skipJhipsterD
"src/main/webapp/app/shared/sort/sort-by.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort-state.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.ts": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -3757,12 +3781,18 @@ exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi(
"src/main/webapp/app/shared/sort/sort-by.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort-state.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.ts": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -4407,12 +4437,18 @@ exports[`generator - angular monolith-oauth2-withAdminUi(false)-skipJhipsterDepe
"src/main/webapp/app/shared/sort/sort-by.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort-state.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.ts": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -5066,12 +5102,18 @@ exports[`generator - angular monolith-session-skipUserManagement(true)-withAdmin
"src/main/webapp/app/shared/sort/sort-by.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort-state.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.directive.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.spec.ts": {
"stateCleared": "modified",
},
"src/main/webapp/app/shared/sort/sort.service.ts": {
"stateCleared": "modified",
},
Expand Down
8 changes: 5 additions & 3 deletions generators/angular/files-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,13 @@ export const files = {
'shared/date/format-medium-date.pipe.ts',
'shared/date/format-medium-datetime.pipe.ts',
'shared/sort/index.ts',
'shared/sort/sort-by.directive.ts',
'shared/sort/sort-by.directive.spec.ts',
'shared/sort/sort-state.ts',
'shared/sort/sort.directive.spec.ts',
'shared/sort/sort.directive.ts',
'shared/sort/sort.service.spec.ts',
'shared/sort/sort.service.ts',
'shared/sort/sort-by.directive.ts',
'shared/pagination/index.ts',
'shared/pagination/item-count.component.ts',
// alert service code
Expand Down Expand Up @@ -411,8 +415,6 @@ export const files = {
'shared/alert/alert-error.component.spec.ts',
'shared/date/format-medium-date.pipe.spec.ts',
'shared/date/format-medium-datetime.pipe.spec.ts',
'shared/sort/sort.directive.spec.ts',
'shared/sort/sort-by.directive.spec.ts',
'shared/pagination/item-count.component.spec.ts',
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<div class="table-responsive table-entities" id="entities">
<table class="table table-striped" aria-describedby="page-heading">
<thead>
<tr <%= jhiPrefix %>Sort [(predicate)]="predicate" [(ascending)]="ascending" (sortChange)="navigateToWithComponentValues()">
<tr <%= jhiPrefix %>Sort [sortState]="sortState" (sortChange)="navigateToWithComponentValues($event)">
<%_ for (const field of fields.filter(field => !field.hidden)) { _%>
<th scope="col" <%= jhiPrefix %>SortBy="<%= field.fieldName %>">
<div class="d-flex">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ import { of } from 'rxjs';
import { <%= entityAngularName %>Service } from '../service/<%= entityFileName %>.service';

import { <%= entityAngularName %>Component } from './<%= entityFileName %>.component';
<%_ if (!paginationNo) { _%>
import SpyInstance = jest.SpyInstance;
<%_ } _%>

describe('<%= entityAngularName %> Management Component', () => {
let comp: <%= entityAngularName %>Component;
let fixture: ComponentFixture<<%= entityAngularName %>Component>;
let service: <%= entityAngularName %>Service;
<%_ if (!paginationNo) { _%>
let routerNavigateSpy: SpyInstance<Promise<boolean>>;
<%_ } _%>

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -89,9 +85,7 @@ describe('<%= entityAngularName %> Management Component', () => {
fixture = TestBed.createComponent(<%= entityAngularName %>Component);
comp = fixture.componentInstance;
service = TestBed.inject(<%= entityAngularName %>Service);
<%_ if (!paginationNo) { _%>
routerNavigateSpy = jest.spyOn(comp.router, 'navigate');
<%_ } _%>

const headers = new HttpHeaders();
jest.spyOn(service, 'query').mockReturnValue(
Expand Down Expand Up @@ -122,6 +116,19 @@ describe('<%= entityAngularName %> Management Component', () => {
expect(<%= primaryKey.name %>).toBe(entity.<%= primaryKey.name %>);
});
});

it('should calculate the sort attribute for a non-id attribute', () => {
// WHEN
comp.navigateToWithComponentValues({ predicate: 'non-existing-column', order: 'asc' });

// THEN
expect(routerNavigateSpy).toHaveBeenLastCalledWith(expect.anything(),
expect.objectContaining({
queryParams: expect.objectContaining({
sort: ['non-existing-column,asc']
})
}));
});
<%_ if (!paginationNo) { _%>

it('should load a page', () => {
Expand All @@ -140,23 +147,6 @@ describe('<%= entityAngularName %> Management Component', () => {
expect(service.query).toHaveBeenLastCalledWith(expect.objectContaining({ sort: ['<%- primaryKey.fields.map(field => field.fieldName).join(',') %>,<%= order %>'] }));
});

it('should calculate the sort attribute for a non-id attribute', () => {

// GIVEN
comp.predicate = 'non-existing-column';
comp.ascending = true;

// WHEN
comp.navigateToWithComponentValues();

// THEN
expect(routerNavigateSpy).toHaveBeenLastCalledWith(expect.anything(),
expect.objectContaining({
queryParams: expect.objectContaining({
sort: ['non-existing-column,asc']
})
}));
});
<%_ if (paginationInfiniteScroll) { _%>

it('should re-initialize the page', () => {
Expand Down
Loading
Loading