From c44859154608c8fce68f0b50459bca879dcffcfb Mon Sep 17 00:00:00 2001 From: Sidney Alcantara Date: Mon, 6 Jun 2022 12:21:38 +1000 Subject: [PATCH] enable all fields in side drawer --- package.json | 6 +- src/atoms/tableScope/rowActions.ts | 22 +- src/components/CodeEditor/CodeEditor.tsx | 19 +- .../CodeEditor/useMonacoCustomizations.ts | 2 +- src/components/ErrorFallback.tsx | 13 +- src/components/RichTextEditor.tsx | 138 ++++++------ src/components/SideDrawer/FieldWrapper.tsx | 52 ++++- src/components/SideDrawer/MemoizedField.tsx | 107 +++++++++ src/components/SideDrawer/SaveState.tsx | 74 ++++++ src/components/SideDrawer/SideDrawer.tsx | 29 ++- .../SideDrawer/SideDrawerFields.tsx | 114 ++++++---- src/components/SideDrawer/StyledDrawer.ts | 7 + src/components/SideDrawer/utils.ts | 23 +- src/components/Table/TableContainer.tsx | 8 +- .../Table/editors/withSideDrawerEditor.tsx | 13 +- .../Table/formatters/FinalColumn.tsx | 2 +- src/components/TableSettingsDialog/form.tsx | 34 ++- src/components/TableToolbar/HiddenFields.tsx | 6 + .../fields/Action/SideDrawerField.tsx | 119 +++++----- .../fields/Checkbox/SideDrawerField.tsx | 78 +++---- .../fields/Code/SideDrawerField.tsx | 47 ++-- src/components/fields/Color/PopoverCell.tsx | 26 ++- .../fields/Color/SideDrawerField.tsx | 144 ++++++------ .../fields/ConnectService/SideDrawerField.tsx | 101 ++++----- .../fields/ConnectTable/SideDrawerField.tsx | 134 ++++++----- .../fields/Connector/SideDrawerField.tsx | 110 +++++---- .../fields/CreatedAt/SideDrawerField.tsx | 15 +- src/components/fields/CreatedAt/TableCell.tsx | 11 +- .../fields/CreatedBy/SideDrawerField.tsx | 12 +- src/components/fields/CreatedBy/TableCell.tsx | 7 +- .../fields/Date/SideDrawerField.tsx | 102 ++++----- src/components/fields/Date/utils.ts | 2 +- .../fields/DateTime/SideDrawerField.tsx | 104 ++++----- src/components/fields/DateTime/TableCell.tsx | 2 +- .../fields/Duration/SideDrawerField.tsx | 136 +++++++++-- src/components/fields/Duration/index.tsx | 4 +- .../fields/Email/SideDrawerField.tsx | 42 ++-- .../fields/File/SideDrawerField.tsx | 61 ++--- src/components/fields/Id/SideDrawerField.tsx | 4 +- .../fields/Image/SideDrawerField.tsx | 65 ++---- .../fields/Json/SideDrawerField.tsx | 213 ++++++++++-------- .../fields/LongText/SideDrawerField.tsx | 42 ++-- .../fields/MultiSelect/PopoverCell.tsx | 4 +- .../fields/MultiSelect/SideDrawerField.tsx | 95 ++++---- .../fields/Number/SideDrawerField.tsx | 36 ++- .../fields/Percentage/SideDrawerField.tsx | 79 ++++--- .../fields/Phone/SideDrawerField.tsx | 44 ++-- src/components/fields/Rating/Settings.tsx | 4 +- .../fields/Rating/SideDrawerField.tsx | 56 ++--- src/components/fields/Reference/BasicCell.tsx | 40 +++- .../fields/Reference/EditorCell.tsx | 13 +- .../fields/Reference/SideDrawerField.tsx | 57 ++++- .../fields/RichText/SideDrawerField.tsx | 23 +- .../fields/ShortText/SideDrawerField.tsx | 38 ++-- .../fields/SingleSelect/SideDrawerField.tsx | 41 ++-- .../fields/Slider/SideDrawerField.tsx | 93 ++++---- .../fields/Status/SideDrawerField.tsx | 43 ++-- .../fields/SubTable/SideDrawerField.tsx | 32 ++- .../fields/UpdatedAt/SideDrawerField.tsx | 15 +- src/components/fields/UpdatedAt/TableCell.tsx | 11 +- .../fields/UpdatedBy/SideDrawerField.tsx | 11 +- src/components/fields/UpdatedBy/TableCell.tsx | 7 +- src/components/fields/Url/SideDrawerField.tsx | 76 +++---- src/components/fields/Url/TableCell.tsx | 1 + .../fields/User/SideDrawerField.tsx | 87 ++++--- .../BasicCellContextMenuActions.tsx | 2 +- src/components/fields/types.ts | 24 +- src/hooks/useFirebaseStorageUploader.tsx | 2 +- src/index.tsx | 10 +- src/theme/components.tsx | 4 + yarn.lock | 109 +++++---- 71 files changed, 1851 insertions(+), 1456 deletions(-) create mode 100644 src/components/SideDrawer/MemoizedField.tsx create mode 100644 src/components/SideDrawer/SaveState.tsx diff --git a/package.json b/package.json index 1d8b64c0..a422b64a 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "@emotion/styled": "^11.8.1", "@mdi/js": "^6.6.96", "@monaco-editor/react": "^4.4.4", - "@mui/icons-material": "^5.6.0", + "@mui/icons-material": "^5.8.2", "@mui/lab": "^5.0.0-alpha.76", - "@mui/material": "^5.6.0", - "@mui/styles": "^5.6.2", + "@mui/material": "^5.8.2", + "@mui/styles": "^5.8.0", "@mui/x-date-pickers": "^5.0.0-alpha.4", "@rowy/form-builder": "^0.6.1", "@rowy/multiselect": "^0.4.0", diff --git a/src/atoms/tableScope/rowActions.ts b/src/atoms/tableScope/rowActions.ts index 3cb88605..9d197b17 100644 --- a/src/atoms/tableScope/rowActions.ts +++ b/src/atoms/tableScope/rowActions.ts @@ -1,5 +1,12 @@ import { atom } from "jotai"; -import { cloneDeep, find, set as _set, unset } from "lodash-es"; +import { + cloneDeep, + find, + get as _get, + set as _set, + isEqual, + unset, +} from "lodash-es"; import { currentUserAtom } from "@src/atoms/globalScope"; import { @@ -211,6 +218,8 @@ export interface IUpdateFieldOptions { deleteField?: boolean; /** If true, ignores checking required fields have values */ ignoreRequiredFields?: boolean; + /** Optionally, disable checking if the updated value is equal to the current value. By default, we skip the update if they’re equal. */ + disableCheckEquality?: boolean; } /** * Updates or deletes a field in a row. @@ -235,6 +244,7 @@ export const updateFieldAtom = atom( value, deleteField, ignoreRequiredFields, + disableCheckEquality, }: IUpdateFieldOptions ) => { const updateRowDb = get(_updateRowDbAtom); @@ -271,7 +281,15 @@ export const updateFieldAtom = atom( : requiredFields.filter((field) => row[field] === undefined); // Apply field update - if (!deleteField) _set(update, fieldName, value); + if (!deleteField) { + // Check for equality. If updated value is same as current, skip update + if (!disableCheckEquality) { + const currentValue = _get(row, fieldName); + if (isEqual(currentValue, value)) return; + } + // Otherwise, apply the update + _set(update, fieldName, value); + } // Update rowsLocal if any required fields are missing if (missingRequiredFields.length > 0) { diff --git a/src/components/CodeEditor/CodeEditor.tsx b/src/components/CodeEditor/CodeEditor.tsx index 2914bef5..39e05c57 100644 --- a/src/components/CodeEditor/CodeEditor.tsx +++ b/src/components/CodeEditor/CodeEditor.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import Editor, { EditorProps } from "@monaco-editor/react"; import type { editor } from "monaco-editor/esm/vs/editor/editor.api"; -import { useTheme, Box, BoxProps } from "@mui/material"; +import { useTheme, Box, BoxProps, AppBar, Toolbar } from "@mui/material"; import TrapFocus from "@mui/material/Unstable_TrapFocus"; import CircularProgressOptical from "@src/components/CircularProgressOptical"; import { ResizeBottomRight } from "@src/assets/icons"; @@ -17,12 +17,15 @@ export interface ICodeEditorProps Omit { value: string; containerProps?: Partial; + fullScreenTitle?: React.ReactNode; onValidate?: EditorProps["onValidate"]; onValidStatusUpdate?: (result: { isValid: boolean; markers: editor.IMarker[]; }) => void; + onFocus?: () => void; + onBlur?: () => void; } export default function CodeEditor({ @@ -31,9 +34,12 @@ export default function CodeEditor({ disabled, error, containerProps, + fullScreenTitle, onValidate, onValidStatusUpdate, + onFocus, + onBlur, extraLibs, diagnosticsOptions, @@ -76,11 +82,22 @@ export default function CodeEditor({ ]} style={fullScreen ? { height: "100%" } : {}} > + {fullScreen && fullScreenTitle && ( + + + {fullScreenTitle} + + + )} } className="editor" + onMount={(editor) => { + if (onFocus) editor.onDidFocusEditorWidget(onFocus); + if (onBlur) editor.onDidBlurEditorWidget(onBlur); + }} {...props} onValidate={onValidate_} options={{ diff --git a/src/components/CodeEditor/useMonacoCustomizations.ts b/src/components/CodeEditor/useMonacoCustomizations.ts index aae7fa9c..8c83558a 100644 --- a/src/components/CodeEditor/useMonacoCustomizations.ts +++ b/src/components/CodeEditor/useMonacoCustomizations.ts @@ -314,7 +314,7 @@ export default function useMonacoCustomizations({ left: 0, right: 0, bottom: 0, - zIndex: theme.zIndex.tooltip + 1, + zIndex: theme.zIndex.tooltip * 2, m: "0 !important", resize: "none", backgroundColor: theme.palette.background.paper, diff --git a/src/components/ErrorFallback.tsx b/src/components/ErrorFallback.tsx index 40494a0b..d477f4fb 100644 --- a/src/components/ErrorFallback.tsx +++ b/src/components/ErrorFallback.tsx @@ -42,6 +42,7 @@ export default function ErrorFallback({ {error.message}