fix(API): update return type of getFlowPool function to match the actual response structure

fix(EditNodeModal): remove unused setPending function call

fix(PageComponent): remove unused setFlowPool and setLoading state variables

fix(flowStore): remove unused import and updateFlowInDatabase function call, add logic to fetch flowPool data when resetting flow
This commit is contained in:
anovazzi1 2024-01-31 17:03:51 -03:00
commit 9726defa33
4 changed files with 9 additions and 26 deletions

View file

@ -877,7 +877,7 @@ export async function getFlowPool({
}: {
flowId: string;
nodeId?: string;
}): Promise<AxiosResponse<FlowPoolType>> {
}): Promise<AxiosResponse<{ vertex_builds: FlowPoolType }>> {
const config = {};
config["params"] = { flow_id: flowId };
if (nodeId) {

View file

@ -56,7 +56,6 @@ const EditNodeModal = forwardRef(
) => {
const [myData, setMyData] = useState(data);
const setPending = useFlowStore((state) => state.setPending);
const edges = useFlowStore((state) => state.edges);
const setNode = useFlowStore((state) => state.setNode);
@ -546,7 +545,6 @@ const EditNodeModal = forwardRef(
node: myData.node,
},
}));
setPending(true);
setOpen(false);
}}
type="submit"

View file

@ -69,7 +69,6 @@ export default function Page({
const takeSnapshot = useFlowsManagerStore((state) => state.takeSnapshot);
const paste = useFlowStore((state) => state.paste);
const resetFlow = useFlowStore((state) => state.resetFlow);
const setFlowPool = useFlowStore((state) => state.setFlowPool);
const lastCopiedSelection = useFlowStore(
(state) => state.lastCopiedSelection
);
@ -80,7 +79,6 @@ export default function Page({
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
const setErrorData = useAlertStore((state) => state.setErrorData);
const [selectionMenuVisible, setSelectionMenuVisible] = useState(false);
const [loading, setLoading] = useState(true);
const edgeUpdateSuccessful = useRef(true);
const position = useRef({ x: 0, y: 0 });
@ -164,12 +162,8 @@ export default function Page({
edges: flow?.data?.edges ?? [],
viewport: flow?.data?.viewport ?? { zoom: 1, x: 0, y: 0 },
});
// getFlowPool({flowId: currentFlowId}).then((flowPool) => {
// setFlowPool(flowPool.data)
// setLoading(false)
// })
}
}, [currentFlowId, reactFlowInstance, setLoading, setFlowPool]);
}, [currentFlowId, reactFlowInstance]);
useEffect(() => {
return () => {

View file

@ -9,7 +9,7 @@ import {
applyNodeChanges,
} from "reactflow";
import { create } from "zustand";
import { updateFlowInDatabase } from "../controllers/API";
import { getFlowPool, updateFlowInDatabase } from "../controllers/API";
import {
NodeDataType,
NodeType,
@ -35,7 +35,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
nodes: [],
edges: [],
isBuilding: false,
isPending: false,
isPending: true,
hasIO: false,
reactFlowInstance: null,
lastCopiedSelection: null,
@ -46,19 +46,12 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
set({ flowPool });
},
addDataToFlowPool: (data: any, nodeId: string) => {
const currentFlow = useFlowsManagerStore.getState().currentFlow;
let newFlowPool = cloneDeep({ ...get().flowPool });
if (!newFlowPool[nodeId]) newFlowPool[nodeId] = [data];
else {
newFlowPool[nodeId].push(data);
}
get().setFlowPool(newFlowPool);
if (currentFlow) {
window.sessionStorage.setItem(
`${currentFlow!.id}`,
JSON.stringify(newFlowPool)
);
}
},
CleanFlowPool: () => {
get().setFlowPool({});
@ -68,12 +61,6 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
},
resetFlow: ({ nodes, edges, viewport }) => {
const currentFlow = useFlowsManagerStore.getState().currentFlow;
let flowPool = {};
if (currentFlow) {
flowPool = JSON.parse(
window.sessionStorage.getItem(`${currentFlow!.id}`) ?? "{}"
);
}
let newEdges = cleanEdges(nodes, edges);
const { inputs, outputs } = getInputsAndOutputs(nodes);
set({
@ -83,9 +70,13 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
inputs,
outputs,
hasIO: inputs.length > 0 || outputs.length > 0,
flowPool,
});
get().reactFlowInstance!.setViewport(viewport);
if (currentFlow) {
getFlowPool({ flowId: currentFlow.id }).then((flowPool) => {
set({ flowPool: flowPool.data.vertex_builds });
});
}
},
setIsBuilding: (isBuilding) => {
set({ isBuilding });