11import { ValidatorJSON , Value , convexToJson } from "convex/values" ;
22import React , { useCallback , useState } from "react" ;
33import {
4+ DatabaseIndexFilterClause ,
45 FilterByIndex ,
56 FilterByIndexRange ,
67} from "system-udfs/convex/_system/frontend/lib/filters" ;
78import { Checkbox } from "@ui/Checkbox" ;
8- import { ObjectEditor } from "@common/elements/ObjectEditor/ObjectEditor" ;
99import { Combobox , Option } from "@ui/Combobox" ;
1010import { DateTimePicker } from "@common/features/data/components/FilterEditor/DateTimePicker" ;
1111import { cn } from "@ui/cn" ;
12- import { UNDEFINED_PLACEHOLDER } from "system-udfs/convex/_system/frontend/lib/values" ;
1312import { Tooltip } from "@ui/Tooltip" ;
1413import { ExclamationTriangleIcon } from "@radix-ui/react-icons" ;
15-
16- export type IndexFilterState = FilterByIndex | FilterByIndexRange ;
17-
18- export type IndexFilterEditorProps = {
19- idx : number ;
20- field : string ;
21- error : string | undefined ;
22- onChange ( filter : IndexFilterState , idx : number ) : void ;
23- onApplyFilters ( ) : void ;
24- onError ( idx : number , errors : string [ ] ) : void ;
25- filter : IndexFilterState ;
26- autoFocusValueEditor ?: boolean ;
27- documentValidator ?: ValidatorJSON ;
28- shouldSurfaceValidatorErrors ?: boolean ;
29- previousFiltersEnabled : boolean [ ] ;
30- nextFiltersEnabled ?: boolean [ ] ;
31- } ;
14+ import { ObjectEditorWithPlaceholder } from "./ObjectEditorWithPlaceholder" ;
3215
3316// Options for the filter type combobox
3417const filterTypeOptions : Option < string > [ ] = [
@@ -44,7 +27,7 @@ const filterTypeOptions: Option<string>[] = [
4427const RANGE_ERROR_MESSAGE =
4528 "The lower bound of this range is currently set to a value that is higher than the upper bound. This filter would never match any documents." ;
4629
47- export function IndexFilterEditor ( {
30+ export function DatabaseIndexFilterEditor ( {
4831 idx,
4932 field,
5033 error,
@@ -57,7 +40,20 @@ export function IndexFilterEditor({
5740 shouldSurfaceValidatorErrors,
5841 previousFiltersEnabled,
5942 nextFiltersEnabled = [ ] ,
60- } : IndexFilterEditorProps ) {
43+ } : {
44+ idx : number ;
45+ field : string ;
46+ error : string | undefined ;
47+ onChange ( filter : DatabaseIndexFilterClause , idx : number ) : void ;
48+ onApplyFilters ( ) : void ;
49+ onError ( idx : number , errors : string [ ] ) : void ;
50+ filter : DatabaseIndexFilterClause ;
51+ autoFocusValueEditor ?: boolean ;
52+ documentValidator ?: ValidatorJSON ;
53+ shouldSurfaceValidatorErrors ?: boolean ;
54+ previousFiltersEnabled : boolean [ ] ;
55+ nextFiltersEnabled ?: boolean [ ] ;
56+ } ) {
6157 const [ prevIsLastEnabledFilter , setPrevIsLastEnabledFilter ] = useState <
6258 boolean | null
6359 > ( null ) ;
@@ -475,7 +471,7 @@ export function IndexFilterEditor({
475471 path = { `indexFilter${ idx } -${ field } -${ filter . type } ` }
476472 autoFocus = { autoFocusValueEditor }
477473 className = "rounded-l-none rounded-r"
478- filter = { filter }
474+ enabled = { filter . enabled }
479475 onApplyFilters = { onApplyFilters }
480476 handleError = { handleError }
481477 documentValidator = { documentValidator }
@@ -516,7 +512,7 @@ export function IndexFilterEditor({
516512 path = { `indexFilter${ idx } -${ field } -${ filter . type } ` }
517513 autoFocus = { autoFocusValueEditor }
518514 className = "rounded-l-none rounded-r"
519- filter = { filter }
515+ enabled = { filter . enabled }
520516 onApplyFilters = { onApplyFilters }
521517 handleError = { handleError }
522518 documentValidator = { documentValidator }
@@ -546,7 +542,7 @@ export function IndexFilterEditor({
546542 path = { `indexFilterLower${ idx } -${ field } -${ filter . type } ` }
547543 autoFocus = { autoFocusValueEditor }
548544 className = "rounded-l-none rounded-tr rounded-br-none"
549- filter = { filter }
545+ enabled = { filter . enabled }
550546 onApplyFilters = { onApplyFilters }
551547 handleError = { handleError }
552548 documentValidator = { documentValidator }
@@ -569,7 +565,7 @@ export function IndexFilterEditor({
569565 onChangeHandler = { handleUpperValueChange }
570566 path = { `indexFilterUpper${ idx } -${ field } -${ filter . type } ` }
571567 className = "rounded-l-none rounded-tr-none rounded-br border-t-0"
572- filter = { filter }
568+ enabled = { filter . enabled }
573569 onApplyFilters = { onApplyFilters }
574570 handleError = { handleError }
575571 documentValidator = { documentValidator }
@@ -684,77 +680,3 @@ export function IndexFilterEditor({
684680 </ div >
685681 ) ;
686682}
687-
688- // Create a separate component for ObjectEditor with placeholder
689- function ObjectEditorWithPlaceholder ( {
690- value,
691- onChangeHandler,
692- path,
693- autoFocus = false ,
694- className = "" ,
695- filter,
696- onApplyFilters,
697- handleError,
698- documentValidator,
699- shouldSurfaceValidatorErrors,
700- } : {
701- value : any ;
702- onChangeHandler : ( value ?: Value ) => void ;
703- path : string ;
704- autoFocus ?: boolean ;
705- className ?: string ;
706- filter : IndexFilterState ;
707- onApplyFilters : ( ) => void ;
708- handleError : ( errors : string [ ] ) => void ;
709- documentValidator ?: ValidatorJSON ;
710- shouldSurfaceValidatorErrors ?: boolean ;
711- } ) {
712- const [ innerText , setInnerText ] = useState ( "" ) ;
713-
714- return (
715- < >
716- { filter . enabled &&
717- innerText === "" &&
718- value === UNDEFINED_PLACEHOLDER && (
719- < div
720- className = "pointer-events-none absolute z-50 font-mono text-xs text-content-secondary italic"
721- data-testid = "undefined-placeholder"
722- style = { {
723- marginTop : "5px" ,
724- marginLeft : "11px" ,
725- } }
726- >
727- unset
728- </ div >
729- ) }
730- < ObjectEditor
731- key = { path }
732- className = { cn (
733- "w-full min-w-4 border focus-within:border focus-within:border-border-selected" ,
734- filter . enabled && "border-l-transparent" ,
735- className ,
736- ) }
737- editorClassname = { cn (
738- "mt-0 rounded-sm bg-background-secondary px-2 py-1 text-xs" ,
739- className ,
740- ) }
741- allowTopLevelUndefined
742- size = "sm"
743- disableFolding
744- defaultValue = { value === UNDEFINED_PLACEHOLDER ? undefined : value }
745- onChange = { onChangeHandler }
746- onError = { handleError }
747- path = { path }
748- autoFocus = { autoFocus }
749- disableFind
750- saveAction = { onApplyFilters }
751- enterSaves
752- mode = "editField"
753- validator = { documentValidator }
754- shouldSurfaceValidatorErrors = { shouldSurfaceValidatorErrors }
755- disabled = { ! filter . enabled }
756- onChangeInnerText = { setInnerText }
757- />
758- </ >
759- ) ;
760- }
0 commit comments