Refactor: Enable editing on double click and make changes in initial state
This commit is contained in:
parent
9c88ed3cf6
commit
a53180ee31
3 changed files with 34 additions and 12 deletions
|
|
@ -15,6 +15,7 @@ export default function EditShortcutButton({
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
disable,
|
disable,
|
||||||
|
setSelected,
|
||||||
}: {
|
}: {
|
||||||
children: JSX.Element;
|
children: JSX.Element;
|
||||||
shortcut: string[];
|
shortcut: string[];
|
||||||
|
|
@ -23,9 +24,19 @@ export default function EditShortcutButton({
|
||||||
open: boolean;
|
open: boolean;
|
||||||
setOpen: (bool: boolean) => void;
|
setOpen: (bool: boolean) => void;
|
||||||
disable?: boolean;
|
disable?: boolean;
|
||||||
|
setSelected: (selected: string[]) => void;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const isMac = navigator.userAgent.toUpperCase().includes("MAC");
|
const isMac = navigator.userAgent.toUpperCase().includes("MAC");
|
||||||
const [key, setKey] = useState<string | null>("");
|
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<string | null>(null);
|
||||||
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
||||||
const setShortcuts = useShortcutsStore((state) => state.setShortcuts);
|
const setShortcuts = useShortcutsStore((state) => state.setShortcuts);
|
||||||
const unavaliableShortcuts = useShortcutsStore(
|
const unavaliableShortcuts = useShortcutsStore(
|
||||||
|
|
@ -98,7 +109,12 @@ export default function EditShortcutButton({
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) setKey(null);
|
if (!open) {
|
||||||
|
setKey(null);
|
||||||
|
setSelected([]);
|
||||||
|
}
|
||||||
|
console.log(key);
|
||||||
|
console.log(shortcutInitialValue);
|
||||||
}, [open, setOpen, key]);
|
}, [open, setOpen, key]);
|
||||||
|
|
||||||
function getFixedCombination({
|
function getFixedCombination({
|
||||||
|
|
@ -153,20 +169,22 @@ export default function EditShortcutButton({
|
||||||
<BaseModal.Content>
|
<BaseModal.Content>
|
||||||
<div className="align-center flex h-full w-full justify-center gap-4">
|
<div className="align-center flex h-full w-full justify-center gap-4">
|
||||||
<div className="flex items-center justify-center text-center text-lg font-bold">
|
<div className="flex items-center justify-center text-center text-lg font-bold">
|
||||||
{key && key.toUpperCase()}
|
{key === null
|
||||||
|
? shortcutInitialValue?.toUpperCase()
|
||||||
|
: key.toUpperCase()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</BaseModal.Content>
|
</BaseModal.Content>
|
||||||
<BaseModal.Footer>
|
<BaseModal.Footer>
|
||||||
<Button variant={"secondary"} onClick={editCombination}>
|
<Button variant={"secondary"} onClick={editCombination}>
|
||||||
Edit Combination
|
Apply
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
className="mr-5"
|
className="mr-5"
|
||||||
variant={"destructive"}
|
variant={"destructive"}
|
||||||
onClick={() => setKey(null)}
|
onClick={() => setKey(null)}
|
||||||
>
|
>
|
||||||
Reset Combination
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
</BaseModal.Footer>
|
</BaseModal.Footer>
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,10 @@ export default function ShortcutsPage() {
|
||||||
field: "name",
|
field: "name",
|
||||||
flex: 1,
|
flex: 1,
|
||||||
editable: false,
|
editable: false,
|
||||||
headerCheckboxSelection: true,
|
|
||||||
checkboxSelection: true,
|
|
||||||
showDisabledCheckboxes: true,
|
|
||||||
resizable: false,
|
resizable: false,
|
||||||
}, //This column will be twice as wide as the others
|
}, //This column will be twice as wide as the others
|
||||||
{
|
{
|
||||||
|
headerName: "Functionality",
|
||||||
field: "shortcut",
|
field: "shortcut",
|
||||||
flex: 2,
|
flex: 2,
|
||||||
editable: false,
|
editable: false,
|
||||||
|
|
@ -77,11 +75,9 @@ export default function ShortcutsPage() {
|
||||||
defaultShortcuts={shortcuts}
|
defaultShortcuts={shortcuts}
|
||||||
open={open}
|
open={open}
|
||||||
setOpen={setOpen}
|
setOpen={setOpen}
|
||||||
|
setSelected={setSelectedRows}
|
||||||
>
|
>
|
||||||
<Button variant="primary">
|
<div style={{ display: "none" }} />
|
||||||
<ForwardedIconComponent name="Wrench" className="mr-2 w-4" />
|
|
||||||
Customize
|
|
||||||
</Button>
|
|
||||||
</EditShortcutButton>
|
</EditShortcutButton>
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
|
|
@ -109,6 +105,10 @@ export default function ShortcutsPage() {
|
||||||
columnDefs={colDefs}
|
columnDefs={colDefs}
|
||||||
rowData={nodesRowData}
|
rowData={nodesRowData}
|
||||||
paginationPageSize={8}
|
paginationPageSize={8}
|
||||||
|
onCellDoubleClicked={(e) => {
|
||||||
|
setSelectedRows([e.data.name]);
|
||||||
|
setOpen(true);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ pre {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ag-row {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.react-flow__pane {
|
.react-flow__pane {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue