Skip to content

Commit

Permalink
Merge pull request #1519 from rowyio/rc
Browse files Browse the repository at this point in the history
Rc
  • Loading branch information
shamsmosowi authored Jan 2, 2024
2 parents 68b91e7 + a8c70f2 commit f8e6aa8
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 27 deletions.
12 changes: 10 additions & 2 deletions src/atoms/tableScope/rowActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);
}
}
Expand All @@ -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,
}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
});

Expand Down
7 changes: 2 additions & 5 deletions src/components/TableSettingsDialog/TableName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <ShortTextComponent {...props} />;
}
2 changes: 1 addition & 1 deletion src/components/TableSettingsDialog/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions src/components/TableToolbar/Filters/FilterInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default function FilterInputs({
column: selectedColumn,
_rowy_ref: {},
value: query.value,
onSubmit: () => {},
onChange: (value: any) => {
const newQuery = {
...query,
Expand Down
4 changes: 2 additions & 2 deletions src/components/fields/Number/SideDrawerField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getFieldId } from "@src/components/SideDrawer/utils";
export default function Number_({
column,
value,
onChange,
onSubmit,
onChange = () => {},
onSubmit = () => {},
disabled,
}: ISideDrawerFieldProps<number | string>) {
return (
Expand Down
42 changes: 29 additions & 13 deletions src/hooks/useFirestoreCollectionWithAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
);
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/types/table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ export type UpdateDocFunction<T = TableRow> = (
* @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<T = TableRow> = (
path: string,
update: Partial<T>,
deleteFields?: string[],
options?: ArrayTableRowData
options?: ArrayTableRowData & { useSet?: boolean }
) => Promise<void>;

/**
Expand Down

0 comments on commit f8e6aa8

Please sign in to comment.