From e990cc27f2b62a49462219f390d20565647262da Mon Sep 17 00:00:00 2001 From: shams mosowi Date: Thu, 3 Oct 2019 17:21:44 +1000 Subject: [PATCH] feature: row height control --- src/components/Table/index.tsx | 38 ++++++++++++++++++++++-- src/hooks/useFiretable/index.ts | 18 +++++++---- src/hooks/useFiretable/useTableConfig.ts | 13 ++++++-- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index f686fe71..d181cf62 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -31,6 +31,10 @@ import useWindowSize from "../../hooks/useWindowSize"; import { DraggableHeader } from "react-data-grid-addons"; import Confirmation from "components/Confirmation"; import DeleteIcon from "@material-ui/icons/Delete"; +import FormControl from "@material-ui/core/FormControl"; +import InputLabel from "@material-ui/core/InputLabel"; +import Select from "@material-ui/core/Select"; +import MenuItem from "@material-ui/core/MenuItem"; const { DraggableContainer } = DraggableHeader; const deleteAlgoliaRecord = functions.httpsCallable( CLOUD_FUNCTIONS.deleteAlgoliaRecord @@ -70,6 +74,10 @@ const useStyles = makeStyles(Theme => { alignContent: "center", // background: Theme.palette.primary.main, }, + formControl: { + margin: 2, + minWidth: 120, + }, }); }); @@ -90,7 +98,7 @@ function Table(props: Props) { const size = useWindowSize(); useEffect(() => { - tableActions.set(collection, filters); + tableActions.table.set(collection, filters); }, [collection, filters]); const classes = useStyles(); @@ -215,13 +223,37 @@ function Table(props: Props) { ), }); - const rowHeight = 40; + const rowHeight = tableState.config.rowHeight; const rows = tableState.rows.map((row: any) => ({ rowHeight, ...row })); return ( <>
- {collection} +
+ {collection} + + Row Height + + +
{ const state: FiretableState = { columns: tableConfig.columns, + config: { rowHeight: tableConfig.rowHeight }, rows: tableState.rows, }; const actions: FiretableActions = { @@ -46,7 +51,7 @@ const useFiretable = (collectionName: string) => { add: configActions.add, resize: configActions.resize, rename: configActions.rename, - update: configActions.update, + update: configActions.updateColumn, remove: configActions.remove, reorder: configActions.reorder, }, @@ -54,8 +59,11 @@ const useFiretable = (collectionName: string) => { add: tableActions.addRow, delete: tableActions.deleteRow, }, - set: setTable, - filter: filterTable, + table: { + updateConfig: configActions.updateConfig, + set: setTable, + filter: filterTable, + }, }; return { tableState: state, tableActions: actions }; diff --git a/src/hooks/useFiretable/useTableConfig.ts b/src/hooks/useFiretable/useTableConfig.ts index 738f5db8..4ab6286d 100644 --- a/src/hooks/useFiretable/useTableConfig.ts +++ b/src/hooks/useFiretable/useTableConfig.ts @@ -12,7 +12,7 @@ const useTableConfig = (tablePath: string) => { useEffect(() => { const { doc, columns } = tableConfigState; if (doc && columns !== doc.columns) { - documentDispatch({ columns: doc.columns }); + documentDispatch({ columns: doc.columns, rowHeight: doc.rowHeight }); } }, [tableConfigState.doc]); @@ -33,7 +33,7 @@ const useTableConfig = (tablePath: string) => { columns[index].width = width; documentDispatch({ action: DocActions.update, data: { columns } }); }; - const update = (index: number, updatables: any) => { + const updateColumn = (index: number, updatables: any) => { const { columns } = tableConfigState; updatables.forEach((updatable: any) => { columns[index][updatable.field] = updatable.value; @@ -57,8 +57,15 @@ const useTableConfig = (tablePath: string) => { data: { columns: reorderedColumns }, }); }; + const updateConfig = (key: string, value: any) => { + documentDispatch({ + action: DocActions.update, + data: { [key]: value }, + }); + }; const actions = { - update, + updateColumn, + updateConfig, add, resize, setTable,