running flows from store, still need fixes
This commit is contained in:
parent
089446b1b7
commit
b8a62a3c7b
5 changed files with 37 additions and 16 deletions
|
|
@ -52,6 +52,8 @@ export default function CollectionCardComponent({
|
||||||
data?.downloads_count ?? 0
|
data?.downloads_count ?? 0
|
||||||
);
|
);
|
||||||
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
|
const setCurrentFlow = useFlowsManagerStore((state) => state.setCurrentFlow);
|
||||||
|
const getFlowById = useFlowsManagerStore((state) => state.getFlowById);
|
||||||
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
||||||
const setNodes = useFlowStore((state) => state.setNodes);
|
const setNodes = useFlowStore((state) => state.setNodes);
|
||||||
const setEdges = useFlowStore((state) => state.setEdges);
|
const setEdges = useFlowStore((state) => state.setEdges);
|
||||||
|
|
@ -61,21 +63,16 @@ export default function CollectionCardComponent({
|
||||||
|
|
||||||
const name = data.is_component ? "Component" : "Flow";
|
const name = data.is_component ? "Component" : "Flow";
|
||||||
|
|
||||||
|
async function getFlowData(){
|
||||||
|
const res = await getComponent(data.id)
|
||||||
|
const newFlow = cloneFLowWithParent(res, res.id, data.is_component,true);
|
||||||
|
return newFlow;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentFlowId && playground) {
|
if (currentFlowId && playground) {
|
||||||
console.log(currentFlowId)
|
|
||||||
if(currentFlow){
|
|
||||||
setNodes(currentFlow?.data?.nodes ?? [],true);
|
setNodes(currentFlow?.data?.nodes ?? [],true);
|
||||||
setEdges(currentFlow?.data?.edges ?? [],true);
|
setEdges(currentFlow?.data?.edges ?? [],true);
|
||||||
}
|
|
||||||
else{
|
|
||||||
getComponent(data.id)
|
|
||||||
.then((res) => {
|
|
||||||
const newFlow = cloneFLowWithParent(res, res.id, data.is_component);
|
|
||||||
setNodes(newFlow?.data?.nodes??[]);
|
|
||||||
setEdges(newFlow?.data?.edges??[]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
cleanFlowPool();
|
cleanFlowPool();
|
||||||
}
|
}
|
||||||
}, [currentFlowId]);
|
}, [currentFlowId]);
|
||||||
|
|
@ -385,8 +382,17 @@ export default function CollectionCardComponent({
|
||||||
"playground-flow-button-" + data.id
|
"playground-flow-button-" + data.id
|
||||||
}
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setCurrentFlowId(data.id);
|
if(getFlowById(data.id)){
|
||||||
setOpenPlayground(true);
|
setCurrentFlowId(data.id);
|
||||||
|
setOpenPlayground(true);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
getFlowData().then((res) => {
|
||||||
|
setCurrentFlow(res);
|
||||||
|
setOpenPlayground(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IconComponent
|
<IconComponent
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ export default function ComponentsComponent({
|
||||||
const start = (pageIndex - 1) * pageSize;
|
const start = (pageIndex - 1) * pageSize;
|
||||||
const end = start + pageSize;
|
const end = start + pageSize;
|
||||||
setData(all.slice(start, end));
|
setData(all.slice(start, end));
|
||||||
}, [isLoading, pageIndex, pageSize]);
|
}, [flows,isLoading, pageIndex, pageSize]);
|
||||||
|
|
||||||
const [data, setData] = useState<FlowType[]>([]);
|
const [data, setData] = useState<FlowType[]>([]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,16 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
|
||||||
set({ examples });
|
set({ examples });
|
||||||
},
|
},
|
||||||
currentFlowId: "",
|
currentFlowId: "",
|
||||||
|
setCurrentFlow: (flow: FlowType) => {
|
||||||
|
set((state) => ({
|
||||||
|
currentFlow: flow,
|
||||||
|
currentFlowId: flow.id,
|
||||||
|
}));
|
||||||
|
|
||||||
|
},
|
||||||
|
getFlowById: (id: string) => {
|
||||||
|
return get().flows.find((flow) => flow.id === id);
|
||||||
|
},
|
||||||
setCurrentFlowId: (currentFlowId: string) => {
|
setCurrentFlowId: (currentFlowId: string) => {
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
currentFlowId,
|
currentFlowId,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { Edge, Node, Viewport, XYPosition } from "reactflow";
|
||||||
import { FlowType } from "../../flow";
|
import { FlowType } from "../../flow";
|
||||||
|
|
||||||
export type FlowsManagerStoreType = {
|
export type FlowsManagerStoreType = {
|
||||||
|
getFlowById: (id: string) => FlowType | undefined;
|
||||||
flows: Array<FlowType>;
|
flows: Array<FlowType>;
|
||||||
setFlows: (flows: FlowType[]) => void;
|
setFlows: (flows: FlowType[]) => void;
|
||||||
currentFlow: FlowType | undefined;
|
currentFlow: FlowType | undefined;
|
||||||
|
|
@ -50,6 +51,7 @@ export type FlowsManagerStoreType = {
|
||||||
takeSnapshot: () => void;
|
takeSnapshot: () => void;
|
||||||
examples: Array<FlowType>;
|
examples: Array<FlowType>;
|
||||||
setExamples: (examples: FlowType[]) => void;
|
setExamples: (examples: FlowType[]) => void;
|
||||||
|
setCurrentFlow: (flow: FlowType) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UseUndoRedoOptions = {
|
export type UseUndoRedoOptions = {
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,14 @@ import { isInputNode, isOutputNode } from "./reactflowUtils";
|
||||||
export default function cloneFLowWithParent(
|
export default function cloneFLowWithParent(
|
||||||
flow: FlowType,
|
flow: FlowType,
|
||||||
parent: string,
|
parent: string,
|
||||||
is_component: boolean
|
is_component: boolean,
|
||||||
|
keepId=false
|
||||||
) {
|
) {
|
||||||
let childFLow = cloneDeep(flow);
|
let childFLow = cloneDeep(flow);
|
||||||
childFLow.parent = parent;
|
childFLow.parent = parent;
|
||||||
childFLow.id = "";
|
if(!keepId){
|
||||||
|
childFLow.id = "";
|
||||||
|
}
|
||||||
childFLow.is_component = is_component;
|
childFLow.is_component = is_component;
|
||||||
return childFLow;
|
return childFLow;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue