Skip to content

Commit c46d36c

Browse files
ClemsazertSimonClo
authored andcommitted
✨ create column propagation in grist
1 parent 85cc506 commit c46d36c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { AgGridReact } from 'ag-grid-react';
33
import { useEffect, useRef, useState } from 'react';
44

55
import { Box } from '@/components';
6-
import { useGristTableData } from '@/features/grist';
6+
import {
7+
ColumnType,
8+
useGristCrudColumns,
9+
useGristTableData,
10+
} from '@/features/grist';
711

812
import { AddButtonComponent } from './AddColumnButton';
913

@@ -21,6 +25,8 @@ export const DatabaseGrid = ({
2125
tableId,
2226
});
2327

28+
const { createColumns } = useGristCrudColumns();
29+
2430
const [rowData, setRowData] =
2531
useState<Record<string, string | number | boolean>[]>();
2632
const [colDefs, setColDefs] = useState<ColDef[]>();
@@ -88,6 +94,16 @@ export const DatabaseGrid = ({
8894
...(addColumn !== undefined ? [addColumn] : []),
8995
];
9096
});
97+
98+
void createColumns(documentId, tableId, [
99+
{
100+
id: columnName,
101+
fields: {
102+
label: columnName,
103+
type: ColumnType.TEXT,
104+
},
105+
},
106+
]);
91107
};
92108

93109
return (

src/frontend/apps/impress/src/features/grist/useGristCrudColumns.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { gristFetchApi } from '@/api';
22

3+
export enum ColumnType {
4+
TEXT = 'Text',
5+
NUMBER = 'Numeric',
6+
BOOLEAN = 'Bool',
7+
}
8+
9+
type ColumnInput = {
10+
type: ColumnType;
11+
label: string;
12+
};
13+
314
export const useGristCrudColumns = () => {
415
const createColumns = async (
516
documentId: string,
617
tableId: string,
7-
columns: { id: string; fields: unknown }[],
18+
columns: { id: string; fields: ColumnInput }[],
819
) => {
920
const url = `docs/${documentId}/tables/${tableId}/columns`;
1021
try {
@@ -13,7 +24,7 @@ export const useGristCrudColumns = () => {
1324
headers: {
1425
'Content-Type': 'application/json',
1526
},
16-
body: JSON.stringify(columns),
27+
body: JSON.stringify({ columns }),
1728
});
1829

1930
if (!response.ok) {

0 commit comments

Comments
 (0)