Skip to content

Commit b381fa6

Browse files
anaisbergSimonClo
authored andcommitted
🐛 pin add row to bottom
1 parent 91682df commit b381fa6

File tree

1 file changed

+6
-4
lines changed
  • src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ICellRendererParams,
66
} from 'ag-grid-community';
77
import { AgGridReact } from 'ag-grid-react';
8-
import { useCallback, useEffect } from 'react';
8+
import { useCallback, useEffect, useMemo } from 'react';
99

1010
import { Box } from '@/components';
1111
import {
@@ -88,7 +88,7 @@ export const DatabaseGrid = ({
8888
// eslint-disable-next-line react-hooks/exhaustive-deps
8989
}, [tableData]);
9090

91-
useEffect(() => {
91+
const addNewRow = useMemo(() => {
9292
const columnNames = getColumnNames(colDefs);
9393
const lastRow = rowData?.[rowData.length - 1];
9494
if (lastRow && Object.values(lastRow).length > 0) {
@@ -97,8 +97,9 @@ export const DatabaseGrid = ({
9797
return;
9898
}
9999
}
100-
const addNewRow = createNewRow({ value: ADD_NEW_ROW, columnNames });
101-
setRowData((prev) => [...(prev ? prev : []), addNewRow]);
100+
const newRow = createNewRow({ value: ADD_NEW_ROW, columnNames });
101+
102+
return newRow;
102103
// eslint-disable-next-line react-hooks/exhaustive-deps
103104
}, [colDefs]);
104105

@@ -167,6 +168,7 @@ export const DatabaseGrid = ({
167168
domLayout="autoHeight"
168169
enableCellSpan={true}
169170
onCellEditingStopped={onCellEditingStopped}
171+
pinnedBottomRowData={[addNewRow]}
170172
/>
171173
</Box>
172174
<AddButtonComponent addColumn={addColumn} />

0 commit comments

Comments
 (0)