From 0e9910b6666e70dfa5afb2acccecc8aa9df33c53 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Fri, 1 Mar 2024 11:50:32 -0300 Subject: [PATCH] Feat: add shortcut to minimize/expand a node (ctrl Q) --- .../components/codeAreaComponent/index.tsx | 2 ++ .../src/components/ui/select-custom.tsx | 2 +- .../src/modals/ConfirmationModal/index.tsx | 2 +- .../src/modals/codeAreaModal/index.tsx | 2 ++ .../components/nodeToolbarComponent/index.tsx | 28 +++++++++++++++++-- src/frontend/src/types/components/index.ts | 2 ++ 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/components/codeAreaComponent/index.tsx b/src/frontend/src/components/codeAreaComponent/index.tsx index db94065ba..f19b4115b 100644 --- a/src/frontend/src/components/codeAreaComponent/index.tsx +++ b/src/frontend/src/components/codeAreaComponent/index.tsx @@ -16,6 +16,7 @@ export default function CodeAreaComponent({ readonly = false, openModal, selected, + setOpenModal, }: CodeAreaComponentType) { const [myValue, setMyValue] = useState( typeof value == "string" ? value : JSON.stringify(value) @@ -36,6 +37,7 @@ export default function CodeAreaComponent({ + {triggerChild} {title} diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index 100a578ff..d4cf83780 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -37,6 +37,7 @@ export default function CodeAreaModal({ readonly = false, openModal, selected, + setOpenModal, }: codeAreaModalPropsType): JSX.Element { const [code, setCode] = useState(value); const dark = useDarkStore((state) => state.dark); @@ -49,6 +50,7 @@ export default function CodeAreaModal({ } | null>(null); const [open, setOpen] = useState(false); const nodes = useFlowStore((state) => state.nodes); + useEffect(() => { // if nodeClass.template has more fields other than code and dynamic is true diff --git a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx index 409bd432c..b2af560fa 100644 --- a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx @@ -209,6 +209,24 @@ export default function NodeToolbarComponent({ useEffect(() => { function onKeyDown(event: KeyboardEvent) { + if ( + (selected && isMinimal) && + (event.ctrlKey || event.metaKey) && + event.key === "q" + ) { + event.preventDefault(); + setShowNode(data.showNode ?? true ? false : true); + unselectAll(); + } + if ( + selected && + (event.ctrlKey || event.metaKey) && + event.shiftKey && + event.key === "C" + ) { + event.preventDefault(); + setOpenModal(state => !state); + } if ( selected && (event.ctrlKey || event.metaKey) && @@ -270,6 +288,7 @@ export default function NodeToolbarComponent({
- {showNode ? "Minimize" : "Expand"} -
+ + Q +
)} {isGroup && ( diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index ac4512c29..df21a7b45 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -103,6 +103,7 @@ export type PromptAreaComponentType = { }; export type CodeAreaComponentType = { + setOpenModal?: (bool: boolean) => void; disabled: boolean; onChange: (value: string[] | string) => void; value: string; @@ -513,6 +514,7 @@ export type modalHeaderType = { export type codeAreaModalPropsType = { setValue: (value: string) => void; + setOpenModal?: (bool: boolean) => void; value: string; nodeClass: APIClassType | undefined; setNodeClass: (Class: APIClassType, code?: string) => void | undefined;