Skip to content

Commit f8e6aa8

Browse files
authored
Merge pull request #1519 from rowyio/rc
Rc
2 parents 68b91e7 + a8c70f2 commit f8e6aa8

File tree

8 files changed

+50
-27
lines changed

8 files changed

+50
-27
lines changed

src/atoms/tableScope/rowActions.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,11 @@ export const updateFieldAtom = atom(
486486
row._rowy_ref.path,
487487
omitRowyFields(newRowValues),
488488
deleteField ? [fieldName] : [],
489-
arrayTableData
489+
{
490+
...arrayTableData,
491+
// using set if we are updating a nested field
492+
useSet: fieldName.split(".").length > 1,
493+
}
490494
);
491495
}
492496
}
@@ -496,7 +500,11 @@ export const updateFieldAtom = atom(
496500
row._rowy_ref.path,
497501
omitRowyFields(dbUpdate),
498502
deleteField ? [fieldName] : [],
499-
arrayTableData
503+
{
504+
...arrayTableData,
505+
// using set if we are updating a nested field
506+
useSet: fieldName.split(".").length > 1,
507+
}
500508
);
501509
}
502510

src/components/TableModals/ImportCsvWizard/ImportCsvWizard.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export default function ImportCsvWizard({ onClose }: ITableModalProps) {
142142
let requiredUploads: any = {};
143143
columns.forEach((column, index) => {
144144
if (needsConverter(column.type)) {
145-
requiredConverts[index] = getConverter(column.type);
145+
requiredConverts[column.columnKey] = getConverter(column.type);
146146
// console.log({ needsUploadTypes }, column.type);
147147
if (needsUploadTypes(column.type)) {
148148
requiredUploads[column.fieldName + ""] = true;
@@ -215,8 +215,8 @@ export default function ImportCsvWizard({ onClose }: ITableModalProps) {
215215
const newValidRows = validRows.map((row) => {
216216
// Convert required values
217217
Object.keys(row).forEach((key, i) => {
218-
if (requiredConverts[i]) {
219-
row[key] = requiredConverts[i](row[key]);
218+
if (requiredConverts[key]) {
219+
row[key] = requiredConverts[key](row[key]);
220220
}
221221
});
222222

src/components/TableSettingsDialog/TableName.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ITableNameProps extends IShortTextComponentProps {
1212

1313
export default function TableName({ watchedField, ...props }: ITableNameProps) {
1414
const {
15-
field: { onChange, value },
15+
field: { onChange },
1616
useFormMethods: { control },
1717
disabled,
1818
} = props;
@@ -25,12 +25,9 @@ export default function TableName({ watchedField, ...props }: ITableNameProps) {
2525
if (!touched && typeof watchedValue === "string" && !!watchedValue) {
2626
// if table name field is not touched, and watched value is valid, set table name to watched value
2727
onChange(startCase(watchedValue));
28-
} else if (typeof value === "string") {
29-
// otherwise if table name is valid, set watched value to table name
30-
onChange(startCase(value.trim()));
3128
}
3229
}
33-
}, [watchedValue, disabled, onChange, value]);
30+
}, [watchedValue, disabled]);
3431

3532
return <ShortTextComponent {...props} />;
3633
}

src/components/TableSettingsDialog/form.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export const tableSettings = (
213213
name: "name",
214214
label: "Table name",
215215
required: true,
216-
watchedField: "name",
216+
watchedField: "collection",
217217
assistiveText: "User-facing name for this table",
218218
autoFocus: true,
219219
gridCols: { xs: 12, sm: 6 },

src/components/TableToolbar/Filters/FilterInputs.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export default function FilterInputs({
165165
column: selectedColumn,
166166
_rowy_ref: {},
167167
value: query.value,
168+
onSubmit: () => {},
168169
onChange: (value: any) => {
169170
const newQuery = {
170171
...query,

src/components/fields/Number/SideDrawerField.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { getFieldId } from "@src/components/SideDrawer/utils";
66
export default function Number_({
77
column,
88
value,
9-
onChange,
10-
onSubmit,
9+
onChange = () => {},
10+
onSubmit = () => {},
1111
disabled,
1212
}: ISideDrawerFieldProps<number | string>) {
1313
return (

src/hooks/useFirestoreCollectionWithAtom.ts

+29-13
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,37 @@ export function useFirestoreCollectionWithAtom<
264264
// set the atom’s value to a function that updates a doc in the collection
265265
if (updateDocAtom) {
266266
setUpdateDocAtom(
267-
() => async (path: string, update: T, deleteFields?: string[]) => {
268-
const updateToDb = { ...update };
267+
() =>
268+
async (
269+
path: string,
270+
update: T,
271+
deleteFields?: string[],
272+
options?: {
273+
useSet?: boolean;
274+
}
275+
) => {
276+
const updateToDb = { ...update };
269277

270-
if (Array.isArray(deleteFields)) {
271-
for (const field of deleteFields) {
272-
set(updateToDb as any, field, deleteField());
278+
if (Array.isArray(deleteFields)) {
279+
for (const field of deleteFields) {
280+
set(updateToDb as any, field, deleteField());
281+
}
282+
}
283+
284+
if (options?.useSet) {
285+
return await setDoc(doc(firebaseDb, path), updateToDb, {
286+
merge: true,
287+
});
288+
}
289+
290+
try {
291+
return await updateDoc(doc(firebaseDb, path), updateToDb);
292+
} catch (e) {
293+
return await setDoc(doc(firebaseDb, path), updateToDb, {
294+
merge: true,
295+
});
273296
}
274297
}
275-
try {
276-
return await updateDoc(doc(firebaseDb, path), updateToDb);
277-
} catch (e) {
278-
return await setDoc(doc(firebaseDb, path), updateToDb, {
279-
merge: true,
280-
});
281-
}
282-
}
283298
);
284299
}
285300

@@ -443,6 +458,7 @@ export const tableFiltersToFirestoreFilters = (filters: TableFilter[]) => {
443458
continue;
444459
} else if (filter.operator === "is-not-empty") {
445460
firestoreFilters.push(where(filter.key, "!=", ""));
461+
continue;
446462
} else if (filter.operator === "array-contains") {
447463
if (!filter.value || !filter.value.length) continue;
448464
// make the value as a singular string

src/types/table.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ export type UpdateDocFunction<T = TableRow> = (
2626
* @param path - The full path to the doc
2727
* @param update - The updates to be deeply merged with the existing doc. Note arrays should be ovewritten to match Firestore set with merge behavior
2828
* @param deleteFields - Optionally, fields to be deleted from the doc. Access nested fields with dot notation
29+
* @param options - Optionally, filed to pass extra data to the function
2930
* @returns Promise
3031
*/
3132
export type UpdateCollectionDocFunction<T = TableRow> = (
3233
path: string,
3334
update: Partial<T>,
3435
deleteFields?: string[],
35-
options?: ArrayTableRowData
36+
options?: ArrayTableRowData & { useSet?: boolean }
3637
) => Promise<void>;
3738

3839
/**

0 commit comments

Comments
 (0)