diff --git a/src/components/fields/Array/Filter.tsx b/src/components/fields/Array/Filter.tsx new file mode 100644 index 000000000..d30a60f21 --- /dev/null +++ b/src/components/fields/Array/Filter.tsx @@ -0,0 +1,20 @@ +import { IFilterOperator } from "@src/components/fields/types"; + +export const operators: IFilterOperator[] = [ + { + label: "equals", + value: "==", + }, + { + label: "not equals", + value: "!=", + }, + { + label: "contains the following", + value: "array-contains", + }, + { + label: "contains atleast one of the following", + value: "array-contains-any", + }, +]; diff --git a/src/components/fields/Array/SideDrawerField/index.tsx b/src/components/fields/Array/SideDrawerField/index.tsx index 4f6efd098..e1532b078 100644 --- a/src/components/fields/Array/SideDrawerField/index.tsx +++ b/src/components/fields/Array/SideDrawerField/index.tsx @@ -120,7 +120,7 @@ export default function ArraySideDrawerField({ }: ISideDrawerFieldProps) { const handleAddNew = (fieldType: ArraySupportedFiledTypes) => { onChange([...(value || []), SupportedTypes[fieldType].initialValue]); - onDirty(true); + if (onDirty) onDirty(true); }; const handleChange = (newValue_: any, indexUpdated: number) => { onChange( @@ -137,13 +137,13 @@ export default function ArraySideDrawerField({ const handleRemove = (index: number) => { value.splice(index, 1); onChange([...value]); - onDirty(true); + if (onDirty) onDirty(true); onSubmit(); }; const handleClearField = () => { onChange([]); - onSubmit(); + if (onSubmit) onSubmit(); }; function handleOnDragEnd(result: DropResult) { @@ -157,7 +157,7 @@ export default function ArraySideDrawerField({ const [removed] = list.splice(result.source.index, 1); list.splice(result.destination.index, 0, removed); onChange(list); - onSubmit(); + if (onSubmit) onSubmit(); } if (value === undefined || Array.isArray(value)) { @@ -166,7 +166,11 @@ export default function ArraySideDrawerField({ {(provided) => ( - + {(value || []).map((v: any, index: number) => ( - + {props.operator === "array-contains" ? ( + value?.length < 1 ? ( + + ) : ( + <> + ) + ) : ( + + )} ); } diff --git a/src/components/fields/Array/index.tsx b/src/components/fields/Array/index.tsx index fe00851e7..0c750f215 100644 --- a/src/components/fields/Array/index.tsx +++ b/src/components/fields/Array/index.tsx @@ -5,6 +5,7 @@ import { IFieldConfig, FieldType } from "@src/components/fields/types"; import withRenderTableCell from "@src/components/Table/TableCell/withRenderTableCell"; import DisplayCell from "./DisplayCell"; +import { operators } from "./Filter"; import BasicContextMenuActions from "@src/components/Table/ContextMenu/BasicCellContextMenuActions"; @@ -27,6 +28,7 @@ export const config: IFieldConfig = { popoverProps: { PaperProps: { sx: { p: 1, minWidth: "200px" } } }, }), SideDrawerField, + filter: { operators, defaultValue: [] }, requireConfiguration: false, contextMenuActions: BasicContextMenuActions, }; diff --git a/src/components/fields/types.ts b/src/components/fields/types.ts index d69a7be7f..2e35d7126 100644 --- a/src/components/fields/types.ts +++ b/src/components/fields/types.ts @@ -94,6 +94,8 @@ export interface ISideDrawerFieldProps { disabled: boolean; row: TableRow; + + operator?: TableFilter["operator"]; } export interface ISettingsProps { diff --git a/src/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index 16a7fb92b..0681d283c 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -405,6 +405,13 @@ export const tableFiltersToFirestoreFilters = (filters: TableFilter[]) => { where(filter.key.concat(".hex"), "!=", filter.value.hex.toString()) ); continue; + } else if (filter.operator === "array-contains") { + if (!filter.value || !filter.value.length) continue; + // make the value as a singular string + firestoreFilters.push( + where(filter.key, filter.operator as WhereFilterOp, filter.value[0]) + ); + continue; } firestoreFilters.push( where(filter.key, filter.operator as WhereFilterOp, filter.value)