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

fix: save and deploy change #1938

Merged
merged 11 commits into from
Sep 19, 2024
Merged
22 changes: 19 additions & 3 deletions keep-ui/app/workflows/builder/ReactFlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ const ReactFlowEditor = ({
};
onDefinitionChange: (def: Definition) => void
}) => {
const { selectedNode, changes, v2Properties, nodes, edges, setOpneGlobalEditor, synced, setSynced } = useStore();
const { selectedNode, changes, v2Properties, nodes, edges, setOpneGlobalEditor, synced, setSynced, setCanDeploy } = useStore();
const [isOpen, setIsOpen] = useState(false);
const stepEditorRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
const isTrigger = ['interval', 'manual', 'alert'].includes(selectedNode || '')
const saveRef = useRef<boolean>(false);
useEffect(()=>{
if(saveRef.current && synced){
setCanDeploy(true);
saveRef.current = false;
}
}, [saveRef?.current, synced])


useEffect(() => {
setIsOpen(true);
if (selectedNode) {
saveRef.current = false;
const timer = setTimeout(() => {
if (isTrigger) {
setOpneGlobalEditor(true);
Expand Down Expand Up @@ -114,9 +123,16 @@ const ReactFlowEditor = ({
</button>
<div className="flex-1 p-2 bg-white border-2 overflow-y-auto">
<div style={{ width: "300px" }}>
<GlobalEditorV2 synced={synced} />
<GlobalEditorV2 synced={synced}
saveRef={saveRef}
/>
{!selectedNode?.includes('empty') && !isTrigger && <Divider ref={stepEditorRef} />}
{!selectedNode?.includes('empty') && !isTrigger && <StepEditorV2 providers={providers} installedProviders={installedProviders} setSynced={setSynced} />}
{!selectedNode?.includes('empty') && !isTrigger && <StepEditorV2
providers={providers}
installedProviders={installedProviders}
setSynced={setSynced}
saveRef={saveRef}
/>}
</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion keep-ui/app/workflows/builder/builder-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export type FlowState = {
errorNode: string | null;
synced: boolean;
setSynced: (synced: boolean) => void;
canDeploy: boolean;
setCanDeploy: (deploy: boolean) => void;
};


Expand Down Expand Up @@ -260,6 +262,8 @@ const useStore = create<FlowState>((set, get) => ({
firstInitilisationDone: false,
errorNode: null,
synced: true,
canDeploy: false,
setCanDeploy: (deploy)=>set({canDeploy: deploy}),
setSynced: (sync) => set({ synced: sync }),
setErrorNode: (id) => set({ errorNode: id }),
setFirstInitilisationDone: (firstInitilisationDone) => set({ firstInitilisationDone }),
Expand Down Expand Up @@ -291,7 +295,7 @@ const useStore = create<FlowState>((set, get) => ({
});
set({
nodes: updatedNodes,
changes: get().changes + 1
changes: get().changes + 1,
});
}
},
Expand Down
22 changes: 21 additions & 1 deletion keep-ui/app/workflows/builder/builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { WorkflowExecution, WorkflowExecutionFailure } from "./types";
import ReactFlowBuilder from "./ReactFlowBuilder";
import { ReactFlowProvider } from "@xyflow/react";
import useStore, { ReactFlowDefinition, V2Step, Definition as FlowDefinition } from "./builder-store";
import { toast } from "react-toastify";

interface Props {
loadedAlertFile: string | null;
Expand Down Expand Up @@ -76,7 +77,7 @@ function Builder({
const [compiledAlert, setCompiledAlert] = useState<Alert | null>(null);

const searchParams = useSearchParams();
const { setErrorNode } = useStore();
const { errorNode, setErrorNode, canDeploy, synced } = useStore();

const setStepValidationErrorV2 = (step: V2Step, error: string | null) => {
setStepValidationError(error);
Expand Down Expand Up @@ -210,7 +211,12 @@ function Builder({
}, [triggerRun]);

useEffect(() => {

if (triggerSave) {
if(!synced) {
toast('Please save the previous step or wait while properties sync with the workflow.');
return;
}
if (workflowId) {
updateWorkflow();
} else {
Expand All @@ -220,6 +226,20 @@ function Builder({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [triggerSave]);

useEffect(()=>{
if (canDeploy && !errorNode && definition.isValid) {
if(!synced) {
toast('Please save the previous step or wait while properties sync with the workflow.');
return;
}
if (workflowId) {
updateWorkflow();
} else {
addWorkflow();
}
}
}, [canDeploy, errorNode, definition?.isValid])

useEffect(() => {
enableGenerate(
(definition.isValid &&
Expand Down
Loading
Loading