@internetarchive/collection-browser 1.6.0 → 1.7.1-alpha.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.
@@ -76,6 +76,8 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
76
76
  private mobileView;
77
77
  private mobileFacetsVisible;
78
78
  private contentWidth?;
79
+ private defaultSortField;
80
+ private defaultSortDirection;
79
81
  private placeholderType;
80
82
  private prefixFilterCountMap;
81
83
  private contentContainer;
@@ -357,6 +359,11 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
357
359
  facetClickHandler({ detail: { key, state: facetState, negative }, }: CustomEvent<FacetEventDetails>): void;
358
360
  private fetchFacets;
359
361
  private scrollToPage;
362
+ /**
363
+ * Whether sorting by relevance makes sense for the current state.
364
+ * Currently equivalent to having a non-empty query.
365
+ */
366
+ private get isRelevanceSortAvailable();
360
367
  /**
361
368
  * Whether a search may be performed in the current state of the component.
362
369
  * This is only true if the search service is defined, and either
@@ -400,6 +407,12 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
400
407
  */
401
408
  fetchPage(pageNumber: number, numInitialPages?: number): Promise<void>;
402
409
  private preloadCollectionNames;
410
+ /**
411
+ * Applies any default sort option for the current collection, by checking
412
+ * for one in the collection's metadata. If none is found, defaults to sorting
413
+ * descending by weekly views.
414
+ */
415
+ private applyDefaultCollectionSort;
403
416
  /**
404
417
  * This is useful for determining whether we need to reload the scroller.
405
418
  *
@@ -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, } from './models';
14
+ import { SortField, SortFieldToMetadataField, getDefaultSelectedFacets, prefixFilterAggregationKeys, MetadataFieldToSortField, } from './models';
15
15
  import { RestorationStateHandler, } from './restoration-state-handler';
16
16
  import chevronIcon from './assets/img/icons/chevron';
17
17
  import './empty-placeholder';
@@ -24,7 +24,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
24
24
  this.baseImageUrl = 'https://archive.org';
25
25
  this.searchType = SearchType.METADATA;
26
26
  this.sortParam = null;
27
- this.selectedSort = SortField.relevance;
27
+ this.selectedSort = SortField.default;
28
28
  this.selectedTitleFilter = null;
29
29
  this.selectedCreatorFilter = null;
30
30
  this.sortDirection = null;
@@ -63,6 +63,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
63
63
  this.fullYearAggregationLoading = false;
64
64
  this.mobileView = false;
65
65
  this.mobileFacetsVisible = false;
66
+ this.defaultSortField = SortField.relevance;
67
+ this.defaultSortDirection = null;
66
68
  this.placeholderType = null;
67
69
  this.prefixFilterCountMap = {};
68
70
  /**
@@ -216,7 +218,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
216
218
  if (sort) {
217
219
  this.sortParam = null;
218
220
  this.sortDirection = null;
219
- this.selectedSort = SortField.relevance;
221
+ this.selectedSort = SortField.default;
220
222
  }
221
223
  }
222
224
  /**
@@ -402,8 +404,11 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
402
404
  get sortFilterBarTemplate() {
403
405
  return html `
404
406
  <sort-filter-bar
407
+ .defaultSortField=${this.defaultSortField}
408
+ .defaultSortDirection=${this.defaultSortDirection}
405
409
  .selectedSort=${this.selectedSort}
406
410
  .sortDirection=${this.sortDirection}
411
+ .showRelevance=${this.isRelevanceSortAvailable}
407
412
  .displayMode=${this.displayMode}
408
413
  .selectedTitleFilter=${this.selectedTitleFilter}
409
414
  .selectedCreatorFilter=${this.selectedCreatorFilter}
@@ -437,7 +442,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
437
442
  });
438
443
  }
439
444
  selectedSortChanged() {
440
- if (this.selectedSort === 'relevance') {
445
+ if ([SortField.default, SortField.relevance].includes(this.selectedSort)) {
441
446
  this.sortParam = null;
442
447
  return;
443
448
  }
@@ -868,6 +873,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
868
873
  return this._initialSearchCompletePromise;
869
874
  }
870
875
  async handleQueryChange() {
876
+ var _a;
871
877
  // only reset if the query has actually changed
872
878
  if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
873
879
  return;
@@ -892,6 +898,10 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
892
898
  this.infiniteScroller.itemCount = this.estimatedTileCount;
893
899
  this.infiniteScroller.reload();
894
900
  }
901
+ if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
902
+ this.defaultSortField = SortField.relevance;
903
+ this.defaultSortDirection = null;
904
+ }
895
905
  if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
896
906
  this.scrollToPage(this.initialPageNumber);
897
907
  }
@@ -928,7 +938,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
928
938
  this.displayMode = restorationState.displayMode;
929
939
  if (restorationState.searchType != null)
930
940
  this.searchType = restorationState.searchType;
931
- this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.relevance;
941
+ this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
932
942
  this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
933
943
  this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
934
944
  this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
@@ -1221,6 +1231,14 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1221
1231
  }, 0);
1222
1232
  });
1223
1233
  }
1234
+ /**
1235
+ * Whether sorting by relevance makes sense for the current state.
1236
+ * Currently equivalent to having a non-empty query.
1237
+ */
1238
+ get isRelevanceSortAvailable() {
1239
+ var _a;
1240
+ return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1241
+ }
1224
1242
  /**
1225
1243
  * Whether a search may be performed in the current state of the component.
1226
1244
  * This is only true if the search service is defined, and either
@@ -1343,6 +1361,9 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1343
1361
  this.totalResults = success.response.totalResults;
1344
1362
  if (this.withinCollection) {
1345
1363
  this.collectionInfo = success.response.collectionExtraInfo;
1364
+ // For collections, we want the UI to respect the default sort option
1365
+ // which can be specified in metadata, or otherwise assumed to be week:desc
1366
+ this.applyDefaultCollectionSort(success.response.collectionExtraInfo);
1346
1367
  }
1347
1368
  const { results, collectionTitles } = success.response;
1348
1369
  if (results && results.length > 0) {
@@ -1383,6 +1404,36 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1383
1404
  const collectionIdsArray = Array.from(new Set(collectionIds));
1384
1405
  (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1385
1406
  }
1407
+ /**
1408
+ * Applies any default sort option for the current collection, by checking
1409
+ * for one in the collection's metadata. If none is found, defaults to sorting
1410
+ * descending by weekly views.
1411
+ */
1412
+ applyDefaultCollectionSort(collectionInfo) {
1413
+ var _a, _b;
1414
+ if (this.baseQuery) {
1415
+ // If there's a query set, then we default to relevance sorting regardless of
1416
+ // the collection metadata-specified sort.
1417
+ this.defaultSortField = SortField.relevance;
1418
+ this.defaultSortDirection = null;
1419
+ return;
1420
+ }
1421
+ const defaultSort = (_b = (_a = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _a === void 0 ? void 0 : _a['sort-by']) !== null && _b !== void 0 ? _b : '-week';
1422
+ // Account for both -field and field:dir formats
1423
+ let [field, dir] = defaultSort.split(':');
1424
+ if (field.startsWith('-')) {
1425
+ field = field.slice(1);
1426
+ dir = 'desc';
1427
+ }
1428
+ else if (!['asc', 'desc'].includes(dir)) {
1429
+ dir = 'asc';
1430
+ }
1431
+ const sortField = MetadataFieldToSortField[field];
1432
+ if (sortField && sortField !== SortField.default) {
1433
+ this.defaultSortField = sortField;
1434
+ this.defaultSortDirection = dir;
1435
+ }
1436
+ }
1386
1437
  /**
1387
1438
  * This is useful for determining whether we need to reload the scroller.
1388
1439
  *
@@ -2100,6 +2151,12 @@ __decorate([
2100
2151
  __decorate([
2101
2152
  state()
2102
2153
  ], CollectionBrowser.prototype, "contentWidth", void 0);
2154
+ __decorate([
2155
+ state()
2156
+ ], CollectionBrowser.prototype, "defaultSortField", void 0);
2157
+ __decorate([
2158
+ state()
2159
+ ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2103
2160
  __decorate([
2104
2161
  state()
2105
2162
  ], CollectionBrowser.prototype, "placeholderType", void 0);