From eb8ff52ac29aba962619675325d6ebe15a3e6aea Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Wed, 22 Nov 2023 20:45:55 -0300 Subject: [PATCH] chore(flowsContext.tsx): remove unused imports and variables for better code cleanliness feat(flowsContext.tsx): add support for creating a new flow with a default name if no flow is provided feat(flowsContext.tsx): add support for adding a version number to duplicate flow names feat(flowsContext.tsx): add support for saving a flow to the database and updating its id feat(flowsContext.tsx): add support for deleting a component flow feat(extraSidebarComponent/index.tsx): add support for disabling save button when there are no nodes in the flow --- src/frontend/src/contexts/flowsContext.tsx | 21 +++++++------------ .../extraSidebarComponent/index.tsx | 9 ++++++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/frontend/src/contexts/flowsContext.tsx b/src/frontend/src/contexts/flowsContext.tsx index c339f9635..526df8418 100644 --- a/src/frontend/src/contexts/flowsContext.tsx +++ b/src/frontend/src/contexts/flowsContext.tsx @@ -43,8 +43,6 @@ import { createRandomKey, getRandomDescription, getRandomName, - getSetFromObject, - removeCountFromString, } from "../utils/utils"; import { alertContext } from "./alertContext"; import { AuthContext } from "./authContext"; @@ -504,27 +502,22 @@ export function FlowsProvider({ children }: { children: ReactNode }) { let flowData = flow ? processDataFromFlow(flow) : { nodes: [], edges: [], viewport: { zoom: 1, x: 0, y: 0 } }; - - + // Create a new flow with a default name if no flow is provided. const newFlow = createNewFlow(flowData, flow!); - - + const newName = addVersionToDuplicates(newFlow, flows); - - + newFlow.name = newName; try { const { id } = await saveFlowToDatabase(newFlow); // Change the id to the new id. newFlow.id = id; - - + // Add the new flow to the list of flows. addFlowToLocalState(newFlow); - - + // Return the id return id; } catch (error) { @@ -607,6 +600,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) { } async function saveFlow(newFlow: FlowType, silent?: boolean) { + if (newFlow?.data?.nodes?.length === 0) return; try { // updates flow in db const updatedFlow = await updateFlowInDatabase(newFlow); @@ -652,8 +646,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) { function deleteComponent(key: string) { let componentFlow = flows.find( (componentFlow) => - componentFlow.is_component && - componentFlow.name === key + componentFlow.is_component && componentFlow.name === key ); if (componentFlow) { diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index c5d2dab57..bdc8abfb5 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -252,9 +252,12 @@ export default function ExtraSidebar(): JSX.Element {