Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve node toolbar code #3311

Merged
merged 30 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
56a5b13
remove repeated code
anovazzi1 Aug 7, 2024
bce2e6a
refactor: remove useless code
anovazzi1 Aug 7, 2024
19abddb
feat: sort input parameters in GenericNode renderInputParameter
anovazzi1 Aug 7, 2024
a7bd5f9
refactor: remove unused code in GenericNode component
anovazzi1 Aug 8, 2024
ae9c37f
refactor: add NodeName component for displaying and editing node names
anovazzi1 Aug 8, 2024
4b27c6b
refactor: add NodeDescription component for displaying and editing no…
anovazzi1 Aug 8, 2024
f6c1041
fix import and add autofocus on nodeName
anovazzi1 Aug 8, 2024
55247d0
feat: add NodeStatus component for displaying and managing node status
anovazzi1 Aug 8, 2024
9bbeaa4
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 8, 2024
693fe70
refactor: remove unused code in GenericNode component
anovazzi1 Aug 8, 2024
8a067a9
fix bugs on minimize
anovazzi1 Aug 8, 2024
52689fa
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 8, 2024
a33f8fc
Merge remote-tracking branch 'origin/main' into refactorNode
anovazzi1 Aug 13, 2024
bc3448b
refactor: remove unused code and handle count in GenericNodeToolbar c…
anovazzi1 Aug 8, 2024
4aaef1f
refactor: Add useShortcuts hook for handling keyboard shortcuts in no…
anovazzi1 Aug 8, 2024
e288013
refactor: Add keyboard shortcuts handling to nodeToolbarComponent nee…
anovazzi1 Aug 8, 2024
c887f09
refactor: Update FreezeAllVertices function in NodeToolbarComponent
anovazzi1 Aug 13, 2024
4eb6137
feat: Add getNodeLength function to calculate the length of a node's …
anovazzi1 Aug 13, 2024
946d391
refactor: Update RenderIcons component to use navigator.platform for …
anovazzi1 Aug 13, 2024
f3bfe0d
refactor: Add ShortcutDisplay component to nodeToolbarComponent
anovazzi1 Aug 13, 2024
bed43ae
refactor: Update nodeToolbarComponent to remove RenderIcons and add S…
anovazzi1 Aug 13, 2024
a4d7756
refactor: Improve keyboard shortcuts handling in nodeToolbarComponent
anovazzi1 Aug 13, 2024
1d4aa71
Merge remote-tracking branch 'origin/main' into refactorNodeToolbar
anovazzi1 Aug 13, 2024
84563b0
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 13, 2024
4949dd6
Merge branch 'main' into refactorNodeToolbar
anovazzi1 Aug 13, 2024
6a17223
Merge branch 'main' into refactorNodeToolbar
anovazzi1 Aug 13, 2024
e0b751b
Merge branch 'main' into refactorNodeToolbar
anovazzi1 Aug 14, 2024
49c213c
chore: Refactor NodeToolbarComponent to simplify code structure
anovazzi1 Aug 14, 2024
bee3514
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 14, 2024
62398ff
Merge branch 'main' into refactorNodeToolbar
anovazzi1 Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/frontend/src/CustomNodes/GenericNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default function GenericNode({
const takeSnapshot = useFlowsManagerStore((state) => state.takeSnapshot);
const [isOutdated, setIsOutdated] = useState(false);
const [isUserEdited, setIsUserEdited] = useState(false);
const [handles, setHandles] = useState<number>(0);
const [borderColor, setBorderColor] = useState<string>("");
const [showNode, setShowNode] = useState(data.showNode ?? true);

Expand Down Expand Up @@ -108,15 +107,6 @@ export default function GenericNode({
checkNodeIconFragment,
);

function countHandles(): void {
const count = countHandlesFn(data);
setHandles(count);
}

useEffect(() => {
countHandles();
}, [data, data.node]);

useEffect(() => {
setShowNode(data.showNode ?? true);
}, [data.showNode]);
Expand Down Expand Up @@ -228,7 +218,6 @@ export default function GenericNode({
}));
}}
setShowState={setShowNode}
numberOfHandles={handles}
numberOfOutputHandles={shownOutputs.length ?? 0}
showNode={showNode}
openAdvancedModal={false}
Expand All @@ -244,7 +233,6 @@ export default function GenericNode({
takeSnapshot,
setNode,
setShowNode,
handles,
showNode,
updateNodeCode,
isOutdated,
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/components/renderIconComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ForwardedIconComponent from "../genericIconComponent";

export default function RenderIcons({
isMac,
isMac = navigator.platform.toUpperCase().includes("MAC"),
hasShift,
filteredShortcut,
shortcutWPlus,
}: {
isMac: boolean;
isMac?: boolean;
hasShift: boolean;
filteredShortcut: string[];
shortcutWPlus: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { useShortcutsStore } from "@/stores/shortcuts";
import { useHotkeys } from "react-hotkeys-hook";
import isWrappedWithClass from "../../PageComponent/utils/is-wrapped-with-class";

export default function useShortcuts({
showOverrideModal,
showModalAdvanced,
openModal,
showconfirmShare,
FreezeAllVertices,
Freeze,
downloadFunction,
displayDocs,
saveComponent,
showAdvance,
handleCodeModal,
shareComponent,
ungroup,
minimizeFunction,
}: {
showOverrideModal: boolean;
showModalAdvanced: boolean;
openModal: boolean;
showconfirmShare: boolean;
FreezeAllVertices: () => void;
Freeze: () => void;
downloadFunction: () => void;
displayDocs: () => void;
saveComponent: () => void;
showAdvance: () => void;
handleCodeModal: () => void;
shareComponent: () => void;
ungroup: () => void;
minimizeFunction: () => void;
}) {
const advanced = useShortcutsStore((state) => state.advanced);
const minimize = useShortcutsStore((state) => state.minimize);
const component = useShortcutsStore((state) => state.component);
const save = useShortcutsStore((state) => state.save);
const docs = useShortcutsStore((state) => state.docs);
const code = useShortcutsStore((state) => state.code);
const group = useShortcutsStore((state) => state.group);
const download = useShortcutsStore((state) => state.download);
const freeze = useShortcutsStore((state) => state.freeze);
const freezeAll = useShortcutsStore((state) => state.FreezePath);

function handleFreezeAll(e: KeyboardEvent) {
if (isWrappedWithClass(e, "noflow")) return;
e.preventDefault();
FreezeAllVertices();
}

function handleFreeze(e: KeyboardEvent) {
if (isWrappedWithClass(e, "noflow")) return;
e.preventDefault();
Freeze();
}

function handleDownloadWShortcut(e: KeyboardEvent) {
e.preventDefault();
downloadFunction();
}

function handleDocsWShortcut(e: KeyboardEvent) {
e.preventDefault();
displayDocs();
}

function handleSaveWShortcut(e: KeyboardEvent) {
if (isWrappedWithClass(e, "noflow") && !showOverrideModal) return;
e.preventDefault();
saveComponent();
}

function handleAdvancedWShortcut(e: KeyboardEvent) {
//check if there is another modal open
if (isWrappedWithClass(e, "noflow") && !showModalAdvanced) return;
e.preventDefault();
showAdvance();
}

function handleCodeWShortcut(e: KeyboardEvent) {
if (isWrappedWithClass(e, "noflow") && !openModal) return;
e.preventDefault();
handleCodeModal();
}

function handleShareWShortcut(e: KeyboardEvent) {
if (isWrappedWithClass(e, "noflow") && !showconfirmShare) return;
e.preventDefault();
shareComponent();
}
function handleGroupWShortcut(e: KeyboardEvent) {
if (isWrappedWithClass(e, "noflow")) return;
e.preventDefault();
ungroup();
}

function handleMinimizeWShortcut(e: KeyboardEvent) {
if (isWrappedWithClass(e, "noflow")) return;
e.preventDefault();
minimizeFunction();
}

useHotkeys(minimize, handleMinimizeWShortcut, { preventDefault: true });
useHotkeys(group, handleGroupWShortcut, { preventDefault: true });
useHotkeys(component, handleShareWShortcut, { preventDefault: true });
useHotkeys(code, handleCodeWShortcut, { preventDefault: true });
useHotkeys(advanced, handleAdvancedWShortcut, { preventDefault: true });
useHotkeys(save, handleSaveWShortcut, { preventDefault: true });
useHotkeys(docs, handleDocsWShortcut, { preventDefault: true });
useHotkeys(download, handleDownloadWShortcut, { preventDefault: true });
useHotkeys(freeze, handleFreeze);
useHotkeys(freezeAll, handleFreezeAll);
}
Loading