diff --git a/src/atoms/tableScope/rowActions.ts b/src/atoms/tableScope/rowActions.ts index 4185fa248..af5caddf8 100644 --- a/src/atoms/tableScope/rowActions.ts +++ b/src/atoms/tableScope/rowActions.ts @@ -486,7 +486,11 @@ export const updateFieldAtom = atom( row._rowy_ref.path, omitRowyFields(newRowValues), deleteField ? [fieldName] : [], - arrayTableData + { + ...arrayTableData, + // using set if we are updating a nested field + useSet: fieldName.split(".").length > 1, + } ); } } @@ -496,7 +500,11 @@ export const updateFieldAtom = atom( row._rowy_ref.path, omitRowyFields(dbUpdate), deleteField ? [fieldName] : [], - arrayTableData + { + ...arrayTableData, + // using set if we are updating a nested field + useSet: fieldName.split(".").length > 1, + } ); } diff --git a/src/components/TableToolbar/Filters/FilterInputs.tsx b/src/components/TableToolbar/Filters/FilterInputs.tsx index d236bf1c9..be023e9e6 100644 --- a/src/components/TableToolbar/Filters/FilterInputs.tsx +++ b/src/components/TableToolbar/Filters/FilterInputs.tsx @@ -165,6 +165,7 @@ export default function FilterInputs({ column: selectedColumn, _rowy_ref: {}, value: query.value, + onSubmit: () => {}, onChange: (value: any) => { const newQuery = { ...query, diff --git a/src/components/fields/Number/SideDrawerField.tsx b/src/components/fields/Number/SideDrawerField.tsx index 76212c8cf..95b51d6ac 100644 --- a/src/components/fields/Number/SideDrawerField.tsx +++ b/src/components/fields/Number/SideDrawerField.tsx @@ -6,8 +6,8 @@ import { getFieldId } from "@src/components/SideDrawer/utils"; export default function Number_({ column, value, - onChange, - onSubmit, + onChange = () => {}, + onSubmit = () => {}, disabled, }: ISideDrawerFieldProps) { return ( diff --git a/src/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index 8e870dd99..901d2970a 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -264,22 +264,37 @@ export function useFirestoreCollectionWithAtom< // set the atom’s value to a function that updates a doc in the collection if (updateDocAtom) { setUpdateDocAtom( - () => async (path: string, update: T, deleteFields?: string[]) => { - const updateToDb = { ...update }; + () => + async ( + path: string, + update: T, + deleteFields?: string[], + options?: { + useSet?: boolean; + } + ) => { + const updateToDb = { ...update }; - if (Array.isArray(deleteFields)) { - for (const field of deleteFields) { - set(updateToDb as any, field, deleteField()); + if (Array.isArray(deleteFields)) { + for (const field of deleteFields) { + set(updateToDb as any, field, deleteField()); + } + } + + if (options?.useSet) { + return await setDoc(doc(firebaseDb, path), updateToDb, { + merge: true, + }); + } + + try { + return await updateDoc(doc(firebaseDb, path), updateToDb); + } catch (e) { + return await setDoc(doc(firebaseDb, path), updateToDb, { + merge: true, + }); } } - try { - return await updateDoc(doc(firebaseDb, path), updateToDb); - } catch (e) { - return await setDoc(doc(firebaseDb, path), updateToDb, { - merge: true, - }); - } - } ); } @@ -443,6 +458,7 @@ export const tableFiltersToFirestoreFilters = (filters: TableFilter[]) => { continue; } else if (filter.operator === "is-not-empty") { firestoreFilters.push(where(filter.key, "!=", "")); + continue; } else if (filter.operator === "array-contains") { if (!filter.value || !filter.value.length) continue; // make the value as a singular string diff --git a/src/types/table.d.ts b/src/types/table.d.ts index db6754e6e..2fd8b5324 100644 --- a/src/types/table.d.ts +++ b/src/types/table.d.ts @@ -26,13 +26,14 @@ export type UpdateDocFunction = ( * @param path - The full path to the doc * @param update - The updates to be deeply merged with the existing doc. Note arrays should be ovewritten to match Firestore set with merge behavior * @param deleteFields - Optionally, fields to be deleted from the doc. Access nested fields with dot notation + * @param options - Optionally, filed to pass extra data to the function * @returns Promise */ export type UpdateCollectionDocFunction = ( path: string, update: Partial, deleteFields?: string[], - options?: ArrayTableRowData + options?: ArrayTableRowData & { useSet?: boolean } ) => Promise; /**