From 4729d229232a353dcd45bc861e09514ab8dd91e4 Mon Sep 17 00:00:00 2001 From: Sidney Alcantara Date: Thu, 22 Oct 2020 14:17:53 +1100 Subject: [PATCH] restyle NewColumn dialog --- .../components/Table/ColumnMenu/NewColumn.tsx | 234 ++++++++++-------- .../components/Table/FinalColumnHeader.tsx | 8 +- 2 files changed, 136 insertions(+), 106 deletions(-) diff --git a/www/src/components/Table/ColumnMenu/NewColumn.tsx b/www/src/components/Table/ColumnMenu/NewColumn.tsx index d998d3df..5a3af4a6 100644 --- a/www/src/components/Table/ColumnMenu/NewColumn.tsx +++ b/www/src/components/Table/ColumnMenu/NewColumn.tsx @@ -2,124 +2,160 @@ import React, { useState, useEffect } from "react"; import _camel from "lodash/camelCase"; import { + makeStyles, + createStyles, + Dialog, + DialogTitle, + IconButton, + DialogContent, + Grid, Button, TextField, - Dialog, - Grid, DialogActions, - DialogContent, - Typography, - IconButton, } from "@material-ui/core"; import CloseIcon from "@material-ui/icons/Close"; import { FieldType } from "constants/fields"; import FieldsDropdown from "./FieldsDropdown"; +import { MONO_FONT } from "Theme"; + +const useStyles = makeStyles((theme) => + createStyles({ + root: { userSelect: "none" }, + + closeButton: { + position: "absolute", + top: theme.spacing(0.5), + right: theme.spacing(0.5), + }, + + content: { paddingBottom: theme.spacing(1.5) }, + + helperText: { + ...theme.typography.body2, + marginTop: theme.spacing(1), + }, + + fieldKey: { fontFamily: MONO_FONT }, + }) +); + +export interface IFormDialogProps { + open: boolean; + data: any; + handleClose: () => void; + handleSave: (fieldKey: string, data: any) => void; +} export default function FormDialog({ open, data, handleClose, handleSave, -}: { - open: boolean; - data: any; - handleClose: Function; - handleSave: Function; -}) { - const [type, setType] = useState(FieldType.shortText); +}: IFormDialogProps) { + const classes = useStyles(); + const [columnLabel, setColumnLabel] = useState(""); const [fieldKey, setFieldKey] = useState(""); + const [type, setType] = useState(FieldType.shortText); + useEffect(() => { - setFieldKey(_camel(columnLabel)); + if (type !== FieldType.id) setFieldKey(_camel(columnLabel)); }, [columnLabel]); - return ( -
- { - handleClose(); - }} - aria-labelledby="new-column" - > - - - Add new column - { - handleClose(); - }} - > - - - - Column Name - { - setColumnLabel(e.target.value); - }} - /> - Field Key - { - setFieldKey(e.target.value); - }} - /> - Column Type + useEffect(() => { + if (type === FieldType.id) setFieldKey("id"); + }, [type]); - { - setType(newType.target.value as FieldType); - }} - /> - - - - - - -
+ return ( + + Add New Column + + + + + + + + + setColumnLabel(e.target.value)} + helperText="Set the user-facing name for this column." + FormHelperTextProps={{ classes: { root: classes.helperText } }} + /> + + + + setFieldKey(e.target.value)} + disabled={type === FieldType.id && fieldKey === "id"} + helperText={ + <> + Set the Firestore field key to link to this column. +
+ It will display any existing data for this field key. + + } + FormHelperTextProps={{ classes: { root: classes.helperText } }} + /> +
+ + + setType(newType.target.value as FieldType)} + /> + +
+
+ + + + + +
); } diff --git a/www/src/components/Table/FinalColumnHeader.tsx b/www/src/components/Table/FinalColumnHeader.tsx index b334253e..1b0d0db1 100644 --- a/www/src/components/Table/FinalColumnHeader.tsx +++ b/www/src/components/Table/FinalColumnHeader.tsx @@ -1,13 +1,7 @@ import React from "react"; import { Column } from "react-data-grid"; -import { - makeStyles, - createStyles, - Tooltip, - Grid, - Button, -} from "@material-ui/core"; +import { makeStyles, createStyles, Grid, Button } from "@material-ui/core"; import AddColumnIcon from "assets/icons/AddColumn"; import { useFiretableContext } from "contexts/firetableContext";