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,
|
||||
} from "../utils/reactflowUtils";
|
||||
import {
|
||||
createRandomKey,
|
||||
getRandomDescription,
|
||||
getRandomName,
|
||||
getSetFromObject,
|
||||
|
|
@ -153,9 +154,14 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
return;
|
||||
}
|
||||
if (flow.data && flow.is_component) {
|
||||
console.log(flow.data.nodes[0].data);
|
||||
storeComponents[(flow.data.nodes[0].data as NodeDataType).type] =
|
||||
_.cloneDeep((flow.data.nodes[0].data as NodeDataType).node!);
|
||||
(flow.data.nodes[0].data as NodeDataType).node!.display_name =
|
||||
flow.name;
|
||||
storeComponents[
|
||||
createRandomKey(
|
||||
(flow.data.nodes[0].data as NodeDataType).type,
|
||||
uid()
|
||||
)
|
||||
] = _.cloneDeep((flow.data.nodes[0].data as NodeDataType).node!);
|
||||
return;
|
||||
}
|
||||
if (!skipUpdate) processDataFromFlow(flow, false);
|
||||
|
|
@ -165,9 +171,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
});
|
||||
setData((prev) => {
|
||||
let newData = _.cloneDeep(prev);
|
||||
Object.keys(storeComponents).forEach((key) => {
|
||||
newData["custom_components"][key] = storeComponents[key];
|
||||
});
|
||||
console.log(newData["custom_components"]);
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
|
@ -608,7 +617,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
const addFlowToLocalState = (newFlow: FlowType) => {
|
||||
let newFlows: FlowType[] = [];
|
||||
setFlows((prevState) => {
|
||||
newFlows.concat(prevState);
|
||||
newFlows = newFlows.concat(prevState);
|
||||
newFlows.push(newFlow);
|
||||
return [...prevState, newFlow];
|
||||
});
|
||||
|
|
@ -675,7 +684,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
let key = component.type;
|
||||
if (data["custom_components"][key] !== undefined) {
|
||||
let increment: number;
|
||||
component.type = removeCountFromString(key) + ` (${uid()})`;
|
||||
component.type = createRandomKey(key, uid());
|
||||
let componentNodes: { [key: string]: APIClassType } = {};
|
||||
Object.keys(data["custom_components"]).forEach((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
|
||||
}
|
||||
|
||||
export function createRandomKey(key: string, uid: string): string {
|
||||
return removeCountFromString(key) + ` (${uid})`;
|
||||
}
|
||||
|
||||
export function sensitiveSort(a: string, b: string): number {
|
||||
// Extract the name and number from each string using regular expressions
|
||||
const regex = /(.+) \((\w+)\)/;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue