Skip to content

Commit f7c5614

Browse files
authored
WEBDEV-8186 Implement new single-dropdown sort bar (#558)
* Remove desktop-style sort selectors in favor of one dropdown everywhere * Update unit tests * Clean up some now-unused pieces of the sort bar component * Give sort direction toggle clearer button styling * Remove unused props from main sort bar template * Update sort direction styling slightly * Remove some obsolete logging stmts * Fix bug where sort always defaults to relevance * Clarify the labels for the sort direction button * Don't show unavailable sort option as dropdown label * Show an appropriate default sort while loading collections * Remove some unused imports * Improve code clarity + small fix for TV special case
1 parent 1340c83 commit f7c5614

File tree

6 files changed

+225
-1229
lines changed

6 files changed

+225
-1229
lines changed

src/collection-browser.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ import { updateSelectedFacetBucket } from './utils/facet-utils';
7575
import chevronIcon from './assets/img/icons/chevron';
7676
import { srOnlyStyle } from './styles/sr-only';
7777
import { sha1 } from './utils/sha1';
78-
import { log } from './utils/log';
7978
import type { PlaceholderType } from './empty-placeholder';
8079
import type { ManageBar } from './manage/manage-bar';
8180
import type { SmartFacetBar } from './collection-facets/smart-facets/smart-facet-bar';
@@ -858,21 +857,14 @@ export class CollectionBrowser
858857
if (this.suppressSortBar) return nothing;
859858

860859
// Determine the set of sortable fields that should be shown in the sort bar
861-
let defaultViewSort = SortField.weeklyview;
862-
let defaultDateSort = SortField.date;
863860
let sortFieldAvailability = defaultSortAvailability;
864861

865-
// We adjust the sort options for a couple of special cases...
862+
// We adjust the available sort options for a couple of special cases...
866863
if (this.withinCollection?.startsWith('fav-')) {
867-
// When viewing a fav- collection, we include the Date Favorited option and show
868-
// it as the default in the date dropdown.
869-
defaultDateSort = SortField.datefavorited;
864+
// When viewing a fav- collection, we include the Date Favorited option as the default
870865
sortFieldAvailability = favoritesSortAvailability;
871866
} else if (!this.withinCollection && this.searchType === SearchType.TV) {
872-
// When viewing TV search results, we default the views dropdown to All-time Views
873-
// and exclude several of the usual date sort options.
874-
defaultViewSort = SortField.alltimeview;
875-
defaultDateSort = SortField.datearchived;
867+
// When viewing TV search results, we exclude several of the usual date sort options.
876868
sortFieldAvailability = tvSortAvailability;
877869
}
878870

@@ -883,16 +875,13 @@ export class CollectionBrowser
883875
<sort-filter-bar
884876
.defaultSortField=${this.defaultSortField}
885877
.defaultSortDirection=${this.defaultSortDirection}
886-
.defaultViewSort=${defaultViewSort}
887-
.defaultDateSort=${defaultDateSort}
888878
.selectedSort=${this.selectedSort}
889879
.sortDirection=${this.sortDirection}
890880
.sortFieldAvailability=${sortFieldAvailability}
891881
.displayMode=${this.displayMode}
892882
.selectedTitleFilter=${this.selectedTitleFilter}
893883
.selectedCreatorFilter=${this.selectedCreatorFilter}
894884
.prefixFilterCountMap=${this.dataSource.prefixFilterCountMap}
895-
.resizeObserver=${this.resizeObserver}
896885
.enableSortOptionsSlot=${this.enableSortOptionsSlot}
897886
.suppressDisplayModes=${this.suppressDisplayModes}
898887
@sortChanged=${this.userChangedSort}
@@ -1643,7 +1632,6 @@ export class CollectionBrowser
16431632
dataSource: CollectionBrowserDataSourceInterface,
16441633
queryState: CollectionBrowserQueryState,
16451634
): Promise<void> {
1646-
log('Installing data source & query state in CB:', dataSource, queryState);
16471635
if (this.dataSource) this.removeController(this.dataSource);
16481636
this.dataSource = dataSource;
16491637
this.addController(this.dataSource);
@@ -1772,6 +1760,17 @@ export class CollectionBrowser
17721760
this.applyDefaultProfileSort();
17731761
}
17741762

1763+
if (changed.has('withinCollection') && this.withinCollection) {
1764+
// Set a sensible default collection sort while we load results, which we will later
1765+
// adjust based on any sort-by metadata once the response arrives.
1766+
if (!this.baseQuery) {
1767+
this.defaultSortField = this.withinCollection.startsWith('fav-')
1768+
? SortField.datefavorited
1769+
: SortField.weeklyview;
1770+
this.defaultSortDirection = 'desc';
1771+
}
1772+
}
1773+
17751774
if (changed.has('baseQuery')) {
17761775
this.emitBaseQueryChanged();
17771776
}
@@ -2259,12 +2258,8 @@ export class CollectionBrowser
22592258
this.displayMode = restorationState.displayMode;
22602259
if (!this.suppressURLSinParam && restorationState.searchType != null)
22612260
this.searchType = restorationState.searchType;
2262-
this.selectedSort =
2263-
restorationState.selectedSort ??
2264-
this.defaultSortField ??
2265-
SortField.default;
2266-
this.sortDirection =
2267-
restorationState.sortDirection ?? this.defaultSortDirection ?? null;
2261+
this.selectedSort = restorationState.selectedSort ?? SortField.default;
2262+
this.sortDirection = restorationState.sortDirection ?? null;
22682263
this.selectedTitleFilter = restorationState.selectedTitleFilter ?? null;
22692264
this.selectedCreatorFilter = restorationState.selectedCreatorFilter ?? null;
22702265
this.selectedFacets = restorationState.selectedFacets;

src/data-source/collection-browser-data-source.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
import type { CollectionBrowserDataSourceInterface } from './collection-browser-data-source-interface';
3333
import type { CollectionBrowserSearchInterface } from './collection-browser-query-state';
3434
import { sha1 } from '../utils/sha1';
35-
import { log } from '../utils/log';
3635
import { mergeSelectedFacets } from '../utils/facet-utils';
3736

3837
export class CollectionBrowserDataSource
@@ -250,7 +249,6 @@ export class CollectionBrowserDataSource
250249
* @inheritdoc
251250
*/
252251
reset(): void {
253-
log('Resetting CB data source');
254252
this.pages = {};
255253
this.aggregations = {};
256254
this.histogramAggregation = undefined;
@@ -1120,15 +1118,20 @@ export class CollectionBrowserDataSource
11201118

11211119
let sortParams = this.host.sortParam ? [this.host.sortParam] : [];
11221120
// TODO eventually the PPS should handle these defaults natively
1123-
const isDefaultProfileSort =
1124-
withinProfile && this.host.selectedSort === SortField.default;
1125-
if (isDefaultProfileSort && this.host.defaultSortField) {
1121+
const isDefaultSort = this.host.selectedSort === SortField.default;
1122+
const isTVSearch = this.host.searchType === SearchType.TV;
1123+
const isDefaultTVSort = isTVSearch && isDefaultSort;
1124+
const isDefaultProfileSort = withinProfile && isDefaultSort;
1125+
if (
1126+
(isDefaultProfileSort || isDefaultTVSort) &&
1127+
this.host.defaultSortField
1128+
) {
11261129
const sortOption = SORT_OPTIONS[this.host.defaultSortField];
11271130
if (sortOption.searchServiceKey) {
11281131
sortParams = [
11291132
{
11301133
field: sortOption.searchServiceKey,
1131-
direction: 'desc',
1134+
direction: this.host.defaultSortDirection ?? 'desc',
11321135
},
11331136
];
11341137
}

src/data-source/collection-browser-query-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface CollectionBrowserSearchInterface
3939
isTVCollection: boolean;
4040
readonly sortParam: SortParam | null;
4141
readonly defaultSortField: SortField | null;
42+
readonly defaultSortDirection: SortDirection | null;
4243
readonly facetLoadStrategy: FacetLoadStrategy;
4344
readonly initialPageNumber: number;
4445
readonly maxPagesToManage: number;

0 commit comments

Comments
 (0)