Skip to content

Commit 3330cdc

Browse files
anaisbergSimonClo
authored andcommitted
✨ click on add row without editing cell
1 parent 3097c3b commit 3330cdc

File tree

1 file changed

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

1 file changed

+22
-3
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import { Button } from '@openfun/cunningham-react';
2-
import { CustomCellRendererProps } from 'ag-grid-react';
32

4-
export const AddRowButton = (props: CustomCellRendererProps) => {
5-
console.log('AddRowButton props', props);
3+
import { useColumns, useRows } from './hooks';
4+
import { createNewRow } from './utils';
5+
6+
export const AddRowButton = () => {
7+
const { setRowData } = useRows();
8+
const { colDefs } = useColumns();
9+
10+
const addRow = () => {
11+
const newRow = createNewRow('', colDefs);
12+
setRowData((prev) => {
13+
if (prev === undefined) {
14+
return [newRow];
15+
}
16+
return [...prev, newRow];
17+
});
18+
};
19+
620
const color = '#817E77';
721
return (
822
<Button
@@ -20,6 +34,11 @@ export const AddRowButton = (props: CustomCellRendererProps) => {
2034
padding: 0,
2135
width: '100%',
2236
}}
37+
onClick={(event) => {
38+
event.preventDefault();
39+
event.stopPropagation();
40+
addRow();
41+
}}
2342
>
2443
new row
2544
</Button>

0 commit comments

Comments
 (0)