@@ -10,6 +10,8 @@ import {
10
10
import { GenericDocument } from "convex/server" ;
11
11
import {
12
12
Filter ,
13
+ FilterByIndex ,
14
+ FilterByIndexRange ,
13
15
FilterExpression ,
14
16
FilterValidationError ,
15
17
} from "system-udfs/convex/_system/frontend/lib/filters" ;
@@ -38,11 +40,7 @@ import { cn } from "@common/lib/cn";
38
40
import { useTableIndexes } from "@common/features/data/lib/api" ;
39
41
import { DeploymentInfoContext } from "@common/lib/deploymentContext" ;
40
42
import { IndexFilterState } from "./IndexFilterEditor" ;
41
- import {
42
- IndexFilters ,
43
- DEFAULT_INDEX_NAME ,
44
- getDefaultIndexClause ,
45
- } from "./IndexFilters" ;
43
+ import { IndexFilters , getDefaultIndex } from "./IndexFilters" ;
46
44
47
45
export function DataFilters ( {
48
46
defaultDocument,
@@ -296,10 +294,37 @@ export function DataFilters({
296
294
</ Button >
297
295
) : (
298
296
hasFilters && (
299
- < p className = "ml-1 flex gap-0.5 text-xs font-medium text-content-secondary" >
300
- < CheckIcon />
301
- Filters applied
302
- </ p >
297
+ < div className = "flex w-full items-center gap-1" >
298
+ < p className = "ml-1 flex gap-0.5 text-xs font-medium text-content-secondary" >
299
+ < CheckIcon />
300
+ Filters applied
301
+ </ p >
302
+ < Button
303
+ size = "xs"
304
+ variant = "neutral"
305
+ className = "ml-auto text-xs"
306
+ onClick = { ( ) => {
307
+ onChangeFilters ( {
308
+ clauses : [ ] ,
309
+ index : shownFilters . index
310
+ ? {
311
+ name : shownFilters . index . name ,
312
+ clauses : shownFilters . index . clauses . map (
313
+ ( clause ) => ( {
314
+ ...clause ,
315
+ enabled : false ,
316
+ } ) ,
317
+ ) as
318
+ | FilterByIndex [ ]
319
+ | [ ...FilterByIndex [ ] , FilterByIndexRange ] ,
320
+ }
321
+ : undefined ,
322
+ } ) ;
323
+ } }
324
+ >
325
+ Clear filters
326
+ </ Button >
327
+ </ div >
303
328
)
304
329
) }
305
330
{ dataFetchErrors && dataFetchErrors . length > 0 && (
@@ -440,10 +465,7 @@ function useDataFilters({
440
465
draftFilters ??
441
466
( {
442
467
clauses : [ ] ,
443
- index : {
444
- name : DEFAULT_INDEX_NAME ,
445
- clauses : [ getDefaultIndexClause ( ) ] ,
446
- } ,
468
+ index : getDefaultIndex ( ) ,
447
469
} as FilterExpression ) ,
448
470
[ draftFilters ] ,
449
471
) ;
@@ -499,10 +521,7 @@ function useDataFilters({
499
521
...shownFilters . clauses . slice ( 0 , idx ) ,
500
522
...shownFilters . clauses . slice ( idx + 1 ) ,
501
523
] ,
502
- index : shownFilters . index || {
503
- name : DEFAULT_INDEX_NAME ,
504
- clauses : [ getDefaultIndexClause ( ) ] ,
505
- } ,
524
+ index : shownFilters . index || getDefaultIndex ( ) ,
506
525
} as FilterExpression ;
507
526
setDraftFilters ( newFilters ) ;
508
527
} ,
@@ -518,10 +537,7 @@ function useDataFilters({
518
537
generateNewFilter ( ) ,
519
538
...shownFilters . clauses . slice ( idx ) ,
520
539
] ,
521
- index : shownFilters . index || {
522
- name : DEFAULT_INDEX_NAME ,
523
- clauses : [ getDefaultIndexClause ( ) ] ,
524
- } ,
540
+ index : shownFilters . index || getDefaultIndex ( ) ,
525
541
} as FilterExpression ;
526
542
setDraftFilters ( newFilters ) ;
527
543
} ,
0 commit comments