Skip to content

Commit a0ec6ca

Browse files
anaisbergSimonClo
authored andcommitted
✨ add new row
1 parent c87e1c8 commit a0ec6ca

File tree

1 file changed

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

1 file changed

+29
-2
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ColDef } from 'ag-grid-community';
1+
import { ColDef, ColSpanParams, themeQuartz } from 'ag-grid-community';
22
import { AgGridReact } from 'ag-grid-react';
3-
import { useEffect, useRef, useState } from 'react';
3+
import { useEffect, useMemo, useRef, useState } from 'react';
44

55
import { Box } from '@/components';
66
import {
@@ -31,6 +31,16 @@ export const DatabaseGrid = ({
3131
useState<Record<string, string | number | boolean>[]>();
3232
const [colDefs, setColDefs] = useState<ColDef[]>();
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+
3444
const addColumnColDef: ColDef = {
3545
headerComponentParams: {
3646
innerHeaderComponent: () =>
@@ -62,11 +72,18 @@ export const DatabaseGrid = ({
6272
rowData1.push(row);
6373
}
6474

75+
const addNewRow: Record<string, string> = {};
76+
for (const [key] of filteredEntries) {
77+
addNewRow[key] = '+ new row';
78+
}
79+
rowData1.push(addNewRow);
80+
6581
setRowData(rowData1);
6682

6783
const columnNames = Object.keys(Object.fromEntries(filteredEntries));
6884
const columns: ColDef[] = columnNames.map((key) => ({
6985
field: key,
86+
colSpan: newRowColSpan,
7087
}));
7188

7289
setColDefs(columns.concat(addColumnColDef));
@@ -78,8 +95,17 @@ export const DatabaseGrid = ({
7895
filter: true,
7996
editable: true,
8097
unSortIcon: true,
98+
spanRows: true,
8199
};
82100

101+
const theme = useMemo(() => {
102+
return themeQuartz.withParams({
103+
pinnedRowBorder: {
104+
width: 2,
105+
},
106+
});
107+
}, []);
108+
83109
const addColumn = (columnName: string) => {
84110
const newColDef: ColDef = {
85111
field: columnName,
@@ -115,6 +141,7 @@ export const DatabaseGrid = ({
115141
defaultColDef={defaultColDef}
116142
domLayout="autoHeight"
117143
enableCellSpan={true}
144+
theme={theme}
118145
/>
119146
</Box>
120147
);

0 commit comments

Comments
 (0)