From 71945ed9cf762f19c1e4cf3dadcaa5a1d050c449 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 10 Oct 2023 17:08:27 -0300 Subject: [PATCH] fix(typesContext.tsx): update deleteComponent function signature to include id parameter for better data management fix(typesContext.tsx): update deleteComponent implementation to use id parameter for localStorage key fix(sideBarDraggableComponent/index.tsx): update deleteComponent function call to include id parameter for better data management --- src/frontend/src/contexts/typesContext.tsx | 11 ++++++----- .../sideBarDraggableComponent/index.tsx | 4 +++- src/frontend/src/types/typesContext/index.ts | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/contexts/typesContext.tsx b/src/frontend/src/contexts/typesContext.tsx index 9e9de299b..22a92b538 100644 --- a/src/frontend/src/contexts/typesContext.tsx +++ b/src/frontend/src/contexts/typesContext.tsx @@ -37,7 +37,7 @@ const initialValue: typesContextType = { setFilterEdge: (filter) => {}, getFilterEdge: [], saveComponent: (component: NodeDataType, key: string) => {}, - deleteComponent: (key: string) => {}, + deleteComponent: (id: string, key: string) => {}, }; export const typesContext = createContext(initialValue); @@ -159,16 +159,17 @@ export function TypesProvider({ children }: { children: ReactNode }) { }); } - function deleteComponent(key: string) { + function deleteComponent(id: string, key: string) { let savedComponentsJSON: localStorageUserType = { components: {} }; - if (checkLocalStorageKey(userData?.id!)) { - let savedComponents = localStorage.getItem(userData?.id!)!; + if (checkLocalStorageKey(id)) { + let savedComponents = localStorage.getItem(id)!; savedComponentsJSON = JSON.parse(savedComponents); } let components = savedComponentsJSON.components; delete components[key]; savedComponentsJSON.components = components; - localStorage.setItem(userData?.id!, JSON.stringify(savedComponentsJSON)); + console.log(savedComponentsJSON); + localStorage.setItem(id, JSON.stringify(savedComponentsJSON)); setData((prev) => { let newData = _.cloneDeep(prev); //clone to prevent reference erro diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/sideBarDraggableComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/sideBarDraggableComponent/index.tsx index 133d04f56..044fa6b49 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/sideBarDraggableComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/sideBarDraggableComponent/index.tsx @@ -6,6 +6,7 @@ import { SelectItem, SelectTrigger, } from "../../../../../components/ui/select-custom"; +import { AuthContext } from "../../../../../contexts/authContext"; import { TabsContext } from "../../../../../contexts/tabsContext"; import { typesContext } from "../../../../../contexts/typesContext"; import { APIClassType } from "../../../../../types/api"; @@ -35,6 +36,7 @@ export default function SidebarDraggableComponent({ const open = useRef(false); const { deleteComponent } = useContext(typesContext); const { getNodeId } = useContext(TabsContext); + const { autoLogin, userData } = useContext(AuthContext); function handleSelectChange(value: string) { switch (value) { @@ -47,7 +49,7 @@ export default function SidebarDraggableComponent({ ); break; case "delete": - deleteComponent(itemName); + deleteComponent(autoLogin ? "auto" : userData?.id!, itemName); break; } } diff --git a/src/frontend/src/types/typesContext/index.ts b/src/frontend/src/types/typesContext/index.ts index e6c01358b..3f88ae94e 100644 --- a/src/frontend/src/types/typesContext/index.ts +++ b/src/frontend/src/types/typesContext/index.ts @@ -22,7 +22,7 @@ export type typesContextType = { setFilterEdge: (newState) => void; getFilterEdge: any[]; saveComponent: (component: NodeDataType, key: string) => void; - deleteComponent: (key: string) => void; + deleteComponent: (id: string, key: string) => void; }; export type alertContextType = {