@internetarchive/collection-browser 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ import './sort-filter-bar/sort-filter-bar';
11
11
  import './collection-facets';
12
12
  import './circular-activity-indicator';
13
13
  import './sort-filter-bar/sort-filter-bar';
14
- import { SortField, SortFieldToMetadataField, getDefaultSelectedFacets, prefixFilterAggregationKeys, MetadataFieldToSortField, } from './models';
14
+ import { SortField, getDefaultSelectedFacets, prefixFilterAggregationKeys, sortOptionFromAPIString, SORT_OPTIONS, } from './models';
15
15
  import { RestorationStateHandler, } from './restoration-state-handler';
16
16
  import chevronIcon from './assets/img/icons/chevron';
17
17
  import './empty-placeholder';
@@ -442,13 +442,19 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
442
442
  });
443
443
  }
444
444
  selectedSortChanged() {
445
- if ([SortField.default, SortField.relevance].includes(this.selectedSort)) {
445
+ var _a;
446
+ const sortOption = SORT_OPTIONS[this.selectedSort];
447
+ if (!sortOption.handledBySearchService) {
446
448
  this.sortParam = null;
447
449
  return;
448
450
  }
449
- const sortField = SortFieldToMetadataField[this.selectedSort];
451
+ // If the sort option specified in the URL is unrecognized, we just use it as-is
452
+ const urlSortParam = new URL(window.location.href).searchParams.get('sort');
453
+ const sortField = (_a = sortOption.searchServiceKey) !== null && _a !== void 0 ? _a : urlSortParam === null || urlSortParam === void 0 ? void 0 : urlSortParam.replace(/^-/, '');
454
+ // If the sort direction is still null at this point, then we assume ascending
455
+ // (i.e., it was unrecognized and had no directional flag)
450
456
  if (!this.sortDirection)
451
- this.sortDirection = 'desc';
457
+ this.sortDirection = 'asc';
452
458
  if (!sortField)
453
459
  return;
454
460
  this.sortParam = { field: sortField, direction: this.sortDirection };
@@ -953,22 +959,21 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
953
959
  }
954
960
  }
955
961
  persistState() {
956
- var _a, _b, _c, _d, _e;
962
+ var _a, _b, _c, _d;
957
963
  const restorationState = {
958
964
  displayMode: this.displayMode,
959
965
  searchType: this.searchType,
960
- sortParam: (_a = this.sortParam) !== null && _a !== void 0 ? _a : undefined,
961
966
  selectedSort: this.selectedSort,
962
- sortDirection: (_b = this.sortDirection) !== null && _b !== void 0 ? _b : undefined,
963
- selectedFacets: (_c = this.selectedFacets) !== null && _c !== void 0 ? _c : getDefaultSelectedFacets(),
967
+ sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
968
+ selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
964
969
  baseQuery: this.baseQuery,
965
970
  currentPage: this.currentPage,
966
971
  titleQuery: this.titleQuery,
967
972
  creatorQuery: this.creatorQuery,
968
973
  minSelectedDate: this.minSelectedDate,
969
974
  maxSelectedDate: this.maxSelectedDate,
970
- selectedTitleFilter: (_d = this.selectedTitleFilter) !== null && _d !== void 0 ? _d : undefined,
971
- selectedCreatorFilter: (_e = this.selectedCreatorFilter) !== null && _e !== void 0 ? _e : undefined,
975
+ selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
976
+ selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
972
977
  };
973
978
  this.restorationStateHandler.persistState(restorationState);
974
979
  }
@@ -1429,7 +1434,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1429
1434
  else if (!['asc', 'desc'].includes(dir)) {
1430
1435
  dir = 'asc';
1431
1436
  }
1432
- const sortField = MetadataFieldToSortField[field];
1437
+ const sortOption = sortOptionFromAPIString(field);
1438
+ const sortField = sortOption.field;
1433
1439
  if (sortField && sortField !== SortField.default) {
1434
1440
  this.defaultSortField = sortField;
1435
1441
  this.defaultSortDirection = dir;