fix(tabsContext.tsx): change return type of saveComponent function to Promise<String | undefined> for better error handling and consistency

fix(nodeToolbarComponent/index.tsx): fix saveComponent function call to return a Promise and handle success and error cases properly
fix(types/tabs/index.ts): change return type of saveComponent function to void for consistency with implementation
feat(reactflowUtils.ts): add updateComponentNameAndType function to update component name and type
This commit is contained in:
anovazzi1 2023-10-25 18:31:06 -03:00
commit a718ac2f4b
4 changed files with 23 additions and 18 deletions

View file

@ -80,7 +80,7 @@ const TabsContextInitialValue: TabsContextType = {
selection: { nodes: any; edges: any }, selection: { nodes: any; edges: any },
position: { x: number; y: number; paneX?: number; paneY?: number } position: { x: number; y: number; paneX?: number; paneY?: number }
) => {}, ) => {},
saveComponent: (component: NodeDataType) => {}, saveComponent: async (component: NodeDataType) => "",
deleteComponent: (id: string, key: string) => {}, deleteComponent: (id: string, key: string) => {},
}; };
@ -700,7 +700,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
` (${increment})`; ` (${increment})`;
} }
} }
addFlow(true, createFlowComponent(component)); return addFlow(true, createFlowComponent(component));
} }
function deleteComponent(id: string, key: string) { function deleteComponent(id: string, key: string) {

View file

@ -70,20 +70,21 @@ export default function NodeToolbarComponent({
function handleShareComponent() { function handleShareComponent() {
const componentFlow = cloneDeep(data); const componentFlow = cloneDeep(data);
saveFlowStore(createFlowComponent(componentFlow)).then( saveComponent(componentFlow).then(() => {
() => { saveFlowStore(createFlowComponent(componentFlow)).then(
saveComponent(componentFlow); (_) => {
setSuccessData({ setSuccessData({
title: "Component shared successfully", title: "Component shared successfully",
}); });
}, },
(err) => { (err) => {
setErrorData({ setErrorData({
title: "Error sharing component", title: "Error sharing component",
list: [err["response"]["data"]["detail"]], list: [err["response"]["data"]["detail"]],
}); });
} }
); );
});
} }
const handleSelectChange = (event) => { const handleSelectChange = (event) => {
switch (event) { switch (event) {
@ -98,7 +99,6 @@ export default function NodeToolbarComponent({
downloadNode(createFlowComponent(cloneDeep(data))); downloadNode(createFlowComponent(cloneDeep(data)));
break; break;
case "Share": case "Share":
console.log("Share");
setShowconfirmShare(true); setShowconfirmShare(true);
break; break;
case "SaveAll": case "SaveAll":

View file

@ -36,7 +36,7 @@ export type TabsContextType = {
setLastCopiedSelection: (selection: { nodes: any; edges: any }) => void; setLastCopiedSelection: (selection: { nodes: any; edges: any }) => void;
setTweak: (tweak: tweakType) => tweakType | void; setTweak: (tweak: tweakType) => tweakType | void;
getTweak: tweakType; getTweak: tweakType;
saveComponent: (component: NodeDataType) => void; saveComponent: (component: NodeDataType) => Promise<String | undefined>;
deleteComponent: (id: string, key: string) => void; deleteComponent: (id: string, key: string) => void;
}; };

View file

@ -1097,3 +1097,8 @@ export function downloadNode(NodeFLow: FlowType) {
element.download = `${NodeFLow.name}.json`; element.download = `${NodeFLow.name}.json`;
element.click(); element.click();
} }
export function updateComponentNameAndType(
data: any,
component: NodeDataType
) {}