fix(tabsContext.tsx): fix typo in createRandomKey function parameter name from uid to uid()
feat(tabsContext.tsx): add createRandomKey function to generate random keys for custom components refactor(tabsContext.tsx): refactor logic to update storeComponents object with new custom component data refactor(tabsContext.tsx): refactor logic to update newData object with updated custom_components object refactor(tabsContext.tsx): refactor logic to correctly concatenate newFlows array in addFlowToLocalState function refactor(tabsContext.tsx): refactor logic to generate random key for component type in updateComponentType function feat(utils.ts): add createRandomKey function to generate random keys for components
This commit is contained in:
parent
cbbfa3517f
commit
6d5c803c17
2 changed files with 21 additions and 8 deletions
|
|
@ -40,6 +40,7 @@ import {
|
||||||
updateTemplate,
|
updateTemplate,
|
||||||
} from "../utils/reactflowUtils";
|
} from "../utils/reactflowUtils";
|
||||||
import {
|
import {
|
||||||
|
createRandomKey,
|
||||||
getRandomDescription,
|
getRandomDescription,
|
||||||
getRandomName,
|
getRandomName,
|
||||||
getSetFromObject,
|
getSetFromObject,
|
||||||
|
|
@ -153,9 +154,14 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (flow.data && flow.is_component) {
|
if (flow.data && flow.is_component) {
|
||||||
console.log(flow.data.nodes[0].data);
|
(flow.data.nodes[0].data as NodeDataType).node!.display_name =
|
||||||
storeComponents[(flow.data.nodes[0].data as NodeDataType).type] =
|
flow.name;
|
||||||
_.cloneDeep((flow.data.nodes[0].data as NodeDataType).node!);
|
storeComponents[
|
||||||
|
createRandomKey(
|
||||||
|
(flow.data.nodes[0].data as NodeDataType).type,
|
||||||
|
uid()
|
||||||
|
)
|
||||||
|
] = _.cloneDeep((flow.data.nodes[0].data as NodeDataType).node!);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!skipUpdate) processDataFromFlow(flow, false);
|
if (!skipUpdate) processDataFromFlow(flow, false);
|
||||||
|
|
@ -165,9 +171,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
});
|
});
|
||||||
setData((prev) => {
|
setData((prev) => {
|
||||||
let newData = _.cloneDeep(prev);
|
let newData = _.cloneDeep(prev);
|
||||||
Object.keys(storeComponents).forEach((key) => {
|
console.log(newData["custom_components"]);
|
||||||
newData["custom_components"][key] = storeComponents[key];
|
console.log(storeComponents);
|
||||||
});
|
const customComponent = newData["custom_components"]["CustomComponent"];
|
||||||
|
newData["custom_components"] = cloneDeep(storeComponents);
|
||||||
|
newData["custom_components"]["CustomComponent"] = customComponent;
|
||||||
|
console.log(newData["custom_components"]);
|
||||||
return newData;
|
return newData;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -608,7 +617,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
const addFlowToLocalState = (newFlow: FlowType) => {
|
const addFlowToLocalState = (newFlow: FlowType) => {
|
||||||
let newFlows: FlowType[] = [];
|
let newFlows: FlowType[] = [];
|
||||||
setFlows((prevState) => {
|
setFlows((prevState) => {
|
||||||
newFlows.concat(prevState);
|
newFlows = newFlows.concat(prevState);
|
||||||
newFlows.push(newFlow);
|
newFlows.push(newFlow);
|
||||||
return [...prevState, newFlow];
|
return [...prevState, newFlow];
|
||||||
});
|
});
|
||||||
|
|
@ -675,7 +684,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
let key = component.type;
|
let key = component.type;
|
||||||
if (data["custom_components"][key] !== undefined) {
|
if (data["custom_components"][key] !== undefined) {
|
||||||
let increment: number;
|
let increment: number;
|
||||||
component.type = removeCountFromString(key) + ` (${uid()})`;
|
component.type = createRandomKey(key, uid());
|
||||||
let componentNodes: { [key: string]: APIClassType } = {};
|
let componentNodes: { [key: string]: APIClassType } = {};
|
||||||
Object.keys(data["custom_components"]).forEach((key) => {
|
Object.keys(data["custom_components"]).forEach((key) => {
|
||||||
componentNodes[key] = data["custom_components"][key];
|
componentNodes[key] = data["custom_components"][key];
|
||||||
|
|
|
||||||
|
|
@ -579,6 +579,10 @@ export function removeCountFromString(input: string): string {
|
||||||
return result.trim(); // Trim any leading/trailing spaces
|
return result.trim(); // Trim any leading/trailing spaces
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createRandomKey(key: string, uid: string): string {
|
||||||
|
return removeCountFromString(key) + ` (${uid})`;
|
||||||
|
}
|
||||||
|
|
||||||
export function sensitiveSort(a: string, b: string): number {
|
export function sensitiveSort(a: string, b: string): number {
|
||||||
// Extract the name and number from each string using regular expressions
|
// Extract the name and number from each string using regular expressions
|
||||||
const regex = /(.+) \((\w+)\)/;
|
const regex = /(.+) \((\w+)\)/;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue