Skip to content

Commit 7e31e6c

Browse files
anaisbergSimonClo
authored andcommitted
🏷️ type row
1 parent ebac06e commit 7e31e6c

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111

1212
import { AddButtonComponent } from './AddColumnButton';
1313
import { useColumns, useRows } from './hooks';
14+
import { DatabaseRow } from './types';
1415
import { addRowCellRenderer, autoSizeStrategy, createNewRow } from './utils';
1516

1617
export const DatabaseGrid = ({
@@ -61,12 +62,12 @@ export const DatabaseGrid = ({
6162
([key]) => key !== 'id' && key !== 'manualSort',
6263
);
6364

64-
const rowData1: Record<string, string | number | boolean>[] = [];
65+
const rowData1: DatabaseRow[] = [];
6566

6667
const numRows = filteredEntries[0]?.[1].length;
6768

6869
for (let i = 0; i < numRows; i++) {
69-
const row: Record<string, string | boolean | number> = {};
70+
const row: DatabaseRow = {};
7071
for (const [key, values] of filteredEntries) {
7172
row[key] = values[i] ?? '';
7273
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { ColDef } from 'ag-grid-community';
22
import { useState } from 'react';
33

4+
import { DatabaseRow } from './types';
5+
46
export const useColumns = () => {
57
const [colDefs, setColDefs] = useState<ColDef[]>();
68

79
return { colDefs, setColDefs };
810
};
911

1012
export const useRows = () => {
11-
const [rowData, setRowData] =
12-
useState<Record<string, string | number | boolean>[]>();
13+
const [rowData, setRowData] = useState<DatabaseRow[]>();
1314

1415
return { rowData, setRowData };
1516
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type DatabaseRow = Record<string, string | number | boolean>;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import { Dispatch, SetStateAction } from 'react';
66

77
import { AddRowButton } from './AddRowButton';
8+
import { DatabaseRow } from './types';
89

910
export const autoSizeStrategy: SizeColumnsToContentStrategy = {
1011
type: 'fitCellContents',
@@ -28,9 +29,7 @@ export const createNewRow = (
2829
export const addRowCellRenderer = (
2930
params: ICellRendererParams<Record<string, string>>,
3031
columns: string[] | undefined,
31-
setRowData: Dispatch<
32-
SetStateAction<Record<string, string | number | boolean>[] | undefined>
33-
>,
32+
setRowData: Dispatch<SetStateAction<DatabaseRow[] | undefined>>,
3433
) => {
3534
if (params.data) {
3635
const addRowButton = {

0 commit comments

Comments
 (0)