Added importing flow to the same flow
This commit is contained in:
parent
97645884ab
commit
bc254a8aee
3 changed files with 33 additions and 28 deletions
|
|
@ -263,7 +263,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
* If the file type is application/json, the file is read and parsed into a JSON object.
|
* If the file type is application/json, the file is read and parsed into a JSON object.
|
||||||
* The resulting JSON object is passed to the addFlow function.
|
* The resulting JSON object is passed to the addFlow function.
|
||||||
*/
|
*/
|
||||||
function uploadFlow() {
|
function uploadFlow(newProject?: boolean) {
|
||||||
// create a file input
|
// create a file input
|
||||||
const input = document.createElement("input");
|
const input = document.createElement("input");
|
||||||
input.type = "file";
|
input.type = "file";
|
||||||
|
|
@ -278,7 +278,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
// parse the text into a JSON object
|
// parse the text into a JSON object
|
||||||
let flow: FlowType = JSON.parse(text);
|
let flow: FlowType = JSON.parse(text);
|
||||||
|
|
||||||
addFlow(flow);
|
addFlow(flow, newProject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -415,30 +415,35 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
reactFlowInstance.setEdges(edges);
|
reactFlowInstance.setEdges(edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
const addFlow = async (flow?: FlowType): Promise<String> => {
|
const addFlow = async (flow?: FlowType, newProject?: Boolean): Promise<String> => {
|
||||||
let flowData = extractDataFromFlow(flow);
|
if(newProject){
|
||||||
if(flowData.description == ""){
|
let flowData = extractDataFromFlow(flow);
|
||||||
flowData.description = "This is a new flow.";
|
if(flowData.description == ""){
|
||||||
}
|
flowData.description = "This is a new flow.";
|
||||||
|
}
|
||||||
// Create a new flow with a default name if no flow is provided.
|
|
||||||
const newFlow = createNewFlow(flowData, flow);
|
// Create a new flow with a default name if no flow is provided.
|
||||||
|
const newFlow = createNewFlow(flowData, flow);
|
||||||
try {
|
|
||||||
const id = await saveFlowToDatabase(newFlow);
|
try {
|
||||||
// Change the id to the new id.
|
const id = await saveFlowToDatabase(newFlow);
|
||||||
newFlow.id = id.id;
|
// Change the id to the new id.
|
||||||
|
newFlow.id = id.id;
|
||||||
// Add the new flow to the list of flows.
|
|
||||||
addFlowToLocalState(newFlow);
|
// Add the new flow to the list of flows.
|
||||||
|
addFlowToLocalState(newFlow);
|
||||||
// Return the id
|
|
||||||
return id.id;
|
// Return the id
|
||||||
} catch (error) {
|
return id.id;
|
||||||
// Handle the error if needed
|
} catch (error) {
|
||||||
console.error('Error while adding flow:', error);
|
// Handle the error if needed
|
||||||
throw error; // Re-throw the error so the caller can handle it if needed
|
console.error('Error while adding flow:', error);
|
||||||
|
throw error; // Re-throw the error so the caller can handle it if needed
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
paste({nodes: flow.data.nodes, edges: flow.data.edges}, {x:10, y:10})
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractDataFromFlow = (flow) => {
|
const extractDataFromFlow = (flow) => {
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ export default function ImportModal() {
|
||||||
<ComputerDesktopIcon className="h-10 w-10 flex-shrink-0" />
|
<ComputerDesktopIcon className="h-10 w-10 flex-shrink-0" />
|
||||||
}
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
uploadFlow();
|
uploadFlow(false);
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
}}
|
}}
|
||||||
textColor="text-blue-500 dark:text-blue-500/75"
|
textColor="text-blue-500 dark:text-blue-500/75"
|
||||||
|
|
@ -189,7 +189,7 @@ export default function ImportModal() {
|
||||||
<DocumentDuplicateIcon className="h-6 w-6 flex-shrink-0" />
|
<DocumentDuplicateIcon className="h-6 w-6 flex-shrink-0" />
|
||||||
}
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
addFlow(example);
|
addFlow(example, false);
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
}}
|
}}
|
||||||
textColor="text-emerald-500 dark:text-emerald-500/75"
|
textColor="text-emerald-500 dark:text-emerald-500/75"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ export type TabsContextType = {
|
||||||
setTabId: (index: string) => void;
|
setTabId: (index: string) => void;
|
||||||
flows: Array<FlowType>;
|
flows: Array<FlowType>;
|
||||||
removeFlow: (id: string) => void;
|
removeFlow: (id: string) => void;
|
||||||
addFlow: (flowData?: FlowType, newFlow?: boolean) => Promise<String>;
|
addFlow: (flowData?: FlowType, newProject?: boolean) => Promise<String>;
|
||||||
updateFlow: (newFlow: FlowType) => void;
|
updateFlow: (newFlow: FlowType) => void;
|
||||||
incrementNodeId: () => string;
|
incrementNodeId: () => string;
|
||||||
downloadFlow: (flow: FlowType) => void;
|
downloadFlow: (flow: FlowType) => void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue