refactor(tabsContext.tsx): simplify code in TabsProvider component
The changes in this commit simplify the code in the TabsProvider component in the tabsContext.tsx file. Here's a summary of the changes:
- In the `createNewFlow` function, the `flowData` parameter is now of type `ReactFlowJsonObject | null` instead of `{ data: ReactFlowJsonObject | null; description: string }`. This simplifies the function signature and removes the need for destructuring the `flowData` object.
- The `extractDataFromFlow` function has been renamed to `processDataFromFlow` to better reflect its purpose. The function now returns only the `data` property from the `flow` object instead of an object with `data` and `description` properties.
- The `description` property in the `createNewFlow` function is now set to `flow.description ?? getRandomDescription()`. This ensures that if the `flow` object has a `description` property, it is used, otherwise a random description is generated.
- The `processFlowEdges` and `processFlowNodes` functions are no longer called in the `createNewFlow` function. It seems that these functions are defined elsewhere and are not necessary in this context.
These changes simplify the code and improve readability by removing unnecessary checks and simplifying function signatures.
This commit is contained in:
parent
577046523a
commit
bf1597a9f4
1 changed files with 8 additions and 12 deletions
|
|
@ -490,15 +490,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
flow?: FlowType
|
||||
): Promise<String | undefined> => {
|
||||
if (newProject) {
|
||||
let flowData = extractDataFromFlow(flow!);
|
||||
if (flowData.description == "") {
|
||||
flowData.description = getRandomDescription();
|
||||
}
|
||||
let flowData = flow
|
||||
? processDataFromFlow(flow)
|
||||
: { nodes: [], edges: [], viewport: { zoom: 1, x: 0, y: 0 } };
|
||||
|
||||
// Create a new flow with a default name if no flow is provided.
|
||||
const newFlow = createNewFlow(flowData, flow!);
|
||||
processFlowEdges(newFlow);
|
||||
processFlowNodes(newFlow);
|
||||
|
||||
const flowName = addVersionToDuplicates(newFlow, flows);
|
||||
|
||||
|
|
@ -526,9 +523,8 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
}
|
||||
};
|
||||
|
||||
const extractDataFromFlow = (flow: FlowType) => {
|
||||
const processDataFromFlow = (flow: FlowType) => {
|
||||
let data = flow?.data ? flow.data : null;
|
||||
const description = flow?.description ? flow.description : "";
|
||||
if (data) {
|
||||
processFlowEdges(flow);
|
||||
processFlowNodes(flow);
|
||||
|
|
@ -537,7 +533,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
updateIds(data, getNodeId); // Assuming updateIds is defined elsewhere
|
||||
}
|
||||
|
||||
return { data, description };
|
||||
return data;
|
||||
};
|
||||
|
||||
const updateEdges = (edges: Edge[]) => {
|
||||
|
|
@ -584,12 +580,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
};
|
||||
|
||||
const createNewFlow = (
|
||||
flowData: { data: ReactFlowJsonObject | null; description: string },
|
||||
flowData: ReactFlowJsonObject | null,
|
||||
flow: FlowType
|
||||
) => ({
|
||||
description: flowData.description,
|
||||
description: flow.description ?? getRandomDescription(),
|
||||
name: flow?.name ?? getRandomName(),
|
||||
data: flowData.data,
|
||||
data: flowData,
|
||||
id: "",
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue