Skip to content

Commit b7273dd

Browse files
anaisbergSimonClo
authored andcommitted
♻️ extract cell renderer
1 parent 6bee9ba commit b7273dd

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ColDef, ColSpanParams, ICellRendererParams } from 'ag-grid-community';
1+
import { ColDef, ColSpanParams } from 'ag-grid-community';
22
import { AgGridReact } from 'ag-grid-react';
33
import { useEffect, useRef } from 'react';
44

@@ -10,9 +10,8 @@ import {
1010
} from '@/features/grist';
1111

1212
import { AddButtonComponent } from './AddColumnButton';
13-
import { AddRowButton } from './AddRowButton';
1413
import { useColumns, useRows } from './hooks';
15-
import { createNewRow } from './utils';
14+
import { addRowCellRenderer, createNewRow } from './utils';
1615

1716
export const DatabaseGrid = ({
1817
documentId,
@@ -81,22 +80,7 @@ export const DatabaseGrid = ({
8180
const columns: ColDef[] = columnNames.map((key) => ({
8281
field: key,
8382
colSpan: newRowColSpan,
84-
cellRendererSelector: (
85-
params: ICellRendererParams<Record<string, string>>,
86-
) => {
87-
if (params.data) {
88-
const addRowButton = {
89-
component: AddRowButton,
90-
params: { values: params.data },
91-
};
92-
93-
if (Object.values(params.data)[0]?.includes('new')) {
94-
return addRowButton;
95-
}
96-
return undefined;
97-
}
98-
return undefined;
99-
},
83+
cellRendererSelector: addRowCellRenderer,
10084
}));
10185

10286
setColDefs(columns.concat(addColumnColDef));

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { ColDef } from 'ag-grid-community';
1+
import { ColDef, ICellRendererParams } from 'ag-grid-community';
2+
3+
import { AddRowButton } from './AddRowButton';
24

35
export const createNewRow = (
46
value: string | undefined,
@@ -15,3 +17,18 @@ export const createNewRow = (
1517

1618
return addNewRow;
1719
};
20+
21+
export const addRowCellRenderer = (
22+
params: ICellRendererParams<Record<string, string>>,
23+
) => {
24+
if (params.data) {
25+
const addRowButton = {
26+
component: AddRowButton,
27+
};
28+
if (Object.values(params.data)[0]?.includes('new')) {
29+
return addRowButton;
30+
}
31+
return undefined;
32+
}
33+
return undefined;
34+
};

0 commit comments

Comments
 (0)