@internetarchive/collection-browser 0.4.16-alpha.15 → 0.4.16-alpha.16

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.
@@ -30,6 +30,8 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
30
30
  sortDirection: SortDirection | null;
31
31
  pageSize: number;
32
32
  resizeObserver?: SharedResizeObserverInterface;
33
+ titleQuery?: string;
34
+ creatorQuery?: string;
33
35
  currentPage?: number;
34
36
  minSelectedDate?: string;
35
37
  maxSelectedDate?: string;
@@ -138,16 +140,16 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
138
140
  private sendSortByAnalytics;
139
141
  private selectedSortChanged;
140
142
  private displayModeChanged;
141
- private get titleQuery();
142
- private get creatorQuery();
143
143
  /** Send Analytics when sorting by title's first letter
144
144
  * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
145
145
  * */
146
146
  private sendFilterByTitleAnalytics;
147
+ private selectedTitleLetterChanged;
147
148
  /** Send Analytics when filtering by creator's first letter
148
149
  * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
149
150
  * */
150
151
  private sendFilterByCreatorAnalytics;
152
+ private selectedCreatorLetterChanged;
151
153
  private titleLetterSelected;
152
154
  private creatorLetterSelected;
153
155
  private get mobileFacetsTemplate();
@@ -183,8 +185,12 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
183
185
  private persistState;
184
186
  private doInitialPageFetch;
185
187
  private get filterMap();
188
+ /** The base query joined with any title/creator letter filters */
189
+ private get filteredQuery();
186
190
  /** The full query, including year facets and date range clauses */
187
191
  private get fullQuery();
192
+ /** The full query without any title/creator letter filters */
193
+ private get fullQueryWithoutAlphaFilters();
188
194
  /**
189
195
  * Generates a query string for the given facets
190
196
  *
@@ -150,6 +150,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
150
150
  if (letterFilters) {
151
151
  this.selectedTitleFilter = null;
152
152
  this.selectedCreatorFilter = null;
153
+ this.titleQuery = undefined;
154
+ this.creatorQuery = undefined;
153
155
  }
154
156
  if (sort) {
155
157
  this.sortParam = null;
@@ -191,8 +193,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
191
193
  if (!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
192
194
  this.placeholderType = 'empty-query';
193
195
  }
194
- else if (!this.searchResultsLoading &&
195
- (this.totalResults === 0 || !this.searchService)) {
196
+ if ((!this.searchResultsLoading && this.totalResults === 0) ||
197
+ !this.searchService) {
196
198
  this.placeholderType = 'null-result';
197
199
  }
198
200
  if (this.queryErrorMessage) {
@@ -327,16 +329,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
327
329
  });
328
330
  }
329
331
  }
330
- get titleQuery() {
331
- return this.selectedTitleFilter
332
- ? `firstTitle:${this.selectedTitleFilter}`
333
- : undefined;
334
- }
335
- get creatorQuery() {
336
- return this.selectedCreatorFilter
337
- ? `firstCreator:${this.selectedCreatorFilter}`
338
- : undefined;
339
- }
340
332
  /** Send Analytics when sorting by title's first letter
341
333
  * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
342
334
  * */
@@ -354,6 +346,11 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
354
346
  : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
355
347
  });
356
348
  }
349
+ selectedTitleLetterChanged() {
350
+ this.titleQuery = this.selectedTitleFilter
351
+ ? `firstTitle:${this.selectedTitleFilter}`
352
+ : undefined;
353
+ }
357
354
  /** Send Analytics when filtering by creator's first letter
358
355
  * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
359
356
  * */
@@ -371,13 +368,20 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
371
368
  : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
372
369
  });
373
370
  }
371
+ selectedCreatorLetterChanged() {
372
+ this.creatorQuery = this.selectedCreatorFilter
373
+ ? `firstCreator:${this.selectedCreatorFilter}`
374
+ : undefined;
375
+ }
374
376
  titleLetterSelected(e) {
375
377
  this.selectedCreatorFilter = null;
376
378
  this.selectedTitleFilter = e.detail.selectedLetter;
379
+ this.selectedTitleLetterChanged();
377
380
  }
378
381
  creatorLetterSelected(e) {
379
382
  this.selectedTitleFilter = null;
380
383
  this.selectedCreatorFilter = e.detail.selectedLetter;
384
+ this.selectedCreatorLetterChanged();
381
385
  }
382
386
  get mobileFacetsTemplate() {
383
387
  return html `
@@ -418,7 +422,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
418
422
  .selectedFacets=${this.selectedFacets}
419
423
  .collectionNameCache=${this.collectionNameCache}
420
424
  .showHistogramDatePicker=${this.showHistogramDatePicker}
421
- .query=${this.baseQuery}
425
+ .query=${this.filteredQuery}
422
426
  .filterMap=${this.filterMap}
423
427
  .modalManager=${this.modalManager}
424
428
  ?collapsableFacets=${this.mobileView}
@@ -506,8 +510,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
506
510
  if (changed.has('baseQuery') ||
507
511
  changed.has('minSelectedDate') ||
508
512
  changed.has('maxSelectedDate') ||
509
- changed.has('selectedFacets') ||
510
- changed.has('searchService')) {
513
+ changed.has('selectedFacets')) {
511
514
  this.refreshLetterCounts();
512
515
  }
513
516
  if (changed.has('selectedSort') || changed.has('sortDirection')) {
@@ -517,9 +520,11 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
517
520
  }
518
521
  if (changed.has('selectedTitleFilter')) {
519
522
  this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
523
+ this.selectedTitleLetterChanged();
520
524
  }
521
525
  if (changed.has('selectedCreatorFilter')) {
522
526
  this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
527
+ this.selectedCreatorLetterChanged();
523
528
  }
524
529
  if (changed.has('baseQuery') ||
525
530
  changed.has('searchType') ||
@@ -724,16 +729,20 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
724
729
  }
725
730
  }
726
731
  }
727
- // Add any letter filters
728
- if (this.selectedTitleFilter) {
729
- builder.addFilter('firstTitle', this.selectedTitleFilter, FilterConstraint.INCLUDE);
730
- }
731
- if (this.selectedCreatorFilter) {
732
- builder.addFilter('firstCreator', this.selectedCreatorFilter, FilterConstraint.INCLUDE);
733
- }
734
732
  const filterMap = builder.build();
735
733
  return filterMap;
736
734
  }
735
+ /** The base query joined with any title/creator letter filters */
736
+ get filteredQuery() {
737
+ if (!this.baseQuery)
738
+ return undefined;
739
+ let filteredQuery = this.baseQuery.trim();
740
+ const { sortFilterQueries } = this;
741
+ if (sortFilterQueries) {
742
+ filteredQuery += ` AND ${sortFilterQueries}`;
743
+ }
744
+ return filteredQuery.trim();
745
+ }
737
746
  /** The full query, including year facets and date range clauses */
738
747
  get fullQuery() {
739
748
  if (!this.baseQuery)
@@ -751,6 +760,20 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
751
760
  }
752
761
  return fullQuery.trim();
753
762
  }
763
+ /** The full query without any title/creator letter filters */
764
+ get fullQueryWithoutAlphaFilters() {
765
+ if (!this.baseQuery)
766
+ return undefined;
767
+ let fullQuery = this.baseQuery.trim();
768
+ const { facetQuery, dateRangeQueryClause } = this;
769
+ if (facetQuery) {
770
+ fullQuery += ` AND ${facetQuery}`;
771
+ }
772
+ if (dateRangeQueryClause) {
773
+ fullQuery += ` AND ${dateRangeQueryClause}`;
774
+ }
775
+ return fullQuery.trim();
776
+ }
754
777
  /**
755
778
  * Generates a query string for the given facets
756
779
  *
@@ -845,14 +868,10 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
845
868
  }
846
869
  async fetchFacets() {
847
870
  var _a, _b, _c, _d, _e, _f, _g, _h;
848
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
849
- if (!trimmedQuery)
871
+ if (!this.filteredQuery)
850
872
  return;
851
- if (!this.searchService)
852
- return;
853
- const { facetFetchQueryKey } = this;
854
873
  const params = {
855
- query: trimmedQuery,
874
+ query: this.filteredQuery,
856
875
  rows: 0,
857
876
  filters: this.filterMap,
858
877
  // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
@@ -862,14 +881,9 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
862
881
  uid: this.facetFetchQueryKey,
863
882
  };
864
883
  this.facetsLoading = true;
865
- const searchResponse = await this.searchService.search(params, this.searchType);
884
+ const searchResponse = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
866
885
  const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
867
- // This is checking to see if the query has changed since the data was fetched.
868
- // If so, we just want to discard this set of aggregations because they are
869
- // likely no longer valid for the newer query.
870
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
871
- if (queryChangedSinceFetch)
872
- return;
886
+ this.facetsLoading = false;
873
887
  if (!success) {
874
888
  const errorMsg = (_b = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _b === void 0 ? void 0 : _b.message;
875
889
  const detailMsg = (_d = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.details) === null || _d === void 0 ? void 0 : _d.message;
@@ -879,10 +893,16 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
879
893
  }
880
894
  return;
881
895
  }
896
+ // This is checking to see if the query has changed since the data was fetched.
897
+ // If so, we just want to discard this set of aggregations because they are
898
+ // likely no longer valid for the newer query.
899
+ const returnedUid = success.request.clientParameters.uid;
900
+ const queryChangedSinceFetch = returnedUid !== this.facetFetchQueryKey;
901
+ if (queryChangedSinceFetch)
902
+ return;
882
903
  this.aggregations = success === null || success === void 0 ? void 0 : success.response.aggregations;
883
904
  this.fullYearsHistogramAggregation =
884
905
  (_h = (_g = success === null || success === void 0 ? void 0 : success.response) === null || _g === void 0 ? void 0 : _g.aggregations) === null || _h === void 0 ? void 0 : _h.year_histogram;
885
- this.facetsLoading = false;
886
906
  }
887
907
  scrollToPage(pageNumber) {
888
908
  return new Promise(resolve => {
@@ -933,11 +953,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
933
953
  return `${this.fullQuery}-${this.searchType}`;
934
954
  }
935
955
  async fetchPage(pageNumber) {
936
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
937
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
938
- if (!trimmedQuery)
939
- return;
940
- if (!this.searchService)
956
+ var _a, _b, _c, _d, _e, _f, _g, _h;
957
+ if (!this.filteredQuery)
941
958
  return;
942
959
  // if we already have data, don't fetch again
943
960
  if (this.dataSource[pageNumber])
@@ -946,14 +963,14 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
946
963
  return;
947
964
  // if a fetch is already in progress for this query and page, don't fetch again
948
965
  const { pageFetchQueryKey } = this;
949
- const pageFetches = (_b = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _b !== void 0 ? _b : new Set();
966
+ const pageFetches = (_a = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _a !== void 0 ? _a : new Set();
950
967
  if (pageFetches.has(pageNumber))
951
968
  return;
952
969
  pageFetches.add(pageNumber);
953
970
  this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
954
971
  const sortParams = this.sortParam ? [this.sortParam] : [];
955
972
  const params = {
956
- query: trimmedQuery,
973
+ query: this.filteredQuery,
957
974
  page: pageNumber,
958
975
  rows: this.pageSize,
959
976
  sort: sortParams,
@@ -961,14 +978,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
961
978
  aggregations: { omit: true },
962
979
  uid: this.pageFetchQueryKey,
963
980
  };
964
- const searchResponse = await this.searchService.search(params, this.searchType);
981
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
965
982
  const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
966
- // This is checking to see if the query has changed since the data was fetched.
967
- // If so, we just want to discard the data since there should be a new query
968
- // right behind it.
969
- const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;
970
- if (queryChangedSinceFetch)
971
- return;
972
983
  if (!success) {
973
984
  const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
974
985
  const detailMsg = (_e = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e.message;
@@ -978,10 +989,15 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
978
989
  // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
979
990
  (_g = (_f = window === null || window === void 0 ? void 0 : window.Sentry) === null || _f === void 0 ? void 0 : _f.captureMessage) === null || _g === void 0 ? void 0 : _g.call(_f, this.queryErrorMessage, 'error');
980
991
  }
981
- (_h = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _h === void 0 ? void 0 : _h.delete(pageNumber);
982
- this.searchResultsLoading = false;
983
992
  return;
984
993
  }
994
+ // This is checking to see if the query has changed since the data was fetched.
995
+ // If so, we just want to discard the data since there should be a new query
996
+ // right behind it.
997
+ const returnedUid = success.request.clientParameters.uid;
998
+ const queryChangedSinceFetch = returnedUid !== this.pageFetchQueryKey;
999
+ if (queryChangedSinceFetch)
1000
+ return;
985
1001
  this.totalResults = success.response.totalResults;
986
1002
  const { results } = success.response;
987
1003
  if (results && results.length > 0) {
@@ -997,7 +1013,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
997
1013
  this.infiniteScroller.itemCount = this.totalResults;
998
1014
  }
999
1015
  }
1000
- (_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber);
1016
+ (_h = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _h === void 0 ? void 0 : _h.delete(pageNumber);
1001
1017
  this.searchResultsLoading = false;
1002
1018
  }
1003
1019
  preloadCollectionNames(results) {
@@ -1099,32 +1115,24 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1099
1115
  }
1100
1116
  /** Fetches the aggregation buckets for the given prefix filter type. */
1101
1117
  async fetchPrefixFilterBuckets(filterType) {
1102
- var _a, _b, _c, _d, _e, _f, _g;
1103
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1104
- if (!trimmedQuery)
1118
+ var _a, _b, _c, _d, _e, _f;
1119
+ if (!this.fullQueryWithoutAlphaFilters)
1105
1120
  return [];
1106
1121
  const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1107
1122
  const params = {
1108
- query: trimmedQuery,
1123
+ query: this.fullQueryWithoutAlphaFilters,
1109
1124
  rows: 0,
1110
- filters: this.filterMap,
1111
1125
  // Only fetch the firstTitle or firstCreator aggregation
1112
1126
  aggregations: { simpleParams: [filterAggregationKey] },
1113
1127
  // Fetch all 26 letter buckets
1114
1128
  aggregationsSize: 26,
1115
1129
  };
1116
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1117
- return ((_g = (_f = (_e = (_d = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.aggregations) === null || _e === void 0 ? void 0 : _e[filterAggregationKey]) === null || _f === void 0 ? void 0 : _f.buckets) !== null && _g !== void 0 ? _g : []);
1130
+ const searchResponse = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
1131
+ return ((_f = (_e = (_d = (_c = (_b = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.aggregations) === null || _d === void 0 ? void 0 : _d[filterAggregationKey]) === null || _e === void 0 ? void 0 : _e.buckets) !== null && _f !== void 0 ? _f : []);
1118
1132
  }
1119
1133
  /** Fetches and caches the prefix filter counts for the given filter type. */
1120
1134
  async updatePrefixFilterCounts(filterType) {
1121
- const { facetFetchQueryKey } = this;
1122
1135
  const buckets = await this.fetchPrefixFilterBuckets(filterType);
1123
- // Don't update the filter counts for an outdated query (if it has been changed
1124
- // since we sent the request)
1125
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1126
- if (queryChangedSinceFetch)
1127
- return;
1128
1136
  // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1129
1137
  this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1130
1138
  this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
@@ -1152,9 +1160,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1152
1160
  * Call this whenever the counts are invalidated (e.g., by a query change).
1153
1161
  */
1154
1162
  refreshLetterCounts() {
1155
- if (Object.keys(this.prefixFilterCountMap).length > 0) {
1156
- this.prefixFilterCountMap = {};
1157
- }
1163
+ this.prefixFilterCountMap = {};
1158
1164
  this.updatePrefixFiltersForCurrentSort();
1159
1165
  }
1160
1166
  /**
@@ -1472,6 +1478,12 @@ __decorate([
1472
1478
  __decorate([
1473
1479
  property({ type: Object })
1474
1480
  ], CollectionBrowser.prototype, "resizeObserver", void 0);
1481
+ __decorate([
1482
+ property({ type: String })
1483
+ ], CollectionBrowser.prototype, "titleQuery", void 0);
1484
+ __decorate([
1485
+ property({ type: String })
1486
+ ], CollectionBrowser.prototype, "creatorQuery", void 0);
1475
1487
  __decorate([
1476
1488
  property({ type: Number })
1477
1489
  ], CollectionBrowser.prototype, "currentPage", void 0);