@@ -74,31 +74,37 @@ export default class BrowserFilter extends React.Component {
74
74
return false ;
75
75
}
76
76
77
- // Fallback only when no filterId in URL: Check if current filter structure matches any saved filter
78
- // This is for legacy compatibility
79
- const preferences = ClassPreferences . getPreferences (
80
- this . context . applicationId ,
81
- this . props . className
82
- ) ;
77
+ // Check for legacy filters (filters parameter without filterId)
78
+ const filtersParam = urlParams . get ( 'filters' ) ;
79
+ if ( filtersParam && this . props . filters . size > 0 ) {
80
+ const preferences = ClassPreferences . getPreferences (
81
+ this . context . applicationId ,
82
+ this . props . className
83
+ ) ;
83
84
84
- if ( ! preferences . filters || this . props . filters . size === 0 ) {
85
- return false ;
86
- }
85
+ if ( preferences . filters ) {
86
+ // Try to find a saved filter that matches the current filter content
87
+ const currentFiltersString = JSON . stringify ( this . props . filters . toJS ( ) ) ;
87
88
88
- const currentFiltersString = JSON . stringify ( this . props . filters . toJS ( ) ) ;
89
+ const matchingFilter = preferences . filters . find ( savedFilter => {
90
+ try {
91
+ const savedFiltersString = JSON . stringify ( JSON . parse ( savedFilter . filter ) ) ;
92
+ return savedFiltersString === currentFiltersString ;
93
+ } catch {
94
+ return false ;
95
+ }
96
+ } ) ;
89
97
90
- return preferences . filters . some ( savedFilter => {
91
- try {
92
- const savedFiltersString = JSON . stringify ( JSON . parse ( savedFilter . filter ) ) ;
93
- return savedFiltersString === currentFiltersString ;
94
- } catch {
95
- return false ;
98
+ return ! ! matchingFilter ;
96
99
}
97
- } ) ;
100
+ }
101
+
102
+ return false ;
98
103
} getCurrentFilterInfo ( ) {
99
104
// Extract filterId from URL if present
100
105
const urlParams = new URLSearchParams ( window . location . search ) ;
101
106
const filterId = urlParams . get ( 'filterId' ) ;
107
+ const filtersParam = urlParams . get ( 'filters' ) ;
102
108
103
109
if ( filterId ) {
104
110
const preferences = ClassPreferences . getPreferences (
@@ -132,11 +138,57 @@ export default class BrowserFilter extends React.Component {
132
138
}
133
139
}
134
140
141
+ // Check for legacy filters (filters parameter without filterId)
142
+ if ( filtersParam && this . props . filters . size > 0 ) {
143
+ const preferences = ClassPreferences . getPreferences (
144
+ this . context . applicationId ,
145
+ this . props . className
146
+ ) ;
147
+
148
+ if ( preferences . filters ) {
149
+ // Try to find a saved filter that matches the current filter content
150
+ const currentFiltersString = JSON . stringify ( this . props . filters . toJS ( ) ) ;
151
+
152
+ const matchingFilter = preferences . filters . find ( savedFilter => {
153
+ try {
154
+ const savedFiltersString = JSON . stringify ( JSON . parse ( savedFilter . filter ) ) ;
155
+ const matches = savedFiltersString === currentFiltersString ;
156
+ return matches ;
157
+ } catch {
158
+ return false ;
159
+ }
160
+ } ) ;
161
+
162
+ if ( matchingFilter ) {
163
+ // Check if the filter has relative dates
164
+ let hasRelativeDates = false ;
165
+ try {
166
+ const filterData = JSON . parse ( matchingFilter . filter ) ;
167
+ hasRelativeDates = filterData . some ( filter =>
168
+ filter . compareTo && filter . compareTo . __type === 'RelativeDate'
169
+ ) ;
170
+ } catch ( error ) {
171
+ console . warn ( 'Failed to parse saved filter:' , error ) ;
172
+ hasRelativeDates = false ;
173
+ }
174
+
175
+ return {
176
+ id : matchingFilter . id || null , // Legacy filters might not have an id
177
+ name : matchingFilter . name ,
178
+ isApplied : true ,
179
+ hasRelativeDates : hasRelativeDates ,
180
+ isLegacy : ! matchingFilter . id // Mark as legacy if no id
181
+ } ;
182
+ }
183
+ }
184
+ }
185
+
135
186
return {
136
187
id : null ,
137
188
name : '' ,
138
189
isApplied : false ,
139
- hasRelativeDates : false
190
+ hasRelativeDates : false ,
191
+ isLegacy : false
140
192
} ;
141
193
}
142
194
@@ -182,9 +234,22 @@ export default class BrowserFilter extends React.Component {
182
234
) ;
183
235
184
236
if ( preferences . filters && name ) {
185
- return preferences . filters . some ( filter =>
186
- filter . name === name && filter . id !== this . getCurrentFilterInfo ( ) . id
187
- ) ;
237
+ const currentFilterInfo = this . getCurrentFilterInfo ( ) ;
238
+ return preferences . filters . some ( filter => {
239
+ // For filters with the same name, check if it's not the current filter
240
+ if ( filter . name === name ) {
241
+ // If current filter has an ID, exclude it by ID
242
+ if ( currentFilterInfo . id && filter . id === currentFilterInfo . id ) {
243
+ return false ;
244
+ }
245
+ // If current filter is legacy (no ID), exclude it by name match
246
+ if ( currentFilterInfo . isLegacy && ! filter . id && filter . name === currentFilterInfo . name ) {
247
+ return false ;
248
+ }
249
+ return true ;
250
+ }
251
+ return false ;
252
+ } ) ;
188
253
}
189
254
return false ;
190
255
}
@@ -298,41 +363,50 @@ export default class BrowserFilter extends React.Component {
298
363
299
364
deleteCurrentFilter ( ) {
300
365
const currentFilterInfo = this . getCurrentFilterInfo ( ) ;
301
- if ( ! currentFilterInfo . id ) {
302
- this . setState ( { confirmDelete : false } ) ;
303
- return ;
304
- }
305
366
306
- // Delete the filter from ClassPreferences
307
- const preferences = ClassPreferences . getPreferences (
308
- this . context . applicationId ,
309
- this . props . className
310
- ) ;
311
-
312
- if ( preferences . filters ) {
313
- const updatedFilters = preferences . filters . filter ( filter => filter . id !== currentFilterInfo . id ) ;
314
- ClassPreferences . updatePreferences (
315
- this . context . applicationId ,
316
- this . props . className ,
317
- { ...preferences , filters : updatedFilters }
318
- ) ;
367
+ // Use parent's onDeleteFilter method which handles everything including force update
368
+ if ( this . props . onDeleteFilter ) {
369
+ // For legacy filters, we need to pass the entire filter object for the parent to match
370
+ if ( currentFilterInfo . isLegacy ) {
371
+ const preferences = ClassPreferences . getPreferences ( this . context . applicationId , this . props . className ) ;
372
+ if ( preferences . filters ) {
373
+ const currentFiltersString = JSON . stringify ( this . props . filters . toJS ( ) ) ;
374
+ const matchingFilter = preferences . filters . find ( filter => {
375
+ if ( ! filter . id && filter . name === currentFilterInfo . name ) {
376
+ try {
377
+ const savedFiltersString = JSON . stringify ( JSON . parse ( filter . filter ) ) ;
378
+ return savedFiltersString === currentFiltersString ;
379
+ } catch {
380
+ return false ;
381
+ }
382
+ }
383
+ return false ;
384
+ } ) ;
385
+
386
+ if ( matchingFilter ) {
387
+ this . props . onDeleteFilter ( matchingFilter ) ;
388
+ }
389
+ }
390
+ } else if ( currentFilterInfo . id ) {
391
+ // For modern filters with ID, just pass the ID
392
+ this . props . onDeleteFilter ( currentFilterInfo . id ) ;
393
+ }
319
394
}
320
395
321
- // Remove filterId from URL
396
+ // Remove filterId from URL if present
322
397
const urlParams = new URLSearchParams ( window . location . search ) ;
323
398
urlParams . delete ( 'filterId' ) ;
399
+ // For legacy filters, also remove the filters parameter
400
+ if ( currentFilterInfo . isLegacy ) {
401
+ urlParams . delete ( 'filters' ) ;
402
+ }
324
403
const newUrl = `${ window . location . pathname } ${ urlParams . toString ( ) ? '?' + urlParams . toString ( ) : '' } ` ;
325
404
window . history . replaceState ( { } , '' , newUrl ) ;
326
405
327
406
// Clear current filters and close dialog
328
407
this . props . onChange ( new ImmutableMap ( ) ) ;
329
408
this . setState ( { confirmDelete : false } ) ;
330
409
this . toggle ( ) ;
331
-
332
- // Call onDeleteFilter prop if provided
333
- if ( this . props . onDeleteFilter ) {
334
- this . props . onDeleteFilter ( currentFilterInfo . id ) ;
335
- }
336
410
}
337
411
338
412
copyCurrentFilter ( ) {
@@ -458,7 +532,13 @@ export default class BrowserFilter extends React.Component {
458
532
459
533
// If we're in showMore mode, we're editing an existing filter
460
534
const currentFilterInfo = this . getCurrentFilterInfo ( ) ;
461
- const filterId = this . state . showMore ? currentFilterInfo . id : null ;
535
+ let filterId = this . state . showMore ? currentFilterInfo . id : null ;
536
+
537
+ // For legacy filters (no ID), pass a special identifier so the save handler can convert them
538
+ if ( this . state . showMore && currentFilterInfo . isLegacy && ! filterId ) {
539
+ // Pass the filter name as a special legacy identifier
540
+ filterId = `legacy:${ currentFilterInfo . name } ` ;
541
+ }
462
542
463
543
const savedFilterId = this . props . onSaveFilter ( formatted , this . state . name , this . state . relativeDates , filterId ) ;
464
544
0 commit comments