diff --git a/ROADMAP.md b/ROADMAP.md index 5b3b556b..fb07c57e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -37,19 +37,19 @@ ### Functionality: -- Hide/Show columns -- Delete columns -- Edit columns -- Delete tables -- Edit tables -- Hide tables +- Delete columns✅ +- Edit columns✅ - Fixed column +- Hide/Show columns - resizable column ✅ - keyboard Navigation: - Up key to move to the cell above ✅ - Down key to move to the cell bellow, if last cell create a new row ✅ - Tab to go to the next cell ✅ - column / table Create/edit validation +- Delete tables +- Edit tables +- Hide tables ## V1 diff --git a/src/components/Fields/UrlLink.tsx b/src/components/Fields/UrlLink.tsx index 37a519fe..95f3cbe0 100644 --- a/src/components/Fields/UrlLink.tsx +++ b/src/components/Fields/UrlLink.tsx @@ -11,7 +11,7 @@ const UrlLink = (props: Props) => { return value ? ( <> - + {value} diff --git a/src/components/Table/HeaderPopper.tsx b/src/components/Table/HeaderPopper.tsx index 4b6b3f24..adf57a94 100644 --- a/src/components/Table/HeaderPopper.tsx +++ b/src/components/Table/HeaderPopper.tsx @@ -23,6 +23,7 @@ import VisibilityOffIcon from "@material-ui/icons/VisibilityOff"; import FormatItalicIcon from "@material-ui/icons/FormatItalic"; import FormatUnderlinedIcon from "@material-ui/icons/FormatUnderlined"; import FormatColorFillIcon from "@material-ui/icons/FormatColorFill"; +import DeleteIcon from "@material-ui/icons/Delete"; const useStyles = makeStyles(Theme => createStyles({ @@ -91,7 +92,7 @@ const HeaderPopper = (props: any) => { }; useEffect(() => { - if (column && !column.isNew) + if (column && !column.isNew) { setValues(oldValues => ({ ...oldValues, name: column.name, @@ -99,6 +100,7 @@ const HeaderPopper = (props: any) => { key: column.key, isNew: column.isNew, })); + } }, [column]); const onClickAway = (event: any) => { const dropDownClicked = isFieldType(event.target.dataset.value); @@ -118,6 +120,20 @@ const HeaderPopper = (props: any) => { actions.add(name, type); handleClose(); }; + const deleteColumn = () => { + actions.remove(props.column.idx); + handleClose(); + }; + const updateColumn = () => { + console.log(values, props); + const updatables = [ + { field: "name", value: values.name }, + { field: "type", value: values.type }, + { field: "resizable", value: flags.includes("resizable") }, + ]; + actions.update(props.column.idx, updatables); + handleClose(); + }; if (column) { return ( @@ -139,24 +155,24 @@ const HeaderPopper = (props: any) => { onChange={handleToggle} arial-label="column settings" > - + {flags.includes("editable") ? ( ) : ( )} - + {flags.includes("visible") ? ( ) : ( )} - + - + @@ -174,9 +190,18 @@ const HeaderPopper = (props: any) => { Field Type {FieldsDropDown(values.type, handleChange)} - {column.isNew && ( + {column.isNew ? ( + ) : ( + )} + diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index a7d9f661..ac04a4c0 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -152,11 +152,11 @@ function Table(props: any) { if (tableState.columns) { let columns = tableState.columns.map((column: any) => ({ width: 220, - resizable: true, + key: column.fieldName, name: column.columnName, editable: editable(column.type), - resizeable: true, + resizable: true, headerRenderer: headerRenderer, formatter: formatter(column.type, column.fieldName), ...column, diff --git a/src/hooks/useFiretable/index.ts b/src/hooks/useFiretable/index.ts index 696178f3..7e0cdcb6 100644 --- a/src/hooks/useFiretable/index.ts +++ b/src/hooks/useFiretable/index.ts @@ -4,7 +4,13 @@ import useCell, { Cell } from "./useCell"; export type FiretableActions = { cell: { set: Function; update: Function }; - column: { add: Function; resize: Function; rename: Function }; + column: { + add: Function; + resize: Function; + rename: Function; + remove: Function; + update: Function; + }; row: { add: any; delete: Function }; table: { set: Function }; }; @@ -38,6 +44,8 @@ const useFiretable = (collectionName: string) => { add: configActions.add, resize: configActions.resize, rename: configActions.rename, + update: configActions.update, + remove: configActions.remove, }, row: { add: tableActions.addRow, delete: tableActions.deleteRow }, table: { set: setTable }, diff --git a/src/hooks/useFiretable/useTableConfig.ts b/src/hooks/useFiretable/useTableConfig.ts index 3bc35de1..22b5dbd4 100644 --- a/src/hooks/useFiretable/useTableConfig.ts +++ b/src/hooks/useFiretable/useTableConfig.ts @@ -2,6 +2,7 @@ import { useEffect } from "react"; import useDoc, { DocActions } from "../useDoc"; import { FieldType } from "../../components/Fields"; import _camelCase from "lodash/camelCase"; + const useTableConfig = (tablePath: string) => { const [tableConfigState, documentDispatch] = useDoc({ path: `${tablePath}/_FIRETABLE_`, @@ -29,12 +30,25 @@ const useTableConfig = (tablePath: string) => { columns[index].width = width; documentDispatch({ action: DocActions.update, data: { columns } }); }; - const rename = () => {}; + const update = (index: number, updatables: any) => { + const { columns } = tableConfigState; + updatables.forEach((updatable: any) => { + columns[index][updatable.field] = updatable.value; + }); + documentDispatch({ action: DocActions.update, data: { columns } }); + }; + + const remove = (index: number) => { + const { columns } = tableConfigState; + columns.splice(index, 1); + documentDispatch({ action: DocActions.update, data: { columns } }); + }; const actions = { + update, add, resize, - rename, setTable, + remove, }; return [tableConfigState, actions]; };