Skip to content

Commit dc2ec81

Browse files
anaisbergSimonClo
authored andcommitted
♻️ extract add row cal span compute
1 parent 6e8f360 commit dc2ec81

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

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

Lines changed: 2 additions & 12 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, ICellRendererParams } from 'ag-grid-community';
22
import { AgGridReact } from 'ag-grid-react';
33
import { useEffect } from 'react';
44

@@ -12,7 +12,7 @@ import {
1212
import { AddButtonComponent } from './AddColumnButton';
1313
import { useColumns, useRows } from './hooks';
1414
import { DatabaseRow } from './types';
15-
import { addRowCellRenderer, createNewRow } from './utils';
15+
import { addRowCellRenderer, createNewRow, newRowColSpan } from './utils';
1616

1717
export const DatabaseGrid = ({
1818
documentId,
@@ -31,16 +31,6 @@ export const DatabaseGrid = ({
3131
const { rowData, setRowData } = useRows();
3232
const { colDefs, setColDefs } = useColumns();
3333

34-
const newRowColSpan = (params: ColSpanParams<Record<string, string>>) => {
35-
const colsValues = params.data ?? {};
36-
const isNewRow = Object.values(colsValues)[0]?.includes('new');
37-
if (isNewRow) {
38-
return Object.keys(colsValues).length;
39-
}
40-
41-
return 1;
42-
};
43-
4434
useEffect(() => {
4535
const filteredEntries = Object.entries(tableData).filter(
4636
([key]) => key !== 'id' && key !== 'manualSort',

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
ColSpanParams,
23
ICellRendererParams,
34
SizeColumnsToContentStrategy,
45
} from 'ag-grid-community';
@@ -45,3 +46,15 @@ export const addRowCellRenderer = (
4546
}
4647
return undefined;
4748
};
49+
50+
export const newRowColSpan = (
51+
params: ColSpanParams<Record<string, string>>,
52+
) => {
53+
const colsValues = params.data ?? {};
54+
const isNewRow = Object.values(colsValues)[0]?.includes('new');
55+
if (isNewRow) {
56+
return Object.keys(colsValues).length;
57+
}
58+
59+
return 1;
60+
};

0 commit comments

Comments
 (0)