almost perfect not sending edges and node because of http web method

This commit is contained in:
anovazzi1 2024-04-25 00:10:21 -03:00
commit 257e18cf5e
8 changed files with 48 additions and 11 deletions

View file

@ -58,7 +58,6 @@ export default function CollectionCardComponent({
const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId); const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId);
const name = data.is_component ? "Component" : "Flow"; const name = data.is_component ? "Component" : "Flow";
useEffect(() => { useEffect(() => {
@ -382,7 +381,7 @@ export default function CollectionCardComponent({
className="main-page-nav-button select-none" className="main-page-nav-button select-none"
/> />
Playground Playground
{openPlayground && < IOModal open={openPlayground} setOpen={setOpenPlayground}> {openPlayground && < IOModal cleanOnClose={true} open={openPlayground} setOpen={setOpenPlayground}>
<></> <></>
</IOModal>} </IOModal>}
</Button> </Button>

View file

@ -1,5 +1,5 @@
import { AxiosResponse } from "axios"; import { AxiosRequestConfig, AxiosResponse } from "axios";
import { ReactFlowJsonObject } from "reactflow"; import { Edge, ReactFlowJsonObject,Node } from "reactflow";
import { BASE_URL_API } from "../../constants/constants"; import { BASE_URL_API } from "../../constants/constants";
import { api } from "../../controllers/API/api"; import { api } from "../../controllers/API/api";
import { import {
@ -906,16 +906,21 @@ export async function updateGlobalVariable(
export async function getVerticesOrder( export async function getVerticesOrder(
flowId: string, flowId: string,
startNodeId?: string | null, startNodeId?: string | null,
stopNodeId?: string | null stopNodeId?: string | null,
nodes?:Node[],
Edges?:Edge[]
): Promise<AxiosResponse<VerticesOrderTypeAPI>> { ): Promise<AxiosResponse<VerticesOrderTypeAPI>> {
// nodeId is optional and is a query parameter // nodeId is optional and is a query parameter
// if nodeId is not provided, the API will return all vertices // if nodeId is not provided, the API will return all vertices
const config = {}; const config:AxiosRequestConfig<any> = {};
if (stopNodeId) { if (stopNodeId) {
config["params"] = { stop_component_id: stopNodeId }; config["params"] = { stop_component_id: stopNodeId };
} else if (startNodeId) { } else if (startNodeId) {
config["params"] = { start_component_id: startNodeId }; config["params"] = { start_component_id: startNodeId };
} }
if(nodes && Edges){
config.data = {nodes,Edges}
}
return await api.get(`${BASE_URL_API}build/${flowId}/vertices`, config); return await api.get(`${BASE_URL_API}build/${flowId}/vertices`, config);
} }

View file

@ -31,8 +31,10 @@ export default function IOModal({
open, open,
setOpen, setOpen,
disable, disable,
cleanOnClose=false,
}: IOModalPropsType): JSX.Element { }: IOModalPropsType): JSX.Element {
const allNodes = useFlowStore((state) => state.nodes); const allNodes = useFlowStore((state) => state.nodes);
const cleanFlowPool = useFlowStore((state) => state.CleanFlowPool);
const inputs = useFlowStore((state) => state.inputs).filter( const inputs = useFlowStore((state) => state.inputs).filter(
(input) => input.type !== "ChatInput" (input) => input.type !== "ChatInput"
); );
@ -127,6 +129,13 @@ export default function IOModal({
open={open} open={open}
setOpen={setOpen} setOpen={setOpen}
disable={disable} disable={disable}
onChangeOpenModal={(open)=>{
if(!open && cleanOnClose){
console.log("cleaning flow pool")
cleanFlowPool();
}
}}
> >
<BaseModal.Trigger>{children}</BaseModal.Trigger> <BaseModal.Trigger>{children}</BaseModal.Trigger>
{/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */} {/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */}

View file

@ -6,18 +6,25 @@ import { useDarkStore } from "../../stores/darkStore";
import useFlowsManagerStore from "../../stores/flowsManagerStore"; import useFlowsManagerStore from "../../stores/flowsManagerStore";
import Page from "./components/PageComponent"; import Page from "./components/PageComponent";
import ExtraSidebar from "./components/extraSidebarComponent"; import ExtraSidebar from "./components/extraSidebarComponent";
import useFlowStore from "../../stores/flowStore";
export default function FlowPage({ view }: { view?: boolean }): JSX.Element { export default function FlowPage({ view }: { view?: boolean }): JSX.Element {
const setCurrentFlowId = useFlowsManagerStore( const setCurrentFlowId = useFlowsManagerStore(
(state) => state.setCurrentFlowId (state) => state.setCurrentFlowId
); );
const version = useDarkStore((state) => state.version); const version = useDarkStore((state) => state.version);
const setOnFlowPage = useFlowStore((state) => state.setOnFlowPage);
const currentFlow = useFlowsManagerStore((state) => state.currentFlow); const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
const { id } = useParams(); const { id } = useParams();
// Set flow tab id // Set flow tab id
useEffect(() => { useEffect(() => {
setCurrentFlowId(id!); setCurrentFlowId(id!);
setOnFlowPage(true);
return () => {
setOnFlowPage(false);
};
}, [id]); }, [id]);
return ( return (
<> <>

View file

@ -44,9 +44,12 @@ import { getInputsAndOutputs } from "../utils/storeUtils";
import useAlertStore from "./alertStore"; import useAlertStore from "./alertStore";
import { useDarkStore } from "./darkStore"; import { useDarkStore } from "./darkStore";
import useFlowsManagerStore from "./flowsManagerStore"; import useFlowsManagerStore from "./flowsManagerStore";
import FlowPage from "../pages/FlowPage";
// this is our useStore hook that we can use in our components to get parts of the store and call actions // this is our useStore hook that we can use in our components to get parts of the store and call actions
const useFlowStore = create<FlowStoreType>((set, get) => ({ const useFlowStore = create<FlowStoreType>((set, get) => ({
onFlowPage: false,
setOnFlowPage:(FlowPage=>set({onFlowPage:FlowPage})),
flowState: undefined, flowState: undefined,
flowBuildStatus: {}, flowBuildStatus: {},
nodes: [], nodes: [],
@ -164,7 +167,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
}); });
const flowsManager = useFlowsManagerStore.getState(); const flowsManager = useFlowsManagerStore.getState();
if (!get().isBuilding && !skipSave) { if (!get().isBuilding && !skipSave && get().onFlowPage) {
flowsManager.autoSaveCurrentFlow( flowsManager.autoSaveCurrentFlow(
newChange, newChange,
newEdges, newEdges,
@ -180,7 +183,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
}); });
const flowsManager = useFlowsManagerStore.getState(); const flowsManager = useFlowsManagerStore.getState();
if (!get().isBuilding && !skipSave) { if (!get().isBuilding && !skipSave && get().onFlowPage) {
flowsManager.autoSaveCurrentFlow( flowsManager.autoSaveCurrentFlow(
get().nodes, get().nodes,
newChange, newChange,
@ -560,6 +563,8 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING); useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING);
}, },
onValidateNodes: validateSubgraph, onValidateNodes: validateSubgraph,
nodes: !get().onFlowPage ? get().nodes : undefined,
edges: !get().onFlowPage ? get().edges : undefined,
}); });
get().setIsBuilding(false); get().setIsBuilding(false);
get().revertBuiltStatusFromBuilding(); get().revertBuiltStatusFromBuilding();

View file

@ -594,6 +594,7 @@ export type IOModalPropsType = {
setOpen: (open: boolean) => void; setOpen: (open: boolean) => void;
disable?: boolean; disable?: boolean;
isPlayground?: boolean; isPlayground?: boolean;
cleanOnClose?: boolean;
}; };
export type buttonBoxPropsType = { export type buttonBoxPropsType = {

View file

@ -45,6 +45,8 @@ export type FlowPoolType = {
}; };
export type FlowStoreType = { export type FlowStoreType = {
onFlowPage: boolean;
setOnFlowPage: (onFlowPage: boolean) => void;
flowPool: FlowPoolType; flowPool: FlowPoolType;
inputs: Array<{ type: string; id: string; displayName: string }>; inputs: Array<{ type: string; id: string; displayName: string }>;
outputs: Array<{ type: string; id: string; displayName: string }>; outputs: Array<{ type: string; id: string; displayName: string }>;

View file

@ -5,6 +5,7 @@ import useAlertStore from "../stores/alertStore";
import useFlowStore from "../stores/flowStore"; import useFlowStore from "../stores/flowStore";
import { VertexBuildTypeAPI } from "../types/api"; import { VertexBuildTypeAPI } from "../types/api";
import { VertexLayerElementType } from "../types/zustand/flow"; import { VertexLayerElementType } from "../types/zustand/flow";
import { Edge, Node } from "reactflow";
type BuildVerticesParams = { type BuildVerticesParams = {
flowId: string; // Assuming FlowType is the type for your flow flowId: string; // Assuming FlowType is the type for your flow
@ -21,6 +22,8 @@ type BuildVerticesParams = {
onBuildError?: (title, list, idList: VertexLayerElementType[]) => void; onBuildError?: (title, list, idList: VertexLayerElementType[]) => void;
onBuildStart?: (idList: VertexLayerElementType[]) => void; onBuildStart?: (idList: VertexLayerElementType[]) => void;
onValidateNodes?: (nodes: string[]) => void; onValidateNodes?: (nodes: string[]) => void;
nodes?: Node[];
edges?: Edge[];
}; };
function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI { function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
@ -48,7 +51,9 @@ function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
export async function updateVerticesOrder( export async function updateVerticesOrder(
flowId: string, flowId: string,
startNodeId?: string | null, startNodeId?: string | null,
stopNodeId?: string | null stopNodeId?: string | null,
nodes?:Node[],
edges?:Edge[]
): Promise<{ ): Promise<{
verticesLayers: VertexLayerElementType[][]; verticesLayers: VertexLayerElementType[][];
verticesIds: string[]; verticesIds: string[];
@ -59,7 +64,7 @@ export async function updateVerticesOrder(
const setErrorData = useAlertStore.getState().setErrorData; const setErrorData = useAlertStore.getState().setErrorData;
let orderResponse; let orderResponse;
try { try {
orderResponse = await getVerticesOrder(flowId, startNodeId, stopNodeId); orderResponse = await getVerticesOrder(flowId, startNodeId, stopNodeId, nodes, edges);
} catch (error: any) { } catch (error: any) {
setErrorData({ setErrorData({
title: "Oops! Looks like you missed something", title: "Oops! Looks like you missed something",
@ -101,6 +106,8 @@ export async function buildVertices({
onBuildError, onBuildError,
onBuildStart, onBuildStart,
onValidateNodes, onValidateNodes,
nodes,
edges,
}: BuildVerticesParams) { }: BuildVerticesParams) {
let verticesBuild = useFlowStore.getState().verticesBuild; let verticesBuild = useFlowStore.getState().verticesBuild;
// if startNodeId and stopNodeId are provided // if startNodeId and stopNodeId are provided
@ -113,7 +120,9 @@ export async function buildVertices({
let verticesOrderResponse = await updateVerticesOrder( let verticesOrderResponse = await updateVerticesOrder(
flowId, flowId,
startNodeId, startNodeId,
stopNodeId stopNodeId,
nodes,
edges
); );
if (onValidateNodes) { if (onValidateNodes) {
try { try {