@@ -79,11 +79,13 @@ export function FilterInputServiceContextProvider({
79
79
updatingCount : boolean ;
80
80
count : number ;
81
81
fullCellCount : number ;
82
+ filterString : string ;
82
83
} > ( {
83
84
loading : false ,
84
85
updatingCount : true ,
85
86
count : 0 ,
86
87
fullCellCount : 0 ,
88
+ filterString : "" ,
87
89
} ) ;
88
90
89
91
const mapContext = useContext ( MapContext ) ;
@@ -107,13 +109,16 @@ export function FilterInputServiceContextProvider({
107
109
. then ( ( res ) => res . json ( ) )
108
110
. then ( ( metadata : FilterServiceMetadata ) => {
109
111
setState ( ( prev ) => {
112
+ const count =
113
+ // @ts -ignore
114
+ metadata . attributes . find ( ( a ) => a . attribute === "id" ) ?. count || 0 ;
110
115
return {
111
116
...prev ,
112
117
metadata,
113
118
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 ,
117
122
} ;
118
123
} ) ;
119
124
} )
@@ -158,17 +163,21 @@ export function FilterInputServiceContextProvider({
158
163
)
159
164
) ;
160
165
filterLayerManager . updateFilter ( filterString ) ;
161
- if ( filterString . length === 0 ) {
166
+ if ( filterString === state . filterString ) {
167
+ // do nothing
168
+ } else if ( filterString . length === 0 ) {
162
169
setState ( ( prev ) => ( {
163
170
...prev ,
164
171
updatingCount : false ,
165
172
count : prev . fullCellCount ,
173
+ filterString : "" ,
166
174
} ) ) ;
167
- } else if ( serviceLocation && state . fullCellCount === 0 ) {
175
+ } else if ( serviceLocation ) {
168
176
// TODO: update count from service
169
177
setState ( ( prev ) => ( {
170
178
...prev ,
171
179
updatingCount : true ,
180
+ filterString,
172
181
} ) ) ;
173
182
fetch (
174
183
`${ serviceLocation . replace ( / \/ $ / , "" ) } /count?filter=${ filterString } `
@@ -299,7 +308,7 @@ export function filterStateToSearchString(filters: FilterState) {
299
308
} = { } ;
300
309
for ( const attr in filters ) {
301
310
const filter = filters [ attr ] ;
302
- if ( filter . selected ) {
311
+ if ( filter && filter . selected ) {
303
312
if ( "numberState" in filter ) {
304
313
state [ attr ] = filter . numberState ! ;
305
314
} else if ( "stringState" in filter ) {
0 commit comments