@internetarchive/collection-browser 2.7.8 → 2.7.9
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 +15 -0
- package/dist/src/collection-browser.js +36 -3
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source-interface.d.ts +4 -0
- 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 +4 -0
- package/dist/src/data-source/collection-browser-data-source.js +13 -0
- 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/dist/src/manage/manage-bar.js +2 -2
- package/dist/src/manage/manage-bar.js.map +1 -1
- package/dist/test/collection-browser.test.js +16 -0
- package/dist/test/collection-browser.test.js.map +1 -1
- package/package.json +1 -1
- package/src/collection-browser.ts +33 -1
- package/src/data-source/collection-browser-data-source-interface.ts +5 -0
- package/src/data-source/collection-browser-data-source.ts +14 -0
- package/src/data-source/collection-browser-query-state.ts +1 -0
- package/src/manage/manage-bar.ts +2 -2
- package/test/collection-browser.test.ts +23 -0
package/package.json
CHANGED
|
@@ -252,6 +252,12 @@ export class CollectionBrowser
|
|
|
252
252
|
/** Whether to display a smart results carousel above the full results */
|
|
253
253
|
@property({ type: Boolean, reflect: true }) showSmartResults = false;
|
|
254
254
|
|
|
255
|
+
/**
|
|
256
|
+
* The maximum number of pages we will load when a privileged user clicks
|
|
257
|
+
* the "Manage" button on the search page. Limited to 15 pages.
|
|
258
|
+
*/
|
|
259
|
+
@property({ type: Number }) maxPagesToManage = 15;
|
|
260
|
+
|
|
255
261
|
/**
|
|
256
262
|
* The results per page so we can paginate.
|
|
257
263
|
*
|
|
@@ -797,6 +803,7 @@ export class CollectionBrowser
|
|
|
797
803
|
@cancel=${() => {
|
|
798
804
|
this.isManageView = false;
|
|
799
805
|
this.dataSource.uncheckAllTiles();
|
|
806
|
+
if (this.searchResultsLoading) this.dataSource.resetPages();
|
|
800
807
|
}}
|
|
801
808
|
></manage-bar>
|
|
802
809
|
`;
|
|
@@ -1450,7 +1457,11 @@ export class CollectionBrowser
|
|
|
1450
1457
|
}
|
|
1451
1458
|
|
|
1452
1459
|
if (changed.has('isManageView')) {
|
|
1453
|
-
if (this.isManageView)
|
|
1460
|
+
if (this.isManageView) {
|
|
1461
|
+
this.displayMode = 'grid';
|
|
1462
|
+
this.fetchManagableSearchResults();
|
|
1463
|
+
} else if (this.pageContext === 'search') this.infiniteScroller?.reload();
|
|
1464
|
+
|
|
1454
1465
|
this.infiniteScroller?.refreshAllVisibleCells();
|
|
1455
1466
|
this.emitManageModeChangedEvent();
|
|
1456
1467
|
}
|
|
@@ -2086,6 +2097,27 @@ export class CollectionBrowser
|
|
|
2086
2097
|
}
|
|
2087
2098
|
}
|
|
2088
2099
|
|
|
2100
|
+
/**
|
|
2101
|
+
* Fetches search results for privileged users when in manage view.
|
|
2102
|
+
*
|
|
2103
|
+
* This method:
|
|
2104
|
+
* 1. Checks if we're in search context with > 100 results and not currently loading
|
|
2105
|
+
* 2. Resets the datasource pagination state
|
|
2106
|
+
* 3. Fetches first page with limit based on maxPagesToManage threshold
|
|
2107
|
+
* 4. Reloads the infinite scroller to display new results
|
|
2108
|
+
*/
|
|
2109
|
+
private fetchManagableSearchResults(): void {
|
|
2110
|
+
if (
|
|
2111
|
+
this.pageContext === 'search' &&
|
|
2112
|
+
this.dataSource.totalResults > 100 &&
|
|
2113
|
+
!this.searchResultsLoading
|
|
2114
|
+
) {
|
|
2115
|
+
this.dataSource.resetPages();
|
|
2116
|
+
this.dataSource.fetchPage(1, this.maxPagesToManage);
|
|
2117
|
+
this.infiniteScroller?.reload();
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2089
2121
|
static get styles() {
|
|
2090
2122
|
return [
|
|
2091
2123
|
srOnlyStyle,
|
|
@@ -155,6 +155,11 @@ export interface CollectionBrowserDataSourceInterface
|
|
|
155
155
|
*/
|
|
156
156
|
reset(): void;
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Resets the data source to its pages.
|
|
160
|
+
*/
|
|
161
|
+
resetPages(): void;
|
|
162
|
+
|
|
158
163
|
/**
|
|
159
164
|
* Adds the given page of tile models to the data source.
|
|
160
165
|
* If the given page number already exists, that page will be overwritten.
|
|
@@ -246,6 +246,19 @@ export class CollectionBrowserDataSource
|
|
|
246
246
|
this.requestHostUpdate();
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/**
|
|
250
|
+
* @inheritdoc
|
|
251
|
+
*/
|
|
252
|
+
resetPages(): void {
|
|
253
|
+
if (Object.keys(this.pages).length < this.host.maxPagesToManage) {
|
|
254
|
+
this.pages = {};
|
|
255
|
+
|
|
256
|
+
// Invalidate any fetches in progress
|
|
257
|
+
this.fetchesInProgress.clear();
|
|
258
|
+
this.requestHostUpdate();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
249
262
|
/**
|
|
250
263
|
* @inheritdoc
|
|
251
264
|
*/
|
|
@@ -433,6 +446,7 @@ export class CollectionBrowserDataSource
|
|
|
433
446
|
map(
|
|
434
447
|
callback: (model: TileModel, index: number, array: TileModel[]) => TileModel
|
|
435
448
|
): void {
|
|
449
|
+
if (!Object.keys(this.pages).length) return;
|
|
436
450
|
this.pages = Object.fromEntries(
|
|
437
451
|
Object.entries(this.pages).map(([page, tileModels]) => [
|
|
438
452
|
page,
|
|
@@ -38,6 +38,7 @@ export interface CollectionBrowserSearchInterface
|
|
|
38
38
|
readonly defaultSortField: SortField | null;
|
|
39
39
|
readonly facetLoadStrategy: FacetLoadStrategy;
|
|
40
40
|
readonly initialPageNumber: number;
|
|
41
|
+
readonly maxPagesToManage: number;
|
|
41
42
|
readonly currentVisiblePageNumbers: number[];
|
|
42
43
|
readonly clearResultsOnEmptyQuery?: boolean;
|
|
43
44
|
readonly dataSource?: CollectionBrowserDataSourceInterface;
|
package/src/manage/manage-bar.ts
CHANGED
|
@@ -65,7 +65,7 @@ export class ManageBar extends LitElement {
|
|
|
65
65
|
?disabled=${!this.removeAllowed}
|
|
66
66
|
@click=${this.showRemoveItemsModal}
|
|
67
67
|
>
|
|
68
|
-
${msg('Remove selected items')}
|
|
68
|
+
${msg('Remove selected items')} (${this.selectedItems.length})
|
|
69
69
|
</button>
|
|
70
70
|
${when(
|
|
71
71
|
this.showItemManageButton,
|
|
@@ -74,7 +74,7 @@ export class ManageBar extends LitElement {
|
|
|
74
74
|
?disabled=${!this.removeAllowed}
|
|
75
75
|
@click=${this.manageItemsClicked}
|
|
76
76
|
>
|
|
77
|
-
${msg('Item Manager the items')}
|
|
77
|
+
${msg('Item Manager the items')} (${this.selectedItems.length})
|
|
78
78
|
</button>`
|
|
79
79
|
)}
|
|
80
80
|
<div class="selection-buttons">
|
|
@@ -2001,4 +2001,27 @@ describe('Collection Browser', () => {
|
|
|
2001
2001
|
const infiniteScroller = el.shadowRoot?.querySelector('infinite-scroller');
|
|
2002
2002
|
expect(infiniteScroller).not.to.exist;
|
|
2003
2003
|
});
|
|
2004
|
+
|
|
2005
|
+
it('fetch larger result on search page for admin user to manage items', async () => {
|
|
2006
|
+
const resultsSpy = sinon.spy();
|
|
2007
|
+
const searchService = new MockSearchService({
|
|
2008
|
+
asyncResponse: true,
|
|
2009
|
+
resultsSpy,
|
|
2010
|
+
});
|
|
2011
|
+
|
|
2012
|
+
const el = await fixture<CollectionBrowser>(
|
|
2013
|
+
html`<collection-browser .searchService=${searchService}>
|
|
2014
|
+
</collection-browser>`
|
|
2015
|
+
);
|
|
2016
|
+
|
|
2017
|
+
const numberOfPages = 15;
|
|
2018
|
+
|
|
2019
|
+
el.baseQuery = 'jack';
|
|
2020
|
+
el.isManageView = true;
|
|
2021
|
+
await el.dataSource.fetchPage(1, numberOfPages);
|
|
2022
|
+
await el.updateComplete;
|
|
2023
|
+
|
|
2024
|
+
const initialResults = el.dataSource.getAllPages();
|
|
2025
|
+
expect(Object.keys(initialResults).length).to.deep.equal(numberOfPages);
|
|
2026
|
+
});
|
|
2004
2027
|
});
|