Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/pages/page-pup-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ const initialSort = (a, b) => {
return 0;
}

/** Stable id set for store rows so we do not reset pagination on every pkgController.notify(). */
function pupCatalogSignature(pups) {
if (!pups?.length) return '';
return pups
.map((p) => {
const sourceId = p?.def?.source?.id ?? p?.state?.source?.id ?? '';
const key = p?.def?.key ?? p?.state?.manifest?.meta?.name ?? p?.state?.id ?? '';
return `${sourceId}\0${key}`;
})
.sort()
.join('\n');
}

class StoreView extends LitElement {

static get properties() {
Expand All @@ -29,7 +42,6 @@ class StoreView extends LitElement {
fetchError: { type: Boolean },
busy: { type: Boolean },
inspectedPup: { type: String },
searchValue: { type: String },
_showSourceManagementDialog: { type: Boolean },
_hasSourceErrors: { type: Boolean }
}
Expand All @@ -47,6 +59,7 @@ class StoreView extends LitElement {
this.packageList = new PaginationController(this, undefined, this.itemsPerPage,{ initialSort });
this._showSourceManagementDialog = false;
this._hasSourceErrors = false;
this._pupCatalogSig = '';

this.inspectedPup;
this.showCategories = false;
Expand Down Expand Up @@ -139,6 +152,7 @@ class StoreView extends LitElement {
const storeListingRes = await getStoreListing()
this.pkgController.setStoreData(storeListingRes);
this.packageList.setData(this.pkgController.pups);
this._pupCatalogSig = pupCatalogSignature(this.pkgController.pups);
this.checkForSourceErrors();
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -167,20 +181,12 @@ class StoreView extends LitElement {

updated(changedProperties) {
if (changedProperties.has('pups')) {
this.packageList.setData(this.pups);
}

// Existing code for other property changes
if (changedProperties.has('searchValue')) {
this.filterPackageList();
}
}

filterPackageList() {
if (this.searchValue === "") {
this.packageList.setFilter();
const sig = pupCatalogSignature(this.pups);
if (sig !== this._pupCatalogSig) {
this._pupCatalogSig = sig;
this.packageList.setData(this.pups);
}
}
this.packageList.setFilter((pkg) => pkg?.manifest?.package?.toLowerCase()?.includes(this.searchValue.toLowerCase()));
}

handleManageSourcesClick() {
Expand Down