Skip to content

Commit 1c8458e

Browse files
anaisbergSimonClo
authored andcommitted
♻️ move table data inside grid component
1 parent de4941e commit 1c8458e

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
NEXT_PUBLIC_API_ORIGIN=http://localhost:8071
22
NEXT_PUBLIC_PUBLISH_AS_MIT=false
33
NEXT_PUBLIC_SW_DEACTIVATED=true
4+
NEXT_PUBLIC_GRIST_API_KEY=

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Box, Icon, Text } from '@/components';
99

1010
import { DocsBlockNoteEditor } from '../../types';
1111
import { DatabaseSourceSelector } from '../DatabaseSourceSelector';
12-
import { DatabaseTableDisplay } from '../DatabaseTableDisplay';
1312

1413
import { DatabaseGrid } from './DatabaseBlock/DatabaseGrid';
1514

@@ -42,14 +41,11 @@ export const DatabaseBlock = createReactBlockSpec(
4241
>
4342
<Box as="div" />
4443
{block.props.documentId && block.props.tableId ? (
45-
<Box>
46-
<DatabaseTableDisplay
44+
<Box style={{ height: '100%', width: '100%' }}>
45+
<DatabaseGrid
4746
documentId={block.props.documentId}
4847
tableId={block.props.tableId}
4948
/>
50-
<Box style={{ height: '100%', width: '100%' }}>
51-
<DatabaseGrid />
52-
</Box>
5349
</Box>
5450
) : (
5551
<Box

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@ import { AgGridReact } from 'ag-grid-react';
33
import { useRef, useState } from 'react';
44

55
import { Box } from '@/components';
6+
import { useGristTableData } from '@/features/grist';
67

78
import { AddButtonComponent } from './AddColumnButton';
89

9-
export const DatabaseGrid = () => {
10+
export const DatabaseGrid = ({
11+
documentId,
12+
tableId,
13+
}: {
14+
documentId: string;
15+
tableId: string;
16+
}) => {
1017
const gridRef = useRef(null);
1118

12-
const [rowData, setRowData] = useState([
19+
const { tableData } = useGristTableData({
20+
documentId,
21+
tableId,
22+
});
23+
24+
const rowData = [
1325
{ make: 'Tesla', model: 'Model Y', price: 64950, electric: true },
1426
{ make: 'Ford', model: 'F-Series', price: 33850, electric: false },
1527
{ make: 'Toyota', model: 'Corolla', price: 29600, electric: false },
16-
]);
28+
];
1729

1830
// Column Definitions: Defines the columns to be displayed.
1931
const [colDefs, setColDefs] = useState<ColDef[]>([

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const useGristTableData = ({
1111
documentId,
1212
tableId,
1313
}: UseGristTableDataArguments) => {
14-
const [tableData, setTableData] = useState<unknown[]>([]);
14+
const [tableData, setTableData] = useState<Record<string, unknown>>({});
1515

1616
useEffect(() => {
1717
const fetchData = async () => {
@@ -23,12 +23,12 @@ export const useGristTableData = ({
2323
await errorCauses(response),
2424
);
2525
}
26-
return (await response.json()) as Promise<unknown[]>;
26+
return (await response.json()) as Promise<unknown>;
2727
};
2828

2929
fetchData()
3030
.then((res) => {
31-
setTableData(res);
31+
setTableData(res as Record<string, unknown>);
3232
})
3333
.catch((error) => {
3434
console.error('Error fetching Grist table data:', error);

0 commit comments

Comments
 (0)