@internetarchive/collection-browser 1.5.3-alpha.1 → 1.6.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.
- package/dist/src/collection-browser.d.ts +2 -14
- package/dist/src/collection-browser.js +9 -62
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/models.d.ts +1 -2
- package/dist/src/models.js +1 -5
- package/dist/src/models.js.map +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +0 -9
- package/dist/src/sort-filter-bar/sort-filter-bar.js +24 -62
- package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
- package/dist/test/collection-browser.test.js +2 -60
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/mocks/mock-search-responses.d.ts +0 -2
- package/dist/test/mocks/mock-search-responses.js +117 -111
- package/dist/test/mocks/mock-search-responses.js.map +1 -1
- package/dist/test/mocks/mock-search-service.js +3 -6
- package/dist/test/mocks/mock-search-service.js.map +1 -1
- package/package.json +3 -3
- package/src/collection-browser.ts +7 -63
- package/src/models.ts +2 -6
- package/src/sort-filter-bar/sort-filter-bar.ts +26 -73
- package/test/collection-browser.test.ts +2 -79
- package/test/mocks/mock-search-responses.ts +117 -119
- package/test/mocks/mock-search-service.ts +1 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LitElement, PropertyValues, TemplateResult } from 'lit';
|
|
2
2
|
import type { InfiniteScrollerCellProviderInterface } from '@internetarchive/infinite-scroller';
|
|
3
|
-
import { SearchServiceInterface, SearchType, SortDirection, SortParam } from '@internetarchive/search-service';
|
|
3
|
+
import { CollectionExtraInfo, SearchServiceInterface, SearchType, SortDirection, SortParam } from '@internetarchive/search-service';
|
|
4
4
|
import type { SharedResizeObserverInterface, SharedResizeObserverResizeHandlerInterface } from '@internetarchive/shared-resize-observer';
|
|
5
5
|
import '@internetarchive/infinite-scroller';
|
|
6
6
|
import type { CollectionNameCacheInterface } from '@internetarchive/collection-name-cache';
|
|
@@ -37,6 +37,7 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
|
|
|
37
37
|
selectedFacets?: SelectedFacets;
|
|
38
38
|
showHistogramDatePicker: boolean;
|
|
39
39
|
collectionPagePath: string;
|
|
40
|
+
collectionInfo?: CollectionExtraInfo;
|
|
40
41
|
/** describes where this component is being used */
|
|
41
42
|
searchContext: string;
|
|
42
43
|
collectionNameCache?: CollectionNameCacheInterface;
|
|
@@ -75,8 +76,6 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
|
|
|
75
76
|
private mobileView;
|
|
76
77
|
private mobileFacetsVisible;
|
|
77
78
|
private contentWidth?;
|
|
78
|
-
private defaultSortField;
|
|
79
|
-
private defaultSortDirection;
|
|
80
79
|
private placeholderType;
|
|
81
80
|
private prefixFilterCountMap;
|
|
82
81
|
private contentContainer;
|
|
@@ -358,11 +357,6 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
|
|
|
358
357
|
facetClickHandler({ detail: { key, state: facetState, negative }, }: CustomEvent<FacetEventDetails>): void;
|
|
359
358
|
private fetchFacets;
|
|
360
359
|
private scrollToPage;
|
|
361
|
-
/**
|
|
362
|
-
* Whether sorting by relevance makes sense for the current state.
|
|
363
|
-
* Currently equivalent to having a non-empty query.
|
|
364
|
-
*/
|
|
365
|
-
private get isRelevanceSortAvailable();
|
|
366
360
|
/**
|
|
367
361
|
* Whether a search may be performed in the current state of the component.
|
|
368
362
|
* This is only true if the search service is defined, and either
|
|
@@ -406,12 +400,6 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
|
|
|
406
400
|
*/
|
|
407
401
|
fetchPage(pageNumber: number, numInitialPages?: number): Promise<void>;
|
|
408
402
|
private preloadCollectionNames;
|
|
409
|
-
/**
|
|
410
|
-
* Applies any default sort option for the current collection, by checking
|
|
411
|
-
* for one in the collection's metadata. If none is found, defaults to sorting
|
|
412
|
-
* descending by weekly views.
|
|
413
|
-
*/
|
|
414
|
-
private applyDefaultCollectionSort;
|
|
415
403
|
/**
|
|
416
404
|
* This is useful for determining whether we need to reload the scroller.
|
|
417
405
|
*
|
|
@@ -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,
|
|
14
|
+
import { SortField, SortFieldToMetadataField, getDefaultSelectedFacets, prefixFilterAggregationKeys, } 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.
|
|
27
|
+
this.selectedSort = SortField.relevance;
|
|
28
28
|
this.selectedTitleFilter = null;
|
|
29
29
|
this.selectedCreatorFilter = null;
|
|
30
30
|
this.sortDirection = null;
|
|
@@ -63,8 +63,6 @@ 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;
|
|
68
66
|
this.placeholderType = null;
|
|
69
67
|
this.prefixFilterCountMap = {};
|
|
70
68
|
/**
|
|
@@ -218,7 +216,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
218
216
|
if (sort) {
|
|
219
217
|
this.sortParam = null;
|
|
220
218
|
this.sortDirection = null;
|
|
221
|
-
this.selectedSort = SortField.
|
|
219
|
+
this.selectedSort = SortField.relevance;
|
|
222
220
|
}
|
|
223
221
|
}
|
|
224
222
|
/**
|
|
@@ -404,11 +402,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
404
402
|
get sortFilterBarTemplate() {
|
|
405
403
|
return html `
|
|
406
404
|
<sort-filter-bar
|
|
407
|
-
.defaultSortField=${this.defaultSortField}
|
|
408
|
-
.defaultSortDirection=${this.defaultSortDirection}
|
|
409
405
|
.selectedSort=${this.selectedSort}
|
|
410
406
|
.sortDirection=${this.sortDirection}
|
|
411
|
-
.showRelevance=${this.isRelevanceSortAvailable}
|
|
412
407
|
.displayMode=${this.displayMode}
|
|
413
408
|
.selectedTitleFilter=${this.selectedTitleFilter}
|
|
414
409
|
.selectedCreatorFilter=${this.selectedCreatorFilter}
|
|
@@ -442,7 +437,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
442
437
|
});
|
|
443
438
|
}
|
|
444
439
|
selectedSortChanged() {
|
|
445
|
-
if (
|
|
440
|
+
if (this.selectedSort === 'relevance') {
|
|
446
441
|
this.sortParam = null;
|
|
447
442
|
return;
|
|
448
443
|
}
|
|
@@ -873,7 +868,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
873
868
|
return this._initialSearchCompletePromise;
|
|
874
869
|
}
|
|
875
870
|
async handleQueryChange() {
|
|
876
|
-
var _a;
|
|
877
871
|
// only reset if the query has actually changed
|
|
878
872
|
if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
|
|
879
873
|
return;
|
|
@@ -898,10 +892,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
898
892
|
this.infiniteScroller.itemCount = this.estimatedTileCount;
|
|
899
893
|
this.infiniteScroller.reload();
|
|
900
894
|
}
|
|
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
|
-
}
|
|
905
895
|
if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
|
|
906
896
|
this.scrollToPage(this.initialPageNumber);
|
|
907
897
|
}
|
|
@@ -938,7 +928,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
938
928
|
this.displayMode = restorationState.displayMode;
|
|
939
929
|
if (restorationState.searchType != null)
|
|
940
930
|
this.searchType = restorationState.searchType;
|
|
941
|
-
this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.
|
|
931
|
+
this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.relevance;
|
|
942
932
|
this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
|
|
943
933
|
this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
|
|
944
934
|
this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
|
|
@@ -1231,14 +1221,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
1231
1221
|
}, 0);
|
|
1232
1222
|
});
|
|
1233
1223
|
}
|
|
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
|
-
}
|
|
1242
1224
|
/**
|
|
1243
1225
|
* Whether a search may be performed in the current state of the component.
|
|
1244
1226
|
* This is only true if the search service is defined, and either
|
|
@@ -1360,9 +1342,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
1360
1342
|
}
|
|
1361
1343
|
this.totalResults = success.response.totalResults;
|
|
1362
1344
|
if (this.withinCollection) {
|
|
1363
|
-
|
|
1364
|
-
// which can be specified in metadata, or otherwise assumed to be week:desc
|
|
1365
|
-
this.applyDefaultCollectionSort(success.response.collectionExtraInfo);
|
|
1345
|
+
this.collectionInfo = success.response.collectionExtraInfo;
|
|
1366
1346
|
}
|
|
1367
1347
|
const { results, collectionTitles } = success.response;
|
|
1368
1348
|
if (results && results.length > 0) {
|
|
@@ -1403,36 +1383,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
|
|
|
1403
1383
|
const collectionIdsArray = Array.from(new Set(collectionIds));
|
|
1404
1384
|
(_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
|
|
1405
1385
|
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Applies any default sort option for the current collection, by checking
|
|
1408
|
-
* for one in the collection's metadata. If none is found, defaults to sorting
|
|
1409
|
-
* descending by weekly views.
|
|
1410
|
-
*/
|
|
1411
|
-
applyDefaultCollectionSort(collectionInfo) {
|
|
1412
|
-
var _a, _b;
|
|
1413
|
-
if (this.baseQuery) {
|
|
1414
|
-
// If there's a query set, then we default to relevance sorting regardless of
|
|
1415
|
-
// the collection metadata-specified sort.
|
|
1416
|
-
this.defaultSortField = SortField.relevance;
|
|
1417
|
-
this.defaultSortDirection = null;
|
|
1418
|
-
return;
|
|
1419
|
-
}
|
|
1420
|
-
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';
|
|
1421
|
-
// Account for both -field and field:dir formats
|
|
1422
|
-
let [field, dir] = defaultSort.split(':');
|
|
1423
|
-
if (field.startsWith('-')) {
|
|
1424
|
-
field = field.slice(1);
|
|
1425
|
-
dir = 'desc';
|
|
1426
|
-
}
|
|
1427
|
-
else if (!['asc', 'desc'].includes(dir)) {
|
|
1428
|
-
dir = 'asc';
|
|
1429
|
-
}
|
|
1430
|
-
const sortField = MetadataFieldToSortField[field];
|
|
1431
|
-
if (sortField && sortField !== SortField.default) {
|
|
1432
|
-
this.defaultSortField = sortField;
|
|
1433
|
-
this.defaultSortDirection = dir;
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
1386
|
/**
|
|
1437
1387
|
* This is useful for determining whether we need to reload the scroller.
|
|
1438
1388
|
*
|
|
@@ -2084,6 +2034,9 @@ __decorate([
|
|
|
2084
2034
|
__decorate([
|
|
2085
2035
|
property({ type: String })
|
|
2086
2036
|
], CollectionBrowser.prototype, "collectionPagePath", void 0);
|
|
2037
|
+
__decorate([
|
|
2038
|
+
property({ type: Object })
|
|
2039
|
+
], CollectionBrowser.prototype, "collectionInfo", void 0);
|
|
2087
2040
|
__decorate([
|
|
2088
2041
|
property({ type: String, reflect: true })
|
|
2089
2042
|
], CollectionBrowser.prototype, "searchContext", void 0);
|
|
@@ -2147,12 +2100,6 @@ __decorate([
|
|
|
2147
2100
|
__decorate([
|
|
2148
2101
|
state()
|
|
2149
2102
|
], CollectionBrowser.prototype, "contentWidth", void 0);
|
|
2150
|
-
__decorate([
|
|
2151
|
-
state()
|
|
2152
|
-
], CollectionBrowser.prototype, "defaultSortField", void 0);
|
|
2153
|
-
__decorate([
|
|
2154
|
-
state()
|
|
2155
|
-
], CollectionBrowser.prototype, "defaultSortDirection", void 0);
|
|
2156
2103
|
__decorate([
|
|
2157
2104
|
state()
|
|
2158
2105
|
], CollectionBrowser.prototype, "placeholderType", void 0);
|