@internetarchive/collection-browser 2.1.10 → 2.1.11-alpha.1
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/src/app-root.d.ts +3 -0
- package/dist/src/app-root.js +27 -1
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/collection-browser.d.ts +8 -1
- package/dist/src/collection-browser.js +16 -1
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source-interface.d.ts +6 -1
- package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source.d.ts +14 -0
- package/dist/src/data-source/collection-browser-data-source.js +45 -4
- package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
- package/dist/src/data-source/collection-browser-query-state.d.ts +1 -0
- package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
- package/package.json +1 -1
- package/src/app-root.ts +24 -1
- package/src/collection-browser.ts +17 -1
- package/src/data-source/collection-browser-data-source-interface.ts +7 -1
- package/src/data-source/collection-browser-data-source.ts +56 -6
- package/src/data-source/collection-browser-query-state.ts +1 -0
|
@@ -72,6 +72,12 @@ export class CollectionBrowserDataSource
|
|
|
72
72
|
*/
|
|
73
73
|
private facetsLoading = false;
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Whether the facets are actually visible -- if not, then we can delay any facet
|
|
77
|
+
* fetches until they become visible.
|
|
78
|
+
*/
|
|
79
|
+
private facetsVisible = false;
|
|
80
|
+
|
|
75
81
|
/**
|
|
76
82
|
* Whether further query changes should be ignored and not trigger fetches
|
|
77
83
|
*/
|
|
@@ -238,6 +244,7 @@ export class CollectionBrowserDataSource
|
|
|
238
244
|
this.numTileModels = 0;
|
|
239
245
|
this.endOfDataReached = false;
|
|
240
246
|
this.queryInitialized = false;
|
|
247
|
+
this.facetsLoading = false;
|
|
241
248
|
|
|
242
249
|
// Invalidate any fetches in progress
|
|
243
250
|
this.fetchesInProgress.clear();
|
|
@@ -369,6 +376,7 @@ export class CollectionBrowserDataSource
|
|
|
369
376
|
* @inheritdoc
|
|
370
377
|
*/
|
|
371
378
|
async handleQueryChange(): Promise<void> {
|
|
379
|
+
console.log('in handleQueryChange');
|
|
372
380
|
// Don't react to the change if fetches are suppressed for this data source
|
|
373
381
|
if (this.suppressFetches) return;
|
|
374
382
|
|
|
@@ -379,21 +387,60 @@ export class CollectionBrowserDataSource
|
|
|
379
387
|
this._initialSearchCompleteResolver = res;
|
|
380
388
|
});
|
|
381
389
|
|
|
382
|
-
const shouldFetchFacets =
|
|
383
|
-
!this.host.suppressFacets &&
|
|
384
|
-
!FACETLESS_PAGE_ELEMENTS.includes(this.host.profileElement!);
|
|
385
|
-
|
|
386
390
|
// Fire the initial page & facet requests
|
|
391
|
+
console.log('handling query change:', this.canFetchFacets);
|
|
387
392
|
this.queryInitialized = true;
|
|
388
393
|
await Promise.all([
|
|
389
394
|
this.doInitialPageFetch(),
|
|
390
|
-
|
|
395
|
+
this.canFetchFacets ? this.fetchFacets() : null,
|
|
391
396
|
]);
|
|
392
397
|
|
|
393
398
|
// Resolve the `initialSearchComplete` promise for this search
|
|
394
399
|
this._initialSearchCompleteResolver(true);
|
|
395
400
|
}
|
|
396
401
|
|
|
402
|
+
/**
|
|
403
|
+
* @inheritdoc
|
|
404
|
+
*/
|
|
405
|
+
async handleFacetVisibilityChange(visible: boolean): Promise<void> {
|
|
406
|
+
console.log(
|
|
407
|
+
'handling facet visibility change:',
|
|
408
|
+
this.facetsVisible,
|
|
409
|
+
'->',
|
|
410
|
+
visible
|
|
411
|
+
);
|
|
412
|
+
const facetsBecameVisible = !this.facetsVisible && visible;
|
|
413
|
+
this.facetsVisible = visible;
|
|
414
|
+
|
|
415
|
+
const needsFetch =
|
|
416
|
+
this.host.lazyLoadFacets && facetsBecameVisible && this.canFetchFacets;
|
|
417
|
+
if (needsFetch) {
|
|
418
|
+
this.fetchFacets();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Whether the data source & its host are in a state where a facet request should be fired.
|
|
424
|
+
* (i.e., they aren't suppressed or already loading, etc.)
|
|
425
|
+
*/
|
|
426
|
+
private get canFetchFacets(): boolean {
|
|
427
|
+
// Don't fetch facets if they are suppressed entirely or not required for the current profile page element
|
|
428
|
+
if (this.host.suppressFacets) return false;
|
|
429
|
+
if (FACETLESS_PAGE_ELEMENTS.includes(this.host.profileElement!))
|
|
430
|
+
return false;
|
|
431
|
+
|
|
432
|
+
// If facets are to be lazy-loaded, don't fetch them if they are not going to be visible anyway
|
|
433
|
+
// (wait until they become visible instead)
|
|
434
|
+
if (this.host.lazyLoadFacets && !this.facetsVisible) return false;
|
|
435
|
+
|
|
436
|
+
// Don't fetch facets again if they are already fetched or pending
|
|
437
|
+
const facetsAlreadyFetched =
|
|
438
|
+
Object.keys(this.aggregations ?? {}).length > 0;
|
|
439
|
+
if (this.facetsLoading || facetsAlreadyFetched) return false;
|
|
440
|
+
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
|
|
397
444
|
/**
|
|
398
445
|
* @inheritdoc
|
|
399
446
|
*/
|
|
@@ -868,6 +915,7 @@ export class CollectionBrowserDataSource
|
|
|
868
915
|
* the current search state.
|
|
869
916
|
*/
|
|
870
917
|
private async fetchFacets(): Promise<void> {
|
|
918
|
+
console.log('called fetchFacets');
|
|
871
919
|
const trimmedQuery = this.host.baseQuery?.trim();
|
|
872
920
|
if (!this.canPerformSearch) return;
|
|
873
921
|
|
|
@@ -875,6 +923,9 @@ export class CollectionBrowserDataSource
|
|
|
875
923
|
if (this.fetchesInProgress.has(facetFetchQueryKey)) return;
|
|
876
924
|
this.fetchesInProgress.add(facetFetchQueryKey);
|
|
877
925
|
|
|
926
|
+
console.log('setting facets loading');
|
|
927
|
+
this.setFacetsLoading(true);
|
|
928
|
+
|
|
878
929
|
const sortParams = this.host.sortParam ? [this.host.sortParam] : [];
|
|
879
930
|
const params: SearchParams = {
|
|
880
931
|
...this.pageSpecifierParams,
|
|
@@ -891,7 +942,6 @@ export class CollectionBrowserDataSource
|
|
|
891
942
|
'aggregations'
|
|
892
943
|
);
|
|
893
944
|
|
|
894
|
-
this.setFacetsLoading(true);
|
|
895
945
|
const searchResponse = await this.host.searchService?.search(
|
|
896
946
|
params,
|
|
897
947
|
this.host.searchType
|
|
@@ -37,6 +37,7 @@ export interface CollectionBrowserSearchInterface
|
|
|
37
37
|
readonly sortParam: SortParam | null;
|
|
38
38
|
readonly defaultSortParam: SortParam | null;
|
|
39
39
|
readonly suppressFacets?: boolean;
|
|
40
|
+
readonly lazyLoadFacets?: boolean;
|
|
40
41
|
readonly initialPageNumber: number;
|
|
41
42
|
readonly currentVisiblePageNumbers: number[];
|
|
42
43
|
readonly clearResultsOnEmptyQuery?: boolean;
|