Skip to content

Commit f038b08

Browse files
Fix updates to count
1 parent 56be1f1 commit f038b08

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/client/src/formElements/FilterInputContext.tsx

+15-6
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ export function FilterInputServiceContextProvider({
7979
updatingCount: boolean;
8080
count: number;
8181
fullCellCount: number;
82+
filterString: string;
8283
}>({
8384
loading: false,
8485
updatingCount: true,
8586
count: 0,
8687
fullCellCount: 0,
88+
filterString: "",
8789
});
8890

8991
const mapContext = useContext(MapContext);
@@ -107,13 +109,16 @@ export function FilterInputServiceContextProvider({
107109
.then((res) => res.json())
108110
.then((metadata: FilterServiceMetadata) => {
109111
setState((prev) => {
112+
const count =
113+
// @ts-ignore
114+
metadata.attributes.find((a) => a.attribute === "id")?.count || 0;
110115
return {
111116
...prev,
112117
metadata,
113118
loading: false,
114-
fullCellCount:
115-
// @ts-ignore
116-
metadata.attributes.find((a) => a.attribute === "id")?.count || 0,
119+
fullCellCount: count,
120+
count,
121+
updatingCount: false,
117122
};
118123
});
119124
})
@@ -158,17 +163,21 @@ export function FilterInputServiceContextProvider({
158163
)
159164
);
160165
filterLayerManager.updateFilter(filterString);
161-
if (filterString.length === 0) {
166+
if (filterString === state.filterString) {
167+
// do nothing
168+
} else if (filterString.length === 0) {
162169
setState((prev) => ({
163170
...prev,
164171
updatingCount: false,
165172
count: prev.fullCellCount,
173+
filterString: "",
166174
}));
167-
} else if (serviceLocation && state.fullCellCount === 0) {
175+
} else if (serviceLocation) {
168176
// TODO: update count from service
169177
setState((prev) => ({
170178
...prev,
171179
updatingCount: true,
180+
filterString,
172181
}));
173182
fetch(
174183
`${serviceLocation.replace(/\/$/, "")}/count?filter=${filterString}`
@@ -299,7 +308,7 @@ export function filterStateToSearchString(filters: FilterState) {
299308
} = {};
300309
for (const attr in filters) {
301310
const filter = filters[attr];
302-
if (filter.selected) {
311+
if (filter && filter.selected) {
303312
if ("numberState" in filter) {
304313
state[attr] = filter.numberState!;
305314
} else if ("stringState" in filter) {

packages/client/src/projects/Sketches/FilteredPlanningUnitCountHeader.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Spinner from "../../components/Spinner";
55

66
export default function FilteredPlanningUnitCountHeader() {
77
const context = useContext(FilterInputServiceContext);
8-
console.log("context", context);
98
return (
109
<div
1110
className={`w-full flex items-center p-2 px-4 border-b bg-gray-50 text-sm ${

0 commit comments

Comments
 (0)