Skip to content

Commit fc912a1

Browse files
anaisbergSimonClo
authored andcommitted
🐛 create new row with undefined values
1 parent cbb1282 commit fc912a1

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock/AddRowButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const AddRowButton = ({
1212
setRowData: Dispatch<SetStateAction<DatabaseRow[] | undefined>>;
1313
}) => {
1414
const addRow = () => {
15-
const newRow = createNewRow('', columns);
15+
const newRow = createNewRow({ columnNames: columns });
1616
setRowData((prev: DatabaseRow[] | undefined) => {
1717
if (prev === undefined) {
1818
return [newRow];

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock/DatabaseGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const DatabaseGrid = ({
9494
const columnNames = (colDefs ?? [])
9595
.map((col) => col.field)
9696
.filter((col) => col !== undefined);
97-
const addNewRow = createNewRow('+ new row', columnNames);
97+
const addNewRow = createNewRow({ value: '+ new row', columnNames });
9898
setRowData((prev) => [...(prev ? prev : []), addNewRow]);
9999
}, [colDefs, gridRef, setRowData]);
100100

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock/utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ export const autoSizeStrategy: SizeColumnsToContentStrategy = {
1111
type: 'fitCellContents',
1212
};
1313

14-
export const createNewRow = (
15-
value: string | undefined,
16-
columnNames: string[] | undefined,
17-
) => {
18-
const defaultValue = value ?? '';
19-
const addNewRow: Record<string, string> = {};
14+
export const createNewRow = ({
15+
columnNames,
16+
value = undefined,
17+
}: {
18+
value?: string;
19+
columnNames: string[] | undefined;
20+
}) => {
21+
const addNewRow: DatabaseRow = {};
2022
columnNames?.forEach((name) => {
2123
if (name !== undefined) {
22-
addNewRow[name] = defaultValue;
24+
addNewRow[name] = value;
2325
}
2426
});
2527

0 commit comments

Comments
 (0)