Skip to content

Commit

Permalink
feat: improve the buidler actions and form validtions
Browse files Browse the repository at this point in the history
  • Loading branch information
rajesh-jonnalagadda committed Dec 10, 2024
1 parent 411f640 commit 8182ae8
Show file tree
Hide file tree
Showing 11 changed files with 1,468 additions and 511 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export default function WorkflowOverview({
</StatsCard>
<StatsCard>
<Title>Involved Services</Title>
<WorkflowSteps workflow={parsedWorkflowFile} />
<WorkflowSteps workflow={parsedWorkflowFile} key={workflow_id}/>
</StatsCard>
</div>
<WorkflowGraph
Expand Down
6 changes: 3 additions & 3 deletions keep-ui/app/(keep)/workflows/builder/ReactFlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useStore, {
ReactFlowDefinition,
Definition,
} from "./builder-store";
import { GlobalEditorV2, StepEditorV2 } from "./editors";
import { GlobalEditorV2, StepEditorV3 } from "./editors";
import { Divider } from "@tremor/react";
import { Provider } from "@/app/(keep)/providers/providers";
import { reConstructWorklowToDefinition } from "utils/reactFlow";
Expand Down Expand Up @@ -115,7 +115,7 @@ const ReactFlowEditor = ({
};
const debouncedHandleDefinitionChange = debounce(
handleDefinitionChange,
300
1000
);

debouncedHandleDefinitionChange();
Expand Down Expand Up @@ -155,7 +155,7 @@ const ReactFlowEditor = ({
<Divider ref={stepEditorRef} />
)}
{!selectedNode?.includes("empty") && !isTrigger && (
<StepEditorV2
<StepEditorV3
providers={providers}
installedProviders={installedProviders}
setSynced={setSynced}
Expand Down
81 changes: 62 additions & 19 deletions keep-ui/app/(keep)/workflows/builder/ToolBox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useMemo } from "react";
import { Disclosure } from "@headlessui/react";
import { Subtitle } from "@tremor/react";
import { Subtitle, Switch } from "@tremor/react";
import { IoChevronUp, IoClose } from "react-icons/io5";
import Image from "next/image";
import { IoIosArrowDown } from "react-icons/io";
Expand Down Expand Up @@ -92,7 +92,7 @@ const GroupedMenu = ({
{steps.length > 0 &&
steps.map((step: any) => (
<li
key={step.type}
key={`${step.type}__${step.id || step.name}`}
className="dndnode p-2 my-1 border border-gray-300 rounded cursor-pointer truncate flex justify-start gap-2 items-center"
onDragStart={(event) => handleDragStart(event, { ...step })}
draggable={isDraggable}
Expand Down Expand Up @@ -124,7 +124,8 @@ const DragAndDropSidebar = ({ isDraggable }: { isDraggable?: boolean }) => {
const [searchTerm, setSearchTerm] = useState("");
const [isVisible, setIsVisible] = useState(false);
const [open, setOpen] = useState(false);
const { toolboxConfiguration, selectedNode, selectedEdge, nodes } =
const [showinstalled, setShowInstalled] = useState(true);
const { toolboxConfiguration, selectedNode, selectedEdge, nodes, edges } =
useStore();

useEffect(() => {
Expand All @@ -147,17 +148,46 @@ const DragAndDropSidebar = ({ isDraggable }: { isDraggable?: boolean }) => {
);

const filteredGroups = useMemo(() => {
return (
const checkInstalled = (step: V2Step, groupName: string) => {
if (!showinstalled) {
return true;
}

if (["Conditions", "Misc", "Triggers"].includes(groupName)) {
return true;
}

return step?.installed;
};
let finalGroups =
toolboxConfiguration?.groups?.map((group: any) => ({
...group,
steps: group?.steps?.filter(
(step: any) =>
checkInstalled(step, group.name) &&
step?.name?.toLowerCase().includes(searchTerm?.toLowerCase()) &&
!triggerNodeMap[step?.id]
),
})) || []
);
}, [toolboxConfiguration, searchTerm, nodes?.length]);
})) || [];
const selectedAddEdge = edges.find((edge) => edge.id === selectedEdge);
if (selectedEdge && selectedAddEdge) {
finalGroups = finalGroups.filter(
(group: { name: string }) =>
(group?.name == "Triggers" &&
selectedAddEdge.source === "trigger_start") ||
(selectedAddEdge.source !== "trigger_start" &&
group?.name !== "Triggers")
);
}
return finalGroups;
}, [
toolboxConfiguration?.groups,
edges,
selectedEdge,
showinstalled,
searchTerm,
triggerNodeMap,
]);

const checkForSearchResults =
searchTerm &&
Expand All @@ -177,7 +207,9 @@ const DragAndDropSidebar = ({ isDraggable }: { isDraggable?: boolean }) => {
<div className="relative h-full flex flex-col">
{/* Sticky header */}
<div className="sticky top-0 left-0 z-10">
<h1 className="p-3 font-bold">Toolbox</h1>
<div className="flex justify-between">
<h1 className="p-3 font-bold">Toolbox</h1>
</div>
<div className="flex items-center justify-between p-2 pt-0 border-b-2 bg-white">
<input
type="text"
Expand All @@ -204,17 +236,28 @@ const DragAndDropSidebar = ({ isDraggable }: { isDraggable?: boolean }) => {

{/* Scrollable list */}
{(isVisible || checkForSearchResults) && (
<div className="flex-1 overflow-y-auto pt-6 space-y-4 overflow-hidden">
{filteredGroups.length > 0 &&
filteredGroups.map((group: Record<string, any>) => (
<GroupedMenu
key={group.name}
name={group.name}
steps={group.steps}
searchTerm={searchTerm}
isDraggable={isDraggable}
/>
))}
<div className="flex-1 overflow-y-auto overflow-hidden">
<div className="flex flex-col items-end mr-4">
<div>Installed</div>
<Switch
id="installed"
name="Installed"
checked={showinstalled}
onChange={setShowInstalled}
/>
</div>
<div className="space-y-4 pt-4">
{filteredGroups.length > 0 &&
filteredGroups.map((group: Record<string, any>) => (
<GroupedMenu
key={group.name}
name={group.name}
steps={group.steps}
searchTerm={searchTerm}
isDraggable={isDraggable}
/>
))}
</div>
</div>
)}
</div>
Expand Down
11 changes: 11 additions & 0 deletions keep-ui/app/(keep)/workflows/builder/builder-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type V2Step = {
edgeSource?: string;
edgeTarget?: string;
notClickable?: boolean;
installed?: boolean;
};

export type NodeData = Node["data"] & Record<string, any>;
Expand Down Expand Up @@ -100,6 +101,10 @@ export type FlowState = {
openGlobalEditor: boolean;
stepEditorOpenForNode: string | null;
toolboxConfiguration: Record<string, any>;
stepErrors: Record<string,string> | null;
globalErrors: Record<string,string> | null;
setStepErrors: (error: Record<string,string> | null) => void;
setGlobalErros: (error: Record<string,string> | null) => void;
onNodesChange: OnNodesChange<FlowNode>;
onEdgesChange: OnEdgesChange<Edge>;
onConnect: OnConnect;
Expand Down Expand Up @@ -290,6 +295,8 @@ function addNodeBetween(
break;
}
}
//on adding new node. highlight the added node and update the editor
set({selectedNode: newNodeId, stepEditorOpenForNode: newNodeId})
}

const useStore = create<FlowState>((set, get) => ({
Expand All @@ -308,6 +315,10 @@ const useStore = create<FlowState>((set, get) => ({
errorNode: null,
synced: true,
canDeploy: false,
stepErrors: null,
globalErrors: null,
setGlobalErros: (errors:Record<string,string>|null)=>set({globalErrors: errors}),
setStepErrors: (errors:Record<string,string>|null)=>set({stepErrors: errors}),
setCanDeploy: (deploy) => set({ canDeploy: deploy }),
setSynced: (sync) => set({ synced: sync }),
setErrorNode: (id) => set({ errorNode: id }),
Expand Down
Loading

0 comments on commit 8182ae8

Please sign in to comment.