diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/Grid/Grid.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/Grid/Grid.tsx index e8d2216b32..0527532bb6 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/Grid/Grid.tsx +++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/Grid/Grid.tsx @@ -1,3 +1,6 @@ +import { ViewLayoutTypePB } from '@/services/backend'; + +import { useDatabase } from '../../_shared/database-hooks/useDatabase'; import { GridTableCount } from '../GridTableCount/GridTableCount'; import { GridTableHeader } from '../GridTableHeader/GridTableHeader'; import { GridAddRow } from '../GridTableRows/GridAddRow'; @@ -6,24 +9,29 @@ import { GridTitle } from '../GridTitle/GridTitle'; import { GridToolbar } from '../GridToolbar/GridToolbar'; export const Grid = ({ viewId }: { viewId: string }) => { + const { controller, rows, groups } = useDatabase(viewId, ViewLayoutTypePB.Grid); + return ( -
-
- - + controller && + groups && ( +
+
+ + +
+ + {/* table component view with text area for td */} +
+ + + +
+ + +
+ +
- - {/* table component view with text area for td */} -
- - - -
- - -
- - -
+ ) ); }; diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.hooks.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.hooks.tsx index d05ddaf5f3..a2db70852d 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.hooks.tsx +++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.hooks.tsx @@ -5,7 +5,7 @@ import { useAppDispatch, useAppSelector } from '../../../stores/store'; export const useGridTableHeaderHooks = function () { const dispatch = useAppDispatch(); - const grid = useAppSelector((state) => state.grid); + const database = useAppSelector((state) => state.database); const onAddField = () => { dispatch( @@ -21,7 +21,13 @@ export const useGridTableHeaderHooks = function () { }; return { - fields: grid.fields, + fields: Object.values(database.fields).map((field) => { + return { + fieldId: field.fieldId, + name: field.title, + fieldType: field.fieldType, + }; + }), onAddField, }; }; diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.tsx index 27c0b72a96..66e3791731 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.tsx +++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeader.tsx @@ -27,6 +27,7 @@ export const GridTableHeader = () => { {field.fieldType === FieldType.SingleSelect && } {field.fieldType === FieldType.MultiSelect && } {field.fieldType === FieldType.Checklist && } + {field.fieldType === FieldType.Checkbox && } {field.fieldType === FieldType.URL && } {field.name} diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridAddRow.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridAddRow.hooks.ts index 685e36bee9..517e2964a2 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridAddRow.hooks.ts +++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridAddRow.hooks.ts @@ -1,11 +1,7 @@ -import { gridActions } from '../../../stores/reducers/grid/slice'; -import { useAppDispatch } from '../../../stores/store'; - export const useGridAddRow = () => { - const dispatch = useAppDispatch(); - function addRow() { - dispatch(gridActions.addRow()); + // create a new row + console.log('create a new row'); } return { diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableCell.tsx new file mode 100644 index 0000000000..3319349d7f --- /dev/null +++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableCell.tsx @@ -0,0 +1,25 @@ +import { CellIdentifier } from '@/appflowy_app/stores/effects/database/cell/cell_bd_svc'; +import { CellCache } from '@/appflowy_app/stores/effects/database/cell/cell_cache'; +import { FieldController } from '@/appflowy_app/stores/effects/database/field/field_controller'; +import { BoardCell } from '../../board/BoardCell'; +import { useCell } from '../../_shared/database-hooks/useCell'; + +export const GridTableCell = ({ + cellIdentifier, + cellCache, + fieldController, +}: { + cellIdentifier: CellIdentifier; + cellCache: CellCache; + fieldController: FieldController; +}) => { + const { data } = useCell(cellIdentifier, cellCache, fieldController); + + console.log({ data }); + + return ( +
+ +
+ ); +}; diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableItem.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableItem.hooks.ts deleted file mode 100644 index e36cd3f952..0000000000 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableItem.hooks.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { useState } from 'react'; -import { gridActions } from '../../../stores/reducers/grid/slice'; -import { useAppDispatch, useAppSelector } from '../../../stores/store'; - -export const useGridTableItemHooks = ( - rowItem: { value: string | number; fieldId: string; cellId: string }, - rowId: string -) => { - const dispatch = useAppDispatch(); - const [value, setValue] = useState(rowItem.value); - - function onValueChange(event: React.ChangeEvent) { - setValue(event.target.value); - } - - function onValueBlur() { - dispatch(gridActions.updateRowValue({ rowId: rowId, cellId: rowItem.cellId, value })); - } - - const grid = useAppSelector((state) => state.grid); - - return { - rows: grid.rows, - onValueChange, - value, - onValueBlur, - }; -}; diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableItem.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableItem.tsx deleted file mode 100644 index 99c3fe7856..0000000000 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableItem.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { useGridTableItemHooks } from './GridTableItem.hooks'; - -export const GridTableItem = ({ - rowItem, - rowId, -}: { - rowItem: { - fieldId: string; - value: string | number; - cellId: string; - }; - rowId: string; -}) => { - const { value, onValueChange, onValueBlur } = useGridTableItemHooks(rowItem, rowId); - return ( -
- -
- ); -}; diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRow.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRow.tsx new file mode 100644 index 0000000000..b46c236ddb --- /dev/null +++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRow.tsx @@ -0,0 +1,33 @@ +import { DatabaseController } from '@/appflowy_app/stores/effects/database/database_controller'; +import { RowInfo } from '@/appflowy_app/stores/effects/database/row/row_cache'; +import { useRow } from '../../_shared/database-hooks/useRow'; +import { GridTableCell } from './GridTableCell'; + +export const GridTableRow = ({ + viewId, + controller, + row, +}: { + viewId: string; + controller: DatabaseController; + row: RowInfo; +}) => { + const { cells } = useRow(viewId, controller, row); + + return ( + + {cells.map((cell, cellIndex) => { + return ( + + + + ); + })} + + ); +}; diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRows.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRows.hooks.ts deleted file mode 100644 index b534c5a4d3..0000000000 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRows.hooks.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { useAppSelector } from '../../../stores/store'; - -export const useGridTableRowsHooks = () => { - const grid = useAppSelector((state) => state.grid); - - return { - rows: grid.rows, - }; -}; diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRows.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRows.tsx index 361a77063e..d6f85eebe1 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRows.tsx +++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableRows/GridTableRows.tsx @@ -1,24 +1,19 @@ -import { GridTableItem } from './GridTableItem'; -import { useGridTableRowsHooks } from './GridTableRows.hooks'; - -export const GridTableRows = () => { - const { rows } = useGridTableRowsHooks(); +import { DatabaseController } from '@/appflowy_app/stores/effects/database/database_controller'; +import { RowInfo } from '@/appflowy_app/stores/effects/database/row/row_cache'; +import { GridTableRow } from './GridTableRow'; +export const GridTableRows = ({ + viewId, + controller, + allRows, +}: { + viewId: string; + controller: DatabaseController; + allRows: readonly RowInfo[]; +}) => { return ( - {rows.map((row, i) => { - return ( - - {row.values.map((value) => { - return ( - - - - ); - })} - - - - ); + {allRows.map((row, i) => { + return ; })} );