@internetarchive/collection-browser 1.14.17-alpha.4 → 1.14.17-alpha.40
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.
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/src/collection-browser.d.ts +6 -13
- package/dist/src/collection-browser.js +56 -30
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source-interface.d.ts +194 -0
- package/dist/src/data-source/collection-browser-data-source-interface.js +2 -0
- package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -0
- package/dist/src/data-source/collection-browser-data-source.d.ts +62 -174
- package/dist/src/data-source/collection-browser-data-source.js +185 -64
- package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
- package/dist/src/data-source/collection-browser-query-state.d.ts +42 -0
- package/dist/src/data-source/collection-browser-query-state.js +2 -0
- package/dist/src/data-source/collection-browser-query-state.js.map +1 -0
- package/dist/src/data-source/models.d.ts +1 -39
- package/dist/src/data-source/models.js.map +1 -1
- package/dist/src/models.d.ts +3 -2
- package/dist/src/models.js +24 -22
- package/dist/src/models.js.map +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.js +1 -0
- package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
- package/dist/src/tiles/grid/item-tile.d.ts +1 -0
- package/dist/src/tiles/grid/item-tile.js +28 -1
- package/dist/src/tiles/grid/item-tile.js.map +1 -1
- package/dist/src/tiles/grid/tile-stats.js +13 -8
- package/dist/src/tiles/grid/tile-stats.js.map +1 -1
- package/dist/src/tiles/item-image.d.ts +3 -0
- package/dist/src/tiles/item-image.js +30 -2
- package/dist/src/tiles/item-image.js.map +1 -1
- package/dist/src/tiles/list/tile-list.d.ts +1 -0
- package/dist/src/tiles/list/tile-list.js +30 -1
- package/dist/src/tiles/list/tile-list.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.js +3 -2
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/src/tiles/tile-display-value-provider.d.ts +5 -1
- package/dist/src/tiles/tile-display-value-provider.js +15 -1
- package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
- package/dist/test/collection-browser.test.js +2 -6
- package/dist/test/collection-browser.test.js.map +1 -1
- package/index.ts +3 -5
- package/package.json +2 -2
- package/src/collection-browser.ts +70 -49
- package/src/data-source/collection-browser-data-source-interface.ts +245 -0
- package/src/data-source/collection-browser-data-source.ts +237 -281
- package/src/data-source/collection-browser-query-state.ts +53 -0
- package/src/data-source/models.ts +0 -47
- package/src/models.ts +7 -3
- package/src/sort-filter-bar/sort-filter-bar.ts +1 -0
- package/src/tiles/grid/item-tile.ts +36 -1
- package/src/tiles/grid/tile-stats.ts +12 -7
- package/src/tiles/item-image.ts +28 -0
- package/src/tiles/list/tile-list.ts +37 -1
- package/src/tiles/tile-dispatcher.ts +2 -1
- package/src/tiles/tile-display-value-provider.ts +19 -1
- package/test/collection-browser.test.ts +2 -8
|
@@ -2,6 +2,7 @@ import { FilterConstraint, FilterMapBuilder, SearchType, } from '@internetarchiv
|
|
|
2
2
|
import { prefixFilterAggregationKeys, TileModel, } from '../models';
|
|
3
3
|
import { sha1 } from '../utils/sha1';
|
|
4
4
|
export class CollectionBrowserDataSource {
|
|
5
|
+
// eslint-disable-next-line no-useless-constructor
|
|
5
6
|
constructor(
|
|
6
7
|
/** The host element to which this controller should attach listeners */
|
|
7
8
|
host,
|
|
@@ -13,9 +14,18 @@ export class CollectionBrowserDataSource {
|
|
|
13
14
|
this.offset = 0;
|
|
14
15
|
this.numTileModels = 0;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* A set of fetch IDs that are valid for the current query state
|
|
17
18
|
*/
|
|
18
|
-
this.
|
|
19
|
+
this.fetchesInProgress = new Set();
|
|
20
|
+
/**
|
|
21
|
+
* A record of the query key used for the last search.
|
|
22
|
+
* If this changes, we need to load new results.
|
|
23
|
+
*/
|
|
24
|
+
this.previousQueryKey = '';
|
|
25
|
+
this.searchResultsLoading = false;
|
|
26
|
+
this.facetsLoading = false;
|
|
27
|
+
// TEMP for ease of debugging
|
|
28
|
+
this.id = Math.random();
|
|
19
29
|
/**
|
|
20
30
|
* @inheritdoc
|
|
21
31
|
*/
|
|
@@ -24,6 +34,10 @@ export class CollectionBrowserDataSource {
|
|
|
24
34
|
* @inheritdoc
|
|
25
35
|
*/
|
|
26
36
|
this.endOfDataReached = false;
|
|
37
|
+
/**
|
|
38
|
+
* @inheritdoc
|
|
39
|
+
*/
|
|
40
|
+
this.queryInitialized = false;
|
|
27
41
|
/**
|
|
28
42
|
* @inheritdoc
|
|
29
43
|
*/
|
|
@@ -36,6 +50,12 @@ export class CollectionBrowserDataSource {
|
|
|
36
50
|
* @inheritdoc
|
|
37
51
|
*/
|
|
38
52
|
this.prefixFilterCountMap = {};
|
|
53
|
+
/**
|
|
54
|
+
* Internal property to store the private value backing the `initialSearchComplete` getter.
|
|
55
|
+
*/
|
|
56
|
+
this._initialSearchCompletePromise = new Promise(res => {
|
|
57
|
+
this._initialSearchCompleteResolver = res;
|
|
58
|
+
});
|
|
39
59
|
/**
|
|
40
60
|
* @inheritdoc
|
|
41
61
|
*/
|
|
@@ -94,10 +114,55 @@ export class CollectionBrowserDataSource {
|
|
|
94
114
|
// Swap in the new pages
|
|
95
115
|
this.pages = newPages;
|
|
96
116
|
this.numTileModels -= numChecked;
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
117
|
+
this.requestHostUpdate();
|
|
118
|
+
this.refreshVisibleResults();
|
|
99
119
|
};
|
|
100
|
-
|
|
120
|
+
// Just setting some property values
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @inheritdoc
|
|
124
|
+
*/
|
|
125
|
+
get initialSearchComplete() {
|
|
126
|
+
return this._initialSearchCompletePromise;
|
|
127
|
+
}
|
|
128
|
+
hostConnected() {
|
|
129
|
+
console.log('hostConnected', this.id);
|
|
130
|
+
this.setSearchResultsLoading(this.searchResultsLoading);
|
|
131
|
+
this.setFacetsLoading(this.facetsLoading);
|
|
132
|
+
}
|
|
133
|
+
hostUpdate() {
|
|
134
|
+
console.log('hostUpdate', this.id, this.previousQueryKey, this.pageFetchQueryKey);
|
|
135
|
+
// This reactive controller hook is run whenever the host component (collection-browser) performs an update.
|
|
136
|
+
// We check whether the host's state has changed in a way which should trigger a reset & new results fetch.
|
|
137
|
+
// Only the currently-installed data source should react to the update
|
|
138
|
+
if (!this.activeOnHost)
|
|
139
|
+
return;
|
|
140
|
+
// Copy loading states onto the host
|
|
141
|
+
this.setSearchResultsLoading(this.searchResultsLoading);
|
|
142
|
+
this.setFacetsLoading(this.facetsLoading);
|
|
143
|
+
// Can't perform searches without a search service
|
|
144
|
+
if (!this.host.searchService)
|
|
145
|
+
return;
|
|
146
|
+
// We should only reset if part of the full query state has changed
|
|
147
|
+
const queryKeyChanged = this.pageFetchQueryKey !== this.previousQueryKey;
|
|
148
|
+
console.log('query keys', this.pageFetchQueryKey, this.previousQueryKey);
|
|
149
|
+
if (!queryKeyChanged)
|
|
150
|
+
return;
|
|
151
|
+
// We should only reset if either:
|
|
152
|
+
// (a) our state permits a valid search, or
|
|
153
|
+
// (b) we have a blank query that we want to show empty results for
|
|
154
|
+
const shouldShowEmptyQueryResults = this.host.clearResultsOnEmptyQuery && this.host.baseQuery === '';
|
|
155
|
+
if (!(this.canPerformSearch || shouldShowEmptyQueryResults))
|
|
156
|
+
return;
|
|
157
|
+
if (this.activeOnHost)
|
|
158
|
+
this.host.emitQueryStateChanged();
|
|
159
|
+
this.handleQueryChange();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns whether this data source is the one currently installed on the host component.
|
|
163
|
+
*/
|
|
164
|
+
get activeOnHost() {
|
|
165
|
+
return this.host.dataSource === this;
|
|
101
166
|
}
|
|
102
167
|
/**
|
|
103
168
|
* @inheritdoc
|
|
@@ -109,18 +174,25 @@ export class CollectionBrowserDataSource {
|
|
|
109
174
|
* @inheritdoc
|
|
110
175
|
*/
|
|
111
176
|
reset() {
|
|
177
|
+
console.log('resetting data source', this.id);
|
|
112
178
|
this.pages = {};
|
|
113
179
|
this.aggregations = {};
|
|
114
180
|
this.yearHistogramAggregation = undefined;
|
|
115
|
-
this.pageFetchesInProgress = {};
|
|
116
181
|
this.pageElements = undefined;
|
|
117
182
|
this.parentCollections = [];
|
|
118
183
|
this.prefixFilterCountMap = {};
|
|
184
|
+
this.queryErrorMessage = undefined;
|
|
119
185
|
this.offset = 0;
|
|
120
186
|
this.numTileModels = 0;
|
|
121
187
|
this.totalResults = 0;
|
|
122
188
|
this.endOfDataReached = false;
|
|
123
|
-
this.
|
|
189
|
+
this.queryInitialized = false;
|
|
190
|
+
// Invalidate any fetches in progress
|
|
191
|
+
this.fetchesInProgress.clear();
|
|
192
|
+
console.log('fetches cleared - size =', this.fetchesInProgress.size);
|
|
193
|
+
if (this.activeOnHost)
|
|
194
|
+
this.host.setTotalResultCount(0);
|
|
195
|
+
this.requestHostUpdate();
|
|
124
196
|
}
|
|
125
197
|
/**
|
|
126
198
|
* @inheritdoc
|
|
@@ -128,7 +200,7 @@ export class CollectionBrowserDataSource {
|
|
|
128
200
|
addPage(pageNum, pageTiles) {
|
|
129
201
|
this.pages[pageNum] = pageTiles;
|
|
130
202
|
this.numTileModels += pageTiles.length;
|
|
131
|
-
this.
|
|
203
|
+
this.requestHostUpdate();
|
|
132
204
|
}
|
|
133
205
|
/**
|
|
134
206
|
* @inheritdoc
|
|
@@ -175,10 +247,18 @@ export class CollectionBrowserDataSource {
|
|
|
175
247
|
*/
|
|
176
248
|
async handleQueryChange() {
|
|
177
249
|
this.reset();
|
|
250
|
+
// Reset the `initialSearchComplete` promise with a new value for the imminent search
|
|
251
|
+
this._initialSearchCompletePromise = new Promise(res => {
|
|
252
|
+
this._initialSearchCompleteResolver = res;
|
|
253
|
+
});
|
|
254
|
+
// Fire the initial page & facet requests
|
|
255
|
+
this.queryInitialized = true;
|
|
178
256
|
await Promise.all([
|
|
179
257
|
this.doInitialPageFetch(),
|
|
180
258
|
this.host.suppressFacets ? null : this.fetchFacets(),
|
|
181
259
|
]);
|
|
260
|
+
// Resolve the `initialSearchComplete` promise for this search
|
|
261
|
+
this._initialSearchCompleteResolver(true);
|
|
182
262
|
}
|
|
183
263
|
/**
|
|
184
264
|
* @inheritdoc
|
|
@@ -188,8 +268,8 @@ export class CollectionBrowserDataSource {
|
|
|
188
268
|
page,
|
|
189
269
|
tileModels.map((model, index, array) => model ? callback(model, index, array) : model),
|
|
190
270
|
]));
|
|
191
|
-
this.
|
|
192
|
-
this.
|
|
271
|
+
this.requestHostUpdate();
|
|
272
|
+
this.refreshVisibleResults();
|
|
193
273
|
}
|
|
194
274
|
/**
|
|
195
275
|
* @inheritdoc
|
|
@@ -215,7 +295,6 @@ export class CollectionBrowserDataSource {
|
|
|
215
295
|
.flat()
|
|
216
296
|
.filter((model, index, array) => model ? predicate(model, index, array) : false);
|
|
217
297
|
}
|
|
218
|
-
// DATA FETCHES
|
|
219
298
|
/**
|
|
220
299
|
* @inheritdoc
|
|
221
300
|
*/
|
|
@@ -235,6 +314,43 @@ export class CollectionBrowserDataSource {
|
|
|
235
314
|
(isCollectionSearch && isMetadataSearch) ||
|
|
236
315
|
(isProfileSearch && hasProfileElement && isMetadataSearch));
|
|
237
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Sets the state for whether the initial set of search results for the
|
|
319
|
+
* current query is loading
|
|
320
|
+
*/
|
|
321
|
+
setSearchResultsLoading(loading) {
|
|
322
|
+
this.searchResultsLoading = loading;
|
|
323
|
+
if (this.activeOnHost) {
|
|
324
|
+
this.host.setSearchResultsLoading(loading);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Sets the state for whether the facets for a query is loading
|
|
329
|
+
*/
|
|
330
|
+
setFacetsLoading(loading) {
|
|
331
|
+
this.facetsLoading = loading;
|
|
332
|
+
if (this.activeOnHost) {
|
|
333
|
+
this.host.setFacetsLoading(loading);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Requests that the host perform an update, provided this data
|
|
338
|
+
* source is actively installed on it.
|
|
339
|
+
*/
|
|
340
|
+
requestHostUpdate() {
|
|
341
|
+
if (this.activeOnHost) {
|
|
342
|
+
this.host.requestUpdate();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Requests that the host refresh its visible tiles, provided this
|
|
347
|
+
* data source is actively installed on it.
|
|
348
|
+
*/
|
|
349
|
+
refreshVisibleResults() {
|
|
350
|
+
if (this.activeOnHost) {
|
|
351
|
+
this.host.refreshVisibleResults();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
238
354
|
/**
|
|
239
355
|
* The query key is a string that uniquely identifies the current search.
|
|
240
356
|
* It consists of:
|
|
@@ -246,16 +362,16 @@ export class CollectionBrowserDataSource {
|
|
|
246
362
|
* - Any currently-applied prefix filters
|
|
247
363
|
* - The current sort options
|
|
248
364
|
*
|
|
249
|
-
* This lets us keep track of queries so we don't persist data that's
|
|
250
|
-
* no longer relevant.
|
|
365
|
+
* This lets us internally keep track of queries so we don't persist data that's
|
|
366
|
+
* no longer relevant. Not meant to be human-readable.
|
|
251
367
|
*/
|
|
252
368
|
get pageFetchQueryKey() {
|
|
253
369
|
var _a, _b, _c, _d, _e;
|
|
254
|
-
const profileKey =
|
|
370
|
+
const profileKey = `pf;${this.host.withinProfile}--pe;${this.host.profileElement}`;
|
|
255
371
|
const pageTarget = (_a = this.host.withinCollection) !== null && _a !== void 0 ? _a : profileKey;
|
|
256
372
|
const sortField = (_c = (_b = this.host.sortParam) === null || _b === void 0 ? void 0 : _b.field) !== null && _c !== void 0 ? _c : 'none';
|
|
257
373
|
const sortDirection = (_e = (_d = this.host.sortParam) === null || _d === void 0 ? void 0 : _d.direction) !== null && _e !== void 0 ? _e : 'none';
|
|
258
|
-
return
|
|
374
|
+
return `fq:${this.fullQuery}-pt:${pageTarget}-st:${this.host.searchType}-sf:${sortField}-sd:${sortDirection}`;
|
|
259
375
|
}
|
|
260
376
|
/**
|
|
261
377
|
* Similar to `pageFetchQueryKey` above, but excludes sort fields since they
|
|
@@ -477,10 +593,15 @@ export class CollectionBrowserDataSource {
|
|
|
477
593
|
*/
|
|
478
594
|
async fetchFacets() {
|
|
479
595
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
596
|
+
console.log('fetchFacets', this.id, this.host.profileElement);
|
|
480
597
|
const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
|
|
481
598
|
if (!this.canPerformSearch)
|
|
482
599
|
return;
|
|
600
|
+
console.log('will actually fetch facets');
|
|
483
601
|
const { facetFetchQueryKey } = this;
|
|
602
|
+
if (this.fetchesInProgress.has(facetFetchQueryKey))
|
|
603
|
+
return;
|
|
604
|
+
this.fetchesInProgress.add(facetFetchQueryKey);
|
|
484
605
|
const sortParams = this.host.sortParam ? [this.host.sortParam] : [];
|
|
485
606
|
const params = {
|
|
486
607
|
...this.pageSpecifierParams,
|
|
@@ -493,15 +614,18 @@ export class CollectionBrowserDataSource {
|
|
|
493
614
|
// The default aggregations for the search_results page type should be what we need here.
|
|
494
615
|
};
|
|
495
616
|
params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
|
|
496
|
-
this.
|
|
617
|
+
this.setFacetsLoading(true);
|
|
497
618
|
const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
|
|
498
619
|
const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
|
|
499
620
|
// This is checking to see if the query has changed since the data was fetched.
|
|
500
621
|
// If so, we just want to discard this set of aggregations because they are
|
|
501
622
|
// likely no longer valid for the newer query.
|
|
502
|
-
const queryChangedSinceFetch =
|
|
503
|
-
|
|
623
|
+
const queryChangedSinceFetch = this.fetchesInProgress.has(facetFetchQueryKey);
|
|
624
|
+
this.fetchesInProgress.delete(facetFetchQueryKey);
|
|
625
|
+
if (queryChangedSinceFetch) {
|
|
626
|
+
console.log('facet query has changed since fetch, returning. new/old:', this.facetFetchQueryKey, facetFetchQueryKey);
|
|
504
627
|
return;
|
|
628
|
+
}
|
|
505
629
|
if (!success) {
|
|
506
630
|
const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
|
|
507
631
|
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;
|
|
@@ -509,6 +633,7 @@ export class CollectionBrowserDataSource {
|
|
|
509
633
|
// @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
|
|
510
634
|
(_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, 'Missing or malformed facet response from backend', 'error');
|
|
511
635
|
}
|
|
636
|
+
this.setFacetsLoading(false);
|
|
512
637
|
return;
|
|
513
638
|
}
|
|
514
639
|
const { aggregations, collectionTitles } = success.response;
|
|
@@ -520,17 +645,16 @@ export class CollectionBrowserDataSource {
|
|
|
520
645
|
}
|
|
521
646
|
this.yearHistogramAggregation =
|
|
522
647
|
(_j = (_h = success === null || success === void 0 ? void 0 : success.response) === null || _h === void 0 ? void 0 : _h.aggregations) === null || _j === void 0 ? void 0 : _j.year_histogram;
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
648
|
+
this.setFacetsLoading(false);
|
|
649
|
+
this.requestHostUpdate();
|
|
525
650
|
}
|
|
526
651
|
/**
|
|
527
652
|
* Performs the initial page fetch(es) for the current search state.
|
|
528
653
|
*/
|
|
529
654
|
async doInitialPageFetch() {
|
|
530
|
-
this.
|
|
655
|
+
this.setSearchResultsLoading(true);
|
|
531
656
|
// Try to batch 2 initial page requests when possible
|
|
532
657
|
await this.fetchPage(this.host.initialPageNumber, 2);
|
|
533
|
-
this.host.setSearchResultsLoading(false);
|
|
534
658
|
}
|
|
535
659
|
/**
|
|
536
660
|
* Fetches one or more pages of results and updates the data source.
|
|
@@ -541,8 +665,7 @@ export class CollectionBrowserDataSource {
|
|
|
541
665
|
* if `pageNumber != 1`, defaulting to a single page.
|
|
542
666
|
*/
|
|
543
667
|
async fetchPage(pageNumber, numInitialPages = 1) {
|
|
544
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
545
|
-
console.log(`fetchPage(${pageNumber})`, this.canPerformSearch, this.hasPage(pageNumber), this.endOfDataReached, this.host.baseQuery, JSON.stringify(this.host.selectedFacets));
|
|
668
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
546
669
|
const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
|
|
547
670
|
if (!this.canPerformSearch)
|
|
548
671
|
return;
|
|
@@ -557,15 +680,18 @@ export class CollectionBrowserDataSource {
|
|
|
557
680
|
const numRows = this.pageSize * numPages;
|
|
558
681
|
// if a fetch is already in progress for this query and page, don't fetch again
|
|
559
682
|
const { pageFetchQueryKey } = this;
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
683
|
+
const currentPageKey = `${pageFetchQueryKey}-p:${pageNumber}`;
|
|
684
|
+
console.log('page fetch key', currentPageKey, this.fetchesInProgress.has(currentPageKey));
|
|
685
|
+
if (this.fetchesInProgress.has(currentPageKey))
|
|
563
686
|
return;
|
|
564
|
-
|
|
687
|
+
// const pageFetches =
|
|
688
|
+
// this.fetchesInProgress[pageFetchQueryKey] ?? new Set();
|
|
689
|
+
// if (pageFetches.has(pageNumber)) return;
|
|
565
690
|
for (let i = 0; i < numPages; i += 1) {
|
|
566
|
-
|
|
691
|
+
this.fetchesInProgress.add(`${pageFetchQueryKey}-p:${pageNumber + i}`);
|
|
567
692
|
}
|
|
568
|
-
this.
|
|
693
|
+
console.log(`fetchPage(${pageNumber})`, this.id, this.canPerformSearch, this.hasPage(pageNumber), this.endOfDataReached, this.host.baseQuery, JSON.stringify(this.host.selectedFacets), this.pageFetchQueryKey);
|
|
694
|
+
this.previousQueryKey = pageFetchQueryKey;
|
|
569
695
|
const sortParams = this.host.sortParam ? [this.host.sortParam] : [];
|
|
570
696
|
const params = {
|
|
571
697
|
...this.pageSpecifierParams,
|
|
@@ -578,37 +704,37 @@ export class CollectionBrowserDataSource {
|
|
|
578
704
|
};
|
|
579
705
|
params.uid = await this.requestUID(params, 'hits');
|
|
580
706
|
console.log('=== FIRING PAGE REQUEST ===');
|
|
581
|
-
const searchResponse = await ((
|
|
707
|
+
const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
|
|
582
708
|
console.log('=== RECEIVED PAGE RESPONSE IN CB === ');
|
|
583
709
|
const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
|
|
584
|
-
// This is checking to see if the
|
|
585
|
-
// If so, we just want to discard the
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
if (queryChangedSinceFetch)
|
|
710
|
+
// This is checking to see if the fetch has been invalidated since it was fired off.
|
|
711
|
+
// If so, we just want to discard the response since it is for an obsolete query state.
|
|
712
|
+
console.log('after page fetch key:', currentPageKey, this.fetchesInProgress.has(currentPageKey));
|
|
713
|
+
if (!this.fetchesInProgress.has(currentPageKey))
|
|
589
714
|
return;
|
|
715
|
+
for (let i = 0; i < numPages; i += 1) {
|
|
716
|
+
this.fetchesInProgress.delete(`${pageFetchQueryKey}-p:${pageNumber + i}`);
|
|
717
|
+
}
|
|
590
718
|
if (!success) {
|
|
591
|
-
const errorMsg = (
|
|
592
|
-
const detailMsg = (
|
|
593
|
-
this.
|
|
594
|
-
if (!this.
|
|
595
|
-
this.
|
|
596
|
-
'Missing or malformed response from backend';
|
|
719
|
+
const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
|
|
720
|
+
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;
|
|
721
|
+
this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
|
|
722
|
+
if (!this.queryErrorMessage) {
|
|
723
|
+
this.queryErrorMessage = 'Missing or malformed response from backend';
|
|
597
724
|
// @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
|
|
598
|
-
(
|
|
599
|
-
}
|
|
600
|
-
for (let i = 0; i < numPages; i += 1) {
|
|
601
|
-
(_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber + i);
|
|
725
|
+
(_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');
|
|
602
726
|
}
|
|
603
|
-
this.
|
|
604
|
-
this.
|
|
727
|
+
this.setSearchResultsLoading(false);
|
|
728
|
+
this.requestHostUpdate();
|
|
605
729
|
return;
|
|
606
730
|
}
|
|
607
731
|
this.totalResults = success.response.totalResults - this.offset;
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
this.
|
|
732
|
+
if (this.activeOnHost) {
|
|
733
|
+
this.host.setTotalResultCount(this.totalResults);
|
|
734
|
+
// display event to offshoot when result count is zero.
|
|
735
|
+
if (this.totalResults === 0) {
|
|
736
|
+
this.host.emitEmptyResults();
|
|
737
|
+
}
|
|
612
738
|
}
|
|
613
739
|
if (this.host.withinCollection) {
|
|
614
740
|
console.log('host is within collection, setting collection info:', success.response.collectionExtraInfo);
|
|
@@ -617,7 +743,7 @@ export class CollectionBrowserDataSource {
|
|
|
617
743
|
// which can be specified in metadata, or otherwise assumed to be week:desc
|
|
618
744
|
this.host.applyDefaultCollectionSort(this.collectionExtraInfo);
|
|
619
745
|
if (this.collectionExtraInfo) {
|
|
620
|
-
this.parentCollections = [].concat((
|
|
746
|
+
this.parentCollections = [].concat((_j = (_h = this.collectionExtraInfo.public_metadata) === null || _h === void 0 ? void 0 : _h.collection) !== null && _j !== void 0 ? _j : []);
|
|
621
747
|
}
|
|
622
748
|
}
|
|
623
749
|
else if (this.host.withinProfile) {
|
|
@@ -650,12 +776,11 @@ export class CollectionBrowserDataSource {
|
|
|
650
776
|
if (resultCountDiscrepancy > 0) {
|
|
651
777
|
console.log('End of data reached');
|
|
652
778
|
this.endOfDataReached = true;
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
for (let i = 0; i < numPages; i += 1) {
|
|
656
|
-
(_m = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _m === void 0 ? void 0 : _m.delete(pageNumber + i);
|
|
779
|
+
if (this.activeOnHost)
|
|
780
|
+
this.host.setTileCount(this.totalResults);
|
|
657
781
|
}
|
|
658
|
-
this.
|
|
782
|
+
this.setSearchResultsLoading(false);
|
|
783
|
+
this.requestHostUpdate();
|
|
659
784
|
}
|
|
660
785
|
/**
|
|
661
786
|
* Update the datasource from the fetch response
|
|
@@ -664,10 +789,6 @@ export class CollectionBrowserDataSource {
|
|
|
664
789
|
* @param results
|
|
665
790
|
*/
|
|
666
791
|
addTilesToDataSource(pageNumber, results) {
|
|
667
|
-
// copy our existing datasource so when we set it below, it gets set
|
|
668
|
-
// instead of modifying the existing dataSource since object changes
|
|
669
|
-
// don't trigger a re-render
|
|
670
|
-
// const datasource = { ...this.dataSource };
|
|
671
792
|
const tiles = [];
|
|
672
793
|
results === null || results === void 0 ? void 0 : results.forEach(result => {
|
|
673
794
|
if (!result.identifier)
|
|
@@ -678,7 +799,7 @@ export class CollectionBrowserDataSource {
|
|
|
678
799
|
const visiblePages = this.host.currentVisiblePageNumbers;
|
|
679
800
|
const needsReload = visiblePages.includes(pageNumber);
|
|
680
801
|
if (needsReload) {
|
|
681
|
-
this.
|
|
802
|
+
this.refreshVisibleResults();
|
|
682
803
|
}
|
|
683
804
|
}
|
|
684
805
|
/**
|
|
@@ -722,7 +843,7 @@ export class CollectionBrowserDataSource {
|
|
|
722
843
|
acc[bucket.key.toUpperCase()] = bucket.doc_count;
|
|
723
844
|
return acc;
|
|
724
845
|
}, {});
|
|
725
|
-
this.
|
|
846
|
+
this.requestHostUpdate();
|
|
726
847
|
}
|
|
727
848
|
}
|
|
728
849
|
//# sourceMappingURL=collection-browser-data-source.js.map
|