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.
|
||||
* The resulting JSON object is passed to the addFlow function.
|
||||
*/
|
||||
function uploadFlow() {
|
||||
function uploadFlow(newProject?: boolean) {
|
||||
// create a file input
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
|
|
@ -278,7 +278,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
// parse the text into a JSON object
|
||||
let flow: FlowType = JSON.parse(text);
|
||||
|
||||
addFlow(flow);
|
||||
addFlow(flow, newProject);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -415,30 +415,35 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
reactFlowInstance.setEdges(edges);
|
||||
}
|
||||
|
||||
const addFlow = async (flow?: FlowType): Promise<String> => {
|
||||
let flowData = extractDataFromFlow(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);
|
||||
|
||||
try {
|
||||
const id = await saveFlowToDatabase(newFlow);
|
||||
// Change the id to the new id.
|
||||
newFlow.id = id.id;
|
||||
|
||||
// Add the new flow to the list of flows.
|
||||
addFlowToLocalState(newFlow);
|
||||
|
||||
// Return the id
|
||||
return id.id;
|
||||
} catch (error) {
|
||||
// Handle the error if needed
|
||||
console.error('Error while adding flow:', error);
|
||||
throw error; // Re-throw the error so the caller can handle it if needed
|
||||
const addFlow = async (flow?: FlowType, newProject?: Boolean): Promise<String> => {
|
||||
if(newProject){
|
||||
let flowData = extractDataFromFlow(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);
|
||||
|
||||
try {
|
||||
const id = await saveFlowToDatabase(newFlow);
|
||||
// Change the id to the new id.
|
||||
newFlow.id = id.id;
|
||||
|
||||
// Add the new flow to the list of flows.
|
||||
addFlowToLocalState(newFlow);
|
||||
|
||||
// Return the id
|
||||
return id.id;
|
||||
} catch (error) {
|
||||
// Handle the error 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) => {
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ export default function ImportModal() {
|
|||
<ComputerDesktopIcon className="h-10 w-10 flex-shrink-0" />
|
||||
}
|
||||
onClick={() => {
|
||||
uploadFlow();
|
||||
uploadFlow(false);
|
||||
setModalOpen(false);
|
||||
}}
|
||||
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" />
|
||||
}
|
||||
onClick={() => {
|
||||
addFlow(example);
|
||||
addFlow(example, false);
|
||||
setModalOpen(false);
|
||||
}}
|
||||
textColor="text-emerald-500 dark:text-emerald-500/75"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export type TabsContextType = {
|
|||
setTabId: (index: string) => void;
|
||||
flows: Array<FlowType>;
|
||||
removeFlow: (id: string) => void;
|
||||
addFlow: (flowData?: FlowType, newFlow?: boolean) => Promise<String>;
|
||||
addFlow: (flowData?: FlowType, newProject?: boolean) => Promise<String>;
|
||||
updateFlow: (newFlow: FlowType) => void;
|
||||
incrementNodeId: () => string;
|
||||
downloadFlow: (flow: FlowType) => void;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue