From a53180ee31e165402543a8234e618b24f704e22a Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Sat, 8 Jun 2024 18:08:04 -0300 Subject: [PATCH] Refactor: Enable editing on double click and make changes in initial state --- .../EditShortcutButton/index.tsx | 28 +++++++++++++++---- .../pages/ShortcutsPage/index.tsx | 14 +++++----- src/frontend/src/style/classes.css | 4 +++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx index a446336c1..3f596da57 100644 --- a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/EditShortcutButton/index.tsx @@ -15,6 +15,7 @@ export default function EditShortcutButton({ open, setOpen, disable, + setSelected, }: { children: JSX.Element; shortcut: string[]; @@ -23,9 +24,19 @@ export default function EditShortcutButton({ open: boolean; setOpen: (bool: boolean) => void; disable?: boolean; + setSelected: (selected: string[]) => void; }): JSX.Element { const isMac = navigator.userAgent.toUpperCase().includes("MAC"); - const [key, setKey] = useState(""); + console.log(shortcut[0]?.split(" ")[0].toLowerCase()); + let shortcutInitialValue = + defaultShortcuts.length > 0 + ? defaultShortcuts.find( + (s) => + s.name.split(" ")[0].toLowerCase().toLowerCase() === + shortcut[0]?.split(" ")[0].toLowerCase(), + )?.shortcut + : ""; + const [key, setKey] = useState(null); const setSuccessData = useAlertStore((state) => state.setSuccessData); const setShortcuts = useShortcutsStore((state) => state.setShortcuts); const unavaliableShortcuts = useShortcutsStore( @@ -98,7 +109,12 @@ export default function EditShortcutButton({ } useEffect(() => { - if (!open) setKey(null); + if (!open) { + setKey(null); + setSelected([]); + } + console.log(key); + console.log(shortcutInitialValue); }, [open, setOpen, key]); function getFixedCombination({ @@ -153,20 +169,22 @@ export default function EditShortcutButton({
- {key && key.toUpperCase()} + {key === null + ? shortcutInitialValue?.toUpperCase() + : key.toUpperCase()}
diff --git a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx index e79d59c1e..151101de2 100644 --- a/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx +++ b/src/frontend/src/pages/SettingsPage/pages/ShortcutsPage/index.tsx @@ -22,12 +22,10 @@ export default function ShortcutsPage() { field: "name", flex: 1, editable: false, - headerCheckboxSelection: true, - checkboxSelection: true, - showDisabledCheckboxes: true, resizable: false, }, //This column will be twice as wide as the others { + headerName: "Functionality", field: "shortcut", flex: 2, editable: false, @@ -77,11 +75,9 @@ export default function ShortcutsPage() { defaultShortcuts={shortcuts} open={open} setOpen={setOpen} + setSelected={setSelectedRows} > - +
diff --git a/src/frontend/src/style/classes.css b/src/frontend/src/style/classes.css index b25da3dfb..b375d166e 100644 --- a/src/frontend/src/style/classes.css +++ b/src/frontend/src/style/classes.css @@ -19,6 +19,10 @@ pre { display: none; } +.ag-row { + cursor: pointer; +} + .react-flow__pane { cursor: default; }