Skip to content

Commit

Permalink
Merge branch 'fix-default-sort-and-alignment-issue-7.6' into fix-defa…
Browse files Browse the repository at this point in the history
…ult-sort-and-alignment-issue-main
  • Loading branch information
YanaDePauw committed Jan 22, 2025
2 parents b08edf1 + 6199301 commit 94045f0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('SearchConfigurationService', () => {
service.getCurrentSort(defaults.pagination.id, {} as any);
});
it('should call getCurrentSort on the paginationService with the provided id and sort options', () => {
expect((service as any).paginationService.getCurrentSort).toHaveBeenCalledWith(defaults.pagination.id, {});
expect((service as any).paginationService.getCurrentSort).toHaveBeenCalledWith(defaults.pagination.id, {}, true);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/core/shared/search/search-configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class SearchConfigurationService implements OnDestroy {
* @returns {Observable<string>} Emits the current sorting settings
*/
getCurrentSort(paginationId: string, defaultSort: SortOptions): Observable<SortOptions> {
return this.paginationService.getCurrentSort(paginationId, defaultSort);
return this.paginationService.getCurrentSort(paginationId, defaultSort, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('MyDSpaceConfigurationService', () => {
service.getCurrentSort('page-id', defaults.sort);
});
it('should call getCurrentSort on the paginationService with the provided id and sort options', () => {
expect((service as any).paginationService.getCurrentSort).toHaveBeenCalledWith('page-id', defaults.sort);
expect((service as any).paginationService.getCurrentSort).toHaveBeenCalledWith('page-id', defaults.sort, true);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ <h2 class="comcol-browse-label">{{'browse.comcol.head' | translate}}</h2>
<div class="list-group list-group-horizontal" role="tablist">
<a *ngFor="let option of allOptions"
[attr.aria-current]="(currentOption$ | async)?.id === option.id"
class="list-group-item"
class="d-flex list-group-item"
role="tab"
[routerLink]="option.routerLink"
[queryParams]="option.params"
[class.active]="(currentOption$ | async)?.id === option.id">
{{ option.label | translate }}
<span class="my-auto">{{ option.label | translate }}</span>
</a>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/search/search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function configureSearchComponentTestingModule(compType, additionalDeclar
getConfigurationSearchConfig: observableOf(searchConfig),
getCurrentConfiguration: observableOf('default'),
getCurrentScope: observableOf('test-id'),
getCurrentSort: observableOf(sortOptionsList[0]),
getCurrentSort: observableOf(sortOptionsList[1]),
updateFixedFilter: jasmine.createSpy('updateFixedFilter'),
setPaginationId: jasmine.createSpy('setPaginationId'),
});
Expand Down Expand Up @@ -297,13 +297,13 @@ describe('SearchComponent', () => {
const expectedSearchOptions = Object.assign(paginatedSearchOptions$.value, {
configuration: 'default',
scope: '',
sort: sortOptionsList[0],
sort: sortOptionsList[1],
});
expect(comp.currentConfiguration$).toBeObservable(cold('b', {
b: 'default',
}));
expect(comp.currentSortOptions$).toBeObservable(cold('b', {
b: sortOptionsList[0],
b: sortOptionsList[1],
}));
expect(comp.sortOptionsList$).toBeObservable(cold('b', {
b: sortOptionsList,
Expand Down
11 changes: 6 additions & 5 deletions src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,15 @@ export class SearchComponent implements OnDestroy, OnInit {
map((searchConfig: SearchConfig) => this.searchConfigService.getConfigurationSortOptions(searchConfig)),
distinctUntilChanged(),
);
const sortOption$: Observable<SortOptions> = searchSortOptions$.pipe(
switchMap((searchSortOptions: SortOptions[]) => {
const defaultSort: SortOptions = searchSortOptions[0];
return this.searchConfigService.getCurrentSort(this.paginationId, defaultSort);
const searchOptions$: Observable<PaginatedSearchOptions> = this.getSearchOptions().pipe(distinctUntilChanged());

const sortOption$: Observable<SortOptions> = combineLatest([searchSortOptions$, searchOptions$]).pipe(
switchMap(([searchSortOptions, searchOptions]: [SortOptions[], PaginatedSearchOptions]) => {
const defaultSortOption = hasValue(searchOptions.sort?.field) && hasValue(searchOptions.sort?.field) ? searchOptions.sort : searchSortOptions[0];
return this.searchConfigService.getCurrentSort(this.paginationId, defaultSortOption);
}),
distinctUntilChanged(),
);
const searchOptions$: Observable<PaginatedSearchOptions> = this.getSearchOptions().pipe(distinctUntilChanged());

this.subs.push(combineLatest([configuration$, searchSortOptions$, searchOptions$, sortOption$, this.currentScope$]).pipe(
filter(([configuration, searchSortOptions, searchOptions, sortOption, scope]: [string, SortOptions[], PaginatedSearchOptions, SortOptions, string]) => {
Expand Down

0 comments on commit 94045f0

Please sign in to comment.