From dc229d15cba06edf5db58eafdf088ed1907d8d38 Mon Sep 17 00:00:00 2001 From: Anish Roy <6275anishroy@gmail.com> Date: Thu, 16 Nov 2023 15:12:29 +0530 Subject: [PATCH 1/9] fix: nested key column updating whole object --- src/atoms/tableScope/rowActions.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/atoms/tableScope/rowActions.ts b/src/atoms/tableScope/rowActions.ts index 4185fa248..a54ce5e3a 100644 --- a/src/atoms/tableScope/rowActions.ts +++ b/src/atoms/tableScope/rowActions.ts @@ -406,6 +406,13 @@ export const updateFieldAtom = atom( if (isEqual(currentValue, value)) return; } // Otherwise, apply the update + + // Check if nested path + if (fieldName.split(".").length > 1) { + const p = tableRows.find((r) => r._rowy_ref.path === path); + // add the parent object + _set(update, fieldName.split(".")[0], _get(p, fieldName.split(".")[0])); + } _set(update, fieldName, value); } From 88850420ddd6e0ac928580ebf70e17ae9b9a400e Mon Sep 17 00:00:00 2001 From: Zee Date: Thu, 16 Nov 2023 20:45:05 +0530 Subject: [PATCH 2/9] fix: #1483 --- src/components/fields/Number/SideDrawerField.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ( From baafde20f3881358916d2d4042244617b48007b3 Mon Sep 17 00:00:00 2001 From: Anish Roy <6275anishroy@gmail.com> Date: Fri, 17 Nov 2023 10:46:33 +0530 Subject: [PATCH 3/9] use Set if updating a nested field --- src/atoms/tableScope/rowActions.ts | 19 ++++++---- src/hooks/useFirestoreCollectionWithAtom.ts | 41 ++++++++++++++------- src/types/table.d.ts | 3 +- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/atoms/tableScope/rowActions.ts b/src/atoms/tableScope/rowActions.ts index a54ce5e3a..9f1834a01 100644 --- a/src/atoms/tableScope/rowActions.ts +++ b/src/atoms/tableScope/rowActions.ts @@ -407,12 +407,6 @@ export const updateFieldAtom = atom( } // Otherwise, apply the update - // Check if nested path - if (fieldName.split(".").length > 1) { - const p = tableRows.find((r) => r._rowy_ref.path === path); - // add the parent object - _set(update, fieldName.split(".")[0], _get(p, fieldName.split(".")[0])); - } _set(update, fieldName, value); } @@ -493,17 +487,26 @@ 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, + } ); } } // Otherwise, update single field in database and write audit update field else { + console.log("newRowValues", fieldName); await updateRowDb( 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/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index fd0fa39e9..7fa980594 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -256,22 +256,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, - }); - } - } ); } diff --git a/src/types/table.d.ts b/src/types/table.d.ts index 3ed4b7c35..12dee2d40 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; /** From 8a8292630f89eaff0d0544ef9d2eb2dd50c23c67 Mon Sep 17 00:00:00 2001 From: Anish Roy <6275anishroy@gmail.com> Date: Fri, 17 Nov 2023 10:47:14 +0530 Subject: [PATCH 4/9] removed logs --- src/atoms/tableScope/rowActions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atoms/tableScope/rowActions.ts b/src/atoms/tableScope/rowActions.ts index 9f1834a01..666b95745 100644 --- a/src/atoms/tableScope/rowActions.ts +++ b/src/atoms/tableScope/rowActions.ts @@ -497,7 +497,6 @@ export const updateFieldAtom = atom( } // Otherwise, update single field in database and write audit update field else { - console.log("newRowValues", fieldName); await updateRowDb( row._rowy_ref.path, omitRowyFields(dbUpdate), From 7ef03cead416da2352a09323b18b6a5d59335aa0 Mon Sep 17 00:00:00 2001 From: Anish Roy <6275anishroy@gmail.com> Date: Fri, 17 Nov 2023 10:48:23 +0530 Subject: [PATCH 5/9] . --- src/atoms/tableScope/rowActions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atoms/tableScope/rowActions.ts b/src/atoms/tableScope/rowActions.ts index 666b95745..af5caddf8 100644 --- a/src/atoms/tableScope/rowActions.ts +++ b/src/atoms/tableScope/rowActions.ts @@ -406,7 +406,6 @@ export const updateFieldAtom = atom( if (isEqual(currentValue, value)) return; } // Otherwise, apply the update - _set(update, fieldName, value); } From 41bbb3b80e1afd7eac9516dd2c70e196ffe55414 Mon Sep 17 00:00:00 2001 From: il3ven Date: Mon, 11 Dec 2023 23:28:09 +0530 Subject: [PATCH 6/9] fix "is-not-empty" filter --- src/hooks/useFirestoreCollectionWithAtom.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hooks/useFirestoreCollectionWithAtom.ts b/src/hooks/useFirestoreCollectionWithAtom.ts index 8e870dd99..2f5f8fbd3 100644 --- a/src/hooks/useFirestoreCollectionWithAtom.ts +++ b/src/hooks/useFirestoreCollectionWithAtom.ts @@ -443,6 +443,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 From 3ec15f0121d3abba45a6a3cb05e839122830c80c Mon Sep 17 00:00:00 2001 From: Zee Date: Tue, 12 Dec 2023 16:01:53 +0530 Subject: [PATCH 7/9] fixing number input --- src/components/TableToolbar/Filters/FilterInputs.tsx | 1 + 1 file changed, 1 insertion(+) 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, From 8a7080a547132049ac0b49df9dbc4c4470888a3f Mon Sep 17 00:00:00 2001 From: Anish Roy <6275anishroy@gmail.com> Date: Thu, 21 Dec 2023 17:51:06 +0530 Subject: [PATCH 8/9] fix(CSV import): error while using a column as row id --- .../TableModals/ImportCsvWizard/ImportCsvWizard.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/TableModals/ImportCsvWizard/ImportCsvWizard.tsx b/src/components/TableModals/ImportCsvWizard/ImportCsvWizard.tsx index f7989d264..098c2927f 100644 --- a/src/components/TableModals/ImportCsvWizard/ImportCsvWizard.tsx +++ b/src/components/TableModals/ImportCsvWizard/ImportCsvWizard.tsx @@ -142,7 +142,7 @@ export default function ImportCsvWizard({ onClose }: ITableModalProps) { let requiredUploads: any = {}; columns.forEach((column, index) => { if (needsConverter(column.type)) { - requiredConverts[index] = getConverter(column.type); + requiredConverts[column.columnKey] = getConverter(column.type); // console.log({ needsUploadTypes }, column.type); if (needsUploadTypes(column.type)) { requiredUploads[column.fieldName + ""] = true; @@ -215,8 +215,8 @@ export default function ImportCsvWizard({ onClose }: ITableModalProps) { const newValidRows = validRows.map((row) => { // Convert required values Object.keys(row).forEach((key, i) => { - if (requiredConverts[i]) { - row[key] = requiredConverts[i](row[key]); + if (requiredConverts[key]) { + row[key] = requiredConverts[key](row[key]); } }); From c421071f59552fea9a1f37bdb3fa11cb80052fad Mon Sep 17 00:00:00 2001 From: Bobby Wang Date: Tue, 2 Jan 2024 01:44:54 +0800 Subject: [PATCH 9/9] fix broken table id prefill for table setup --- src/components/TableSettingsDialog/TableName.tsx | 7 ++----- src/components/TableSettingsDialog/form.tsx | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/TableSettingsDialog/TableName.tsx b/src/components/TableSettingsDialog/TableName.tsx index 36875c11e..1b6204a62 100644 --- a/src/components/TableSettingsDialog/TableName.tsx +++ b/src/components/TableSettingsDialog/TableName.tsx @@ -12,7 +12,7 @@ export interface ITableNameProps extends IShortTextComponentProps { export default function TableName({ watchedField, ...props }: ITableNameProps) { const { - field: { onChange, value }, + field: { onChange }, useFormMethods: { control }, disabled, } = props; @@ -25,12 +25,9 @@ export default function TableName({ watchedField, ...props }: ITableNameProps) { if (!touched && typeof watchedValue === "string" && !!watchedValue) { // if table name field is not touched, and watched value is valid, set table name to watched value onChange(startCase(watchedValue)); - } else if (typeof value === "string") { - // otherwise if table name is valid, set watched value to table name - onChange(startCase(value.trim())); } } - }, [watchedValue, disabled, onChange, value]); + }, [watchedValue, disabled]); return ; } diff --git a/src/components/TableSettingsDialog/form.tsx b/src/components/TableSettingsDialog/form.tsx index 31802e14b..9d611e068 100644 --- a/src/components/TableSettingsDialog/form.tsx +++ b/src/components/TableSettingsDialog/form.tsx @@ -213,7 +213,7 @@ export const tableSettings = ( name: "name", label: "Table name", required: true, - watchedField: "name", + watchedField: "collection", assistiveText: "User-facing name for this table", autoFocus: true, gridCols: { xs: 12, sm: 6 },