Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
chore: Add delete all flows functionality
Browse files Browse the repository at this point in the history
This commit add the functionality to remove all
existing flows in the canvas

related: #801
  • Loading branch information
lordrip committed May 10, 2023
1 parent 05365fe commit 28a1a6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/components/KaotoToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LOCAL_STORAGE_UI_THEME_KEY, THEME_DARK_CLASS } from '@kaoto/constants';
import { ValidationService } from '@kaoto/services';
import {
useDeploymentStore,
useFlowsStore,
useIntegrationJsonStore,
useIntegrationSourceStore,
useSettingsStore,
Expand Down Expand Up @@ -61,6 +62,7 @@ export const KaotoToolbar = ({ toggleCatalog, toggleCodeEditor, hideLeftPanel, l
const { settings, setSettings } = useSettingsStore((state) => state);
const { sourceCode, setSourceCode } = useIntegrationSourceStore((state) => state);
const deleteIntegration = useIntegrationJsonStore((state) => state.deleteIntegration);
const deleteAllIntegrations = useFlowsStore((state) => state.deleteAllIntegrations);
const [isActiveButton,setIsActiveButton] = useState('');
const htmlTagElement = document.documentElement;

Expand Down Expand Up @@ -435,7 +437,11 @@ export const KaotoToolbar = ({ toggleCatalog, toggleCodeEditor, hideLeftPanel, l
setIsConfirmationModalOpen(false);
}}
handleConfirm={() => {
/** Delete current flow */
deleteIntegration();

/** Delete all flows */
deleteAllIntegrations();
setSourceCode('');
setSettings({ dsl: settings.dsl, name: 'integration', namespace: 'default' });
setIsConfirmationModalOpen(false);
Expand Down
7 changes: 4 additions & 3 deletions src/components/Visualization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
VisualizationStepViews,
} from '@kaoto/components';
import { StepsService, VisualizationService } from '@kaoto/services';
import { useIntegrationJsonStore, useSettingsStore, useVisualizationStore } from '@kaoto/store';
import { useFlowsStore, useIntegrationJsonStore, useSettingsStore, useVisualizationStore } from '@kaoto/store';
import { IStepProps, IVizStepNode } from '@kaoto/types';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import ReactFlow, { Background, Viewport } from 'reactflow';
Expand All @@ -35,6 +35,7 @@ const Visualization = () => {
});

const useMultipleFlows = useSettingsStore((state) => state.settings.useMultipleFlows);
const flows = useFlowsStore((state) => state.flows);
const visualizationStore = useVisualizationStore.getState();
const layout = useVisualizationStore((state) => state.layout);
const nodes = useVisualizationStore((state) => state.nodes);
Expand All @@ -49,7 +50,7 @@ const Visualization = () => {
*/
useEffect(() => {
stepsService.updateViews();
}, [integrationJson, stepsService]);
}, [integrationJson, flows, stepsService]);

/**
* Check for changes to integrationJson to refresh the selected step's data.
Expand All @@ -72,7 +73,7 @@ const Visualization = () => {

useEffect(() => {
visualizationService.redrawDiagram(handleDeleteStep, true).catch((e) => console.error(e));
}, [integrationJson, layout, useMultipleFlows]);
}, [integrationJson, layout, useMultipleFlows, flows]);

const nodeTypes = useMemo(() => ({ step: VisualizationStep }), []);
const edgeTypes = useMemo(
Expand Down
2 changes: 2 additions & 0 deletions src/store/flowsStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IFlowsStore {
// Handler methods
insertStep: IInsertOptions;
deleteStep: (integrationId: string, stepUUID: string) => void;
deleteAllIntegrations: () => void;
}

export const flowsInitialState: Pick<IFlowsStore, 'flows' | 'properties' | 'views'> = {
Expand Down Expand Up @@ -111,6 +112,7 @@ export const useFlowsStore = create<IFlowsStore>()(
return state;
});
},
deleteAllIntegrations: () => set((state) => ({ ...state, ...flowsInitialState })),
}),
{
partialize: (state) => {
Expand Down

0 comments on commit 28a1a6e

Please sign in to comment.