Skip to content

Commit 3ed589d

Browse files
authored
Remove platform/product selections when no longer relevant (#805)
* Remove platform/product selections when no longer relevant * Disable buttons when no collection selected
1 parent 8db28fc commit 3ed589d

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

packages/base/src/stacBrowser/components/StacFilterSection.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,17 @@ const StacFilterSection = ({
139139
}
140140
}, [section, data, selectedCollections, selectedData, handleCheckedChange]);
141141

142+
const isTriggerDisabled =
143+
(section === 'Platform' || section === 'Data / Product') &&
144+
selectedCollections.length === 0;
145+
142146
return (
143147
<div className="jgis-stac-filter-section-container">
144148
<DropdownMenu modal={false}>
145-
<DropdownMenuTrigger className="jgis-stac-filter-trigger">
149+
<DropdownMenuTrigger
150+
className="jgis-stac-filter-trigger"
151+
disabled={isTriggerDisabled}
152+
>
146153
{section}
147154
<ChevronRight className="DropdownMenuIcon" />
148155
</DropdownMenuTrigger>

packages/base/src/stacBrowser/components/StacPanelFilters.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
import StacFilterSection from '@/src/stacBrowser/components/StacFilterSection';
1414
import {
1515
datasets as datasetsList,
16-
platforms,
17-
products,
16+
platforms as platformsList,
17+
products as productsList,
1818
} from '@/src/stacBrowser/constants';
1919
import {
2020
StacFilterState,
@@ -57,6 +57,28 @@ const StacPanelFilters = ({
5757
});
5858
if (datasetsForCollection.length === 0) {
5959
collections.delete(collection);
60+
61+
const platforms = new Set(filterState.platforms);
62+
const products = new Set(filterState.products);
63+
64+
// Remove platforms belonging to this collection
65+
if (platformsList[collection as keyof typeof platformsList]) {
66+
platformsList[collection as keyof typeof platformsList].forEach(
67+
platform => {
68+
platforms.delete(platform);
69+
},
70+
);
71+
}
72+
73+
// Remove products belonging to this collection
74+
productsList
75+
.filter(product => product.collections.includes(collection))
76+
.forEach(product => {
77+
products.delete(product.productCode);
78+
});
79+
80+
filterSetters.platforms(platforms);
81+
filterSetters.products(products);
6082
}
6183
} else {
6284
datasets.add(dataset);
@@ -127,14 +149,14 @@ const StacPanelFilters = ({
127149
/>
128150
<StacFilterSection
129151
section="Platform"
130-
data={platforms}
152+
data={platformsList}
131153
selectedCollections={Array.from(filterState.collections)}
132154
selectedData={Array.from(filterState.platforms)}
133155
handleCheckedChange={platform => handleToggle('platforms', platform)}
134156
/>
135157
<StacFilterSection
136158
section="Data / Product"
137-
data={products}
159+
data={productsList}
138160
selectedCollections={Array.from(filterState.collections)}
139161
selectedData={Array.from(filterState.products)}
140162
handleCheckedChange={product => handleToggle('products', product)}

packages/base/style/stacBrowser.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
gap: 0.15rem;
5757
}
5858

59+
.jgis-stac-filter-trigger:disabled {
60+
cursor: not-allowed;
61+
}
62+
5963
.jgis-stac-filter-section-container {
6064
display: flex;
6165
flex-direction: column;

0 commit comments

Comments
 (0)