You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by oe...@apache.org on 2026/07/29 15:42:26 UTC
(streampipes) 01/02: Preserve asset filter state after loading assets
This is an automated email from the ASF dual-hosted git repository.
SvenO3 pushed a commit to branch 4776-preserve-asset-filter-state-after-editing-resources
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit bc680921cb07d6dc1c097b4f3e334857c2662615
Author: Sven Oehler <oe...@web.de>
AuthorDate: Wed Jul 29 17:40:03 2026 +0200
Preserve asset filter state after loading assets
---
.../asset-browser/asset-browser.service.ts | 64 +++++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)
diff --git a/ui/projects/streampipes/shared-ui/src/lib/components/asset-browser/asset-browser.service.ts b/ui/projects/streampipes/shared-ui/src/lib/components/asset-browser/asset-browser.service.ts
index 35c17fe55c..aa7dfb6625 100644
--- a/ui/projects/streampipes/shared-ui/src/lib/components/asset-browser/asset-browser.service.ts
+++ b/ui/projects/streampipes/shared-ui/src/lib/components/asset-browser/asset-browser.service.ts
@@ -68,6 +68,8 @@ export class SpAssetBrowserService {
}
loadAssetData(): void {
+ const previousAssetData = this.loadedAssetData;
+ const activeFilters = this.filter$.getValue();
const assets$ = this.assetService.getAllAssets();
const assetLinks$ = this.genericStorageService.getAllDocuments(
AssetConstants.ASSET_LINK_TYPES_DOC_NAME,
@@ -87,7 +89,16 @@ export class SpAssetBrowserService {
labels: res[3].sort((a, b) => a.label.localeCompare(b.label)),
};
this.assetData$.next(this.loadedAssetData);
- this.reloadFilters();
+ if (activeFilters === undefined) {
+ this.reloadFilters();
+ } else {
+ const refreshedFilters = this.refreshFilterSelections(
+ activeFilters,
+ previousAssetData,
+ );
+ this.filter$.next(refreshedFilters);
+ this.applyFilters(refreshedFilters);
+ }
});
}
@@ -211,6 +222,57 @@ export class SpAssetBrowserService {
this.currentAssetFilter$.next(currentFilter);
}
+ private refreshFilterSelections(
+ activeFilters: AssetFilter,
+ previousAssetData: AssetBrowserData,
+ ): AssetFilter {
+ const previousTypes = this.typeService.getTypeDescriptions();
+ const currentTypes = this.typeService.getTypeDescriptions();
+
+ return {
+ selectedSites: this.refreshSelectedItems(
+ previousAssetData?.sites ?? [],
+ this.loadedAssetData.sites,
+ activeFilters.selectedSites,
+ site => site._id,
+ ),
+ selectedLabels: this.refreshSelectedItems(
+ previousAssetData?.labels ?? [],
+ this.loadedAssetData.labels,
+ activeFilters.selectedLabels,
+ label => label._id,
+ ),
+ selectedTypes: this.refreshSelectedItems(
+ previousTypes,
+ currentTypes,
+ activeFilters.selectedTypes,
+ type => type.type,
+ ),
+ selectedAssetModels: this.refreshSelectedItems(
+ previousAssetData?.assets ?? [],
+ this.loadedAssetData.assets,
+ activeFilters.selectedAssetModels,
+ asset => asset.assetId,
+ ),
+ };
+ }
+
+ private refreshSelectedItems<T, TId>(
+ previousItems: T[],
+ currentItems: T[],
+ selectedItems: T[],
+ getId: (item: T) => TId,
+ ): T[] {
+ const selectedIds = new Set(selectedItems.map(getId));
+ const allItemsSelected =
+ previousItems.length === selectedItems.length &&
+ previousItems.every(item => selectedIds.has(getId(item)));
+
+ return allItemsSelected
+ ? [...currentItems]
+ : currentItems.filter(item => selectedIds.has(getId(item)));
+ }
+
private allSelected(items: any[], selected: any[]) {
return items.length === selected.length;
}