From 1ce4193a9958159552a04ac5cb2e6db000eb3ea6 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Tue, 12 Mar 2024 16:30:05 -0300 Subject: [PATCH] Feat: Create ToolbarSelectItem to avoid duplicated code --- .../components/nodeToolbarComponent/index.tsx | 160 +++++------------- .../toolbarSelectItem/index.tsx | 44 +++++ src/frontend/src/types/components/index.ts | 16 ++ 3 files changed, 104 insertions(+), 116 deletions(-) create mode 100644 src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/toolbarSelectItem/index.tsx diff --git a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx index fa2c4757b..06ee3719e 100644 --- a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx @@ -30,6 +30,7 @@ import { updateFlowPosition, } from "../../../../utils/reactflowUtils"; import { classNames, cn } from "../../../../utils/utils"; +import ToolbarSelectItem from "./toolbarSelectItem"; export default function NodeToolbarComponent({ data, @@ -445,86 +446,42 @@ export default function NodeToolbarComponent({ {nodeLength > 0 && ( -
- {" "} - Edit{" "} - {navigator.userAgent.toUpperCase().includes("MAC") ? ( - - ) : ( - - Ctrl +{" "} - - )} - E -
+
)} -
- - Duplicate - {navigator.userAgent.toUpperCase().includes("MAC") ? ( - - ) : ( - - Ctrl +{" "} - - )} - D -
{" "} +
-
- {" "} - Copy{" "} - {navigator.userAgent.toUpperCase().includes("MAC") ? ( - - ) : ( - - Ctrl +{" "} - - )} - C -
+
{isOutdated && ( -
- {" "} - Update{" "} - {navigator.userAgent.toUpperCase().includes("MAC") ? ( - - ) : ( - - Ctrl +{" "} - - )} - U -
+
)} {hasStore && ( @@ -532,28 +489,14 @@ export default function NodeToolbarComponent({ value={"Share"} disabled={!hasApiKey || !validApiKey} > -
- {" "} - Share{" "} - {navigator.userAgent.toUpperCase().includes("MAC") ? ( - - ) : ( - - Ctrl - - )} - - S -
{" "} + )} {!hasStore && ( @@ -571,28 +514,13 @@ export default function NodeToolbarComponent({ value={"documentation"} disabled={data.node?.documentation === ""} > -
- {" "} - Docs{" "} - {navigator.userAgent.toUpperCase().includes("MAC") ? ( - - ) : ( - - Ctrl - - )} - - D -
+ {isMinimal && ( diff --git a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/toolbarSelectItem/index.tsx b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/toolbarSelectItem/index.tsx new file mode 100644 index 000000000..00e31e08a --- /dev/null +++ b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/toolbarSelectItem/index.tsx @@ -0,0 +1,44 @@ +import { useEffect } from "react"; +import ForwardedIconComponent from "../../../../../components/genericIconComponent"; +import { toolbarSelectItemProps } from "../../../../../types/components"; + +export default function ToolbarSelectItem({ + shift, + isMac, + keyboardKey, + value, + icon, + styleObj, +}: toolbarSelectItemProps) { + + return ( +
+ {" "} + {value}{" "} + {isMac ? ( + + ) : ( + + {shift ? ( + "Ctrl" + ) : ( + "Ctrl +" + )} + + )} + {shift && ( + + )} + {keyboardKey} +
+ ); +} diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 379f5be30..55f33da16 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -688,3 +688,19 @@ export type IOFileInputProps = { field: TemplateVariableType; updateValue: (e: any, type: string) => void; }; + +export type toolbarSelectItemProps = { + isMac: boolean; + shift: boolean; + keyboardKey: string; + value: string; + icon: string; + styleObj?: { + iconClasses?: string; + commandClasses?: string; + shiftClasses?: string; + ctrlClasses?: string; + keyClasses?: string; + valueClasses?: string; + } +};