Skip to content

Commit

Permalink
Merge branch 'main' into ui/multi-delete-sub-work-flow-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
billcookie authored Jan 8, 2025
2 parents b5a32e5 + 858e81d commit daf7631
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,55 @@ type Props = {
canRedo: boolean;
onRedo?: () => void;
onUndo?: () => void;
isMainWorkflow: boolean;
};

const Toolbox: React.FC<Props> = ({ canUndo, canRedo, onRedo, onUndo }) => {
const Toolbox: React.FC<Props> = ({
canUndo,
canRedo,
onRedo,
onUndo,
isMainWorkflow,
}) => {
const t = useT();

const availableTools: Tool[] = [
{
id: "reader",
id: "reader" as const,
name: t("Reader Node"),
icon: <Database weight="thin" />,
},
{
id: "transformer",
id: "transformer" as const,
name: t("Transformer Node"),
icon: <Lightning weight="thin" />,
},
{
id: "writer",
id: "writer" as const,
name: t("Writer Node"),
icon: <Disc weight="thin" />,
},
{
id: "note",
id: "note" as const,
name: t("Note"),
icon: <Note weight="thin" />,
},
{
id: "batch",
id: "batch" as const,
name: t("Batch Node"),
icon: <RectangleDashed weight="thin" />,
},
{
id: "subworkflow",
id: "subworkflow" as const,
name: t("Subworkflow Node"),
icon: <Graph weight="thin" />,
},
];
].filter((tool) => {
if (!isMainWorkflow) {
return tool.id !== "reader" && tool.id !== "writer";
}
return true;
});

const availableActions: Action[] = [
{
Expand Down Expand Up @@ -97,7 +109,7 @@ const Toolbox: React.FC<Props> = ({ canUndo, canRedo, onRedo, onUndo }) => {
<div className="flex size-12 rounded bg-secondary">
<div
className={`
flex w-full justify-center rounded align-middle
flex w-full justify-center rounded align-middle
${
nodeType === "reader"
? "bg-node-reader/60"
Expand Down
3 changes: 3 additions & 0 deletions ui/src/features/Editor/components/OverlayUI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type OverlayUIProps = {
onNodePickerClose: () => void;
onWorkflowUndo: () => void;
onWorkflowRedo: () => void;
isMainWorkflow: boolean;
children?: React.ReactNode;
};

Expand All @@ -43,6 +44,7 @@ const OverlayUI: React.FC<OverlayUIProps> = ({
onNodePickerClose,
onWorkflowUndo,
onWorkflowRedo,
isMainWorkflow,
children: canvas,
}) => {
// const { devMode } = config();
Expand All @@ -58,6 +60,7 @@ const OverlayUI: React.FC<OverlayUIProps> = ({
canRedo={canRedo}
onRedo={onWorkflowRedo}
onUndo={onWorkflowUndo}
isMainWorkflow={isMainWorkflow}
/>
<ActionBar
allowedToDeploy={allowedToDeploy}
Expand Down
7 changes: 5 additions & 2 deletions ui/src/features/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Array as YArray, UndoManager as YUndoManager } from "yjs";

import { YWorkflow } from "@flow/lib/yjs/utils";

import { useIsMainWorkflow } from "../KeyboardShortcutDialog/useHooks";

import {
BottomPanel,
Canvas,
Expand Down Expand Up @@ -51,7 +53,7 @@ export default function Editor({
handleWorkflowUndo,
handleWorkflowRename,
} = useHooks({ yWorkflows, undoManager, undoTrackerActionWrapper });

const isMainWorkflow = useIsMainWorkflow(currentWorkflowId);
return (
<div className="flex h-screen flex-col">
<div className="relative flex flex-1">
Expand All @@ -72,7 +74,8 @@ export default function Editor({
onWorkflowUndo={handleWorkflowUndo}
onWorkflowRedo={handleWorkflowRedo}
onNodesChange={handleNodesUpdate}
onNodePickerClose={handleNodePickerClose}>
onNodePickerClose={handleNodePickerClose}
isMainWorkflow={isMainWorkflow}>
<Canvas
nodes={nodes}
edges={edges}
Expand Down
9 changes: 9 additions & 0 deletions ui/src/features/KeyboardShortcutDialog/useHooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { useMemo } from "react";

import { DEFAULT_ENTRY_GRAPH_ID } from "@flow/global-constants";
import { useT } from "@flow/lib/i18n";
import {
Shortcuts,
Expand All @@ -9,6 +12,12 @@ import {
GeneralKeys,
} from "@flow/types";

export const useIsMainWorkflow = (currentWorkflowId: string | undefined) => {
return useMemo(() => {
return currentWorkflowId === DEFAULT_ENTRY_GRAPH_ID;
}, [currentWorkflowId]);
};

export default () => {
const t = useT();

Expand Down

0 comments on commit daf7631

Please sign in to comment.