Skip to content

Commit 26a9391

Browse files
anaisbergSimonClo
authored andcommitted
🐛 add column button outside table
1 parent 5e686cb commit 26a9391

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

src/frontend/apps/impress/src/components/DropButton.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CSSProperties,
23
PropsWithChildren,
34
ReactNode,
45
useEffect,
@@ -38,6 +39,7 @@ const StyledButton = styled(Button)<StyledButtonProps>`
3839
export interface DropButtonProps {
3940
button: ReactNode;
4041
buttonCss?: BoxProps['$css'];
42+
buttonStyle?: CSSProperties;
4143
isOpen?: boolean;
4244
onOpenChange?: (isOpen: boolean) => void;
4345
label?: string;
@@ -46,6 +48,7 @@ export interface DropButtonProps {
4648
export const DropButton = ({
4749
button,
4850
buttonCss,
51+
buttonStyle,
4952
isOpen = false,
5053
onOpenChange,
5154
children,
@@ -77,6 +80,7 @@ export const DropButton = ({
7780
${buttonCss};
7881
`}
7982
className="--docs--drop-button"
83+
style={buttonStyle}
8084
>
8185
{button}
8286
</StyledButton>

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ export const DatabaseBlock = createReactBlockSpec(
3737
}}
3838
>
3939
{block.props.documentId && block.props.tableId ? (
40-
<Box style={{ height: '100%', width: '100%' }}>
40+
<Box
41+
style={{
42+
height: '100%',
43+
width: '100%',
44+
flexDirection: 'row',
45+
}}
46+
>
4147
<DatabaseGrid
4248
documentId={block.props.documentId}
4349
tableId={block.props.tableId}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ export const AddButtonComponent = ({
1919
isOpen={isOpen}
2020
onOpenChange={onOpenChange}
2121
label="add column"
22+
buttonStyle={{ marginBottom: 'auto' }}
2223
button={
23-
<Box style={{ padding: '0.25rem', gap: '16px' }} color="tertiary">
24+
<Box
25+
style={{
26+
padding: '0.25rem',
27+
gap: '16px',
28+
display: 'flex',
29+
marginTop: '8px',
30+
}}
31+
color="tertiary"
32+
>
2433
<span className="material-icons">add</span>
2534
</Box>
2635
}

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

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

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

1717
export const DatabaseGrid = ({
1818
documentId,
@@ -21,8 +21,6 @@ export const DatabaseGrid = ({
2121
documentId: string;
2222
tableId: string;
2323
}) => {
24-
const gridRef = useRef(null);
25-
2624
const { tableData } = useGristTableData({
2725
documentId,
2826
tableId,
@@ -43,20 +41,6 @@ export const DatabaseGrid = ({
4341
return 1;
4442
};
4543

46-
const addColumnColDef: ColDef = {
47-
headerComponentParams: {
48-
innerHeaderComponent: () =>
49-
AddButtonComponent({
50-
addColumn,
51-
}),
52-
},
53-
unSortIcon: false,
54-
editable: false,
55-
sortable: false,
56-
spanRows: true,
57-
filter: false,
58-
};
59-
6044
useEffect(() => {
6145
const filteredEntries = Object.entries(tableData).filter(
6246
([key]) => key !== 'id' && key !== 'manualSort',
@@ -86,7 +70,8 @@ export const DatabaseGrid = ({
8670
) => addRowCellRenderer(params, columnNames, setRowData),
8771
}));
8872

89-
setColDefs(columns.concat(addColumnColDef));
73+
setColDefs(columns);
74+
9075
// eslint-disable-next-line react-hooks/exhaustive-deps
9176
}, [tableData]);
9277

@@ -96,14 +81,13 @@ export const DatabaseGrid = ({
9681
.filter((col) => col !== undefined);
9782
const addNewRow = createNewRow({ value: '+ new row', columnNames });
9883
setRowData((prev) => [...(prev ? prev : []), addNewRow]);
99-
}, [colDefs, gridRef, setRowData]);
84+
}, [colDefs, setRowData]);
10085

10186
const defaultColDef = {
10287
flex: 1,
10388
filter: true,
10489
editable: true,
10590
unSortIcon: true,
106-
suppressSizeToFit: true,
10791
minWidth: 200,
10892
};
10993

@@ -134,16 +118,17 @@ export const DatabaseGrid = ({
134118
};
135119

136120
return (
137-
<Box style={{ height: '100%', width: '100%' }}>
138-
<AgGridReact
139-
ref={gridRef}
140-
rowData={rowData}
141-
columnDefs={colDefs}
142-
defaultColDef={defaultColDef}
143-
domLayout="autoHeight"
144-
enableCellSpan={true}
145-
autoSizeStrategy={autoSizeStrategy}
146-
/>
147-
</Box>
121+
<>
122+
<Box style={{ height: '100%', width: '100%' }}>
123+
<AgGridReact
124+
rowData={rowData}
125+
columnDefs={colDefs}
126+
defaultColDef={defaultColDef}
127+
domLayout="autoHeight"
128+
enableCellSpan={true}
129+
/>
130+
</Box>
131+
<AddButtonComponent addColumn={addColumn} />
132+
</>
148133
);
149134
};

0 commit comments

Comments
 (0)