diff --git a/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx b/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx index 8d67a8250b..f8ec103336 100644 --- a/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx +++ b/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx @@ -1,5 +1,4 @@ import { Row } from 'antd'; -import { useDashboardVariablesFromLocalStorage } from 'hooks/dashboard/useDashboardFromLocalStorage'; import { useDashboard } from 'providers/Dashboard/Dashboard'; import { memo, useEffect, useState } from 'react'; import { IDashboardVariable } from 'types/api/dashboard/getAll'; @@ -11,12 +10,8 @@ function DashboardVariableSelection(): JSX.Element | null { const { selectedDashboard, setSelectedDashboard, - dashboardId, - } = useDashboard(); - - const { updateLocalStorageDashboardVariables, - } = useDashboardVariablesFromLocalStorage(dashboardId); + } = useDashboard(); const { data } = selectedDashboard || {}; diff --git a/frontend/src/providers/Dashboard/Dashboard.tsx b/frontend/src/providers/Dashboard/Dashboard.tsx index a7fa94c044..326a4aae83 100644 --- a/frontend/src/providers/Dashboard/Dashboard.tsx +++ b/frontend/src/providers/Dashboard/Dashboard.tsx @@ -52,6 +52,7 @@ const DashboardContext = createContext({ updatedTimeRef: {} as React.MutableRefObject, toScrollWidgetId: '', setToScrollWidgetId: () => {}, + updateLocalStorageDashboardVariables: () => {}, }); interface Props { @@ -96,9 +97,10 @@ export function DashboardProvider({ const [selectedDashboard, setSelectedDashboard] = useState(); - const { currentDashboard } = useDashboardVariablesFromLocalStorage( - dashboardId, - ); + const { + currentDashboard, + updateLocalStorageDashboardVariables, + } = useDashboardVariablesFromLocalStorage(dashboardId); const updatedTimeRef = useRef(null); // Using ref to store the updated time const modalRef = useRef(null); @@ -320,6 +322,7 @@ export function DashboardProvider({ setSelectedDashboard, updatedTimeRef, setToScrollWidgetId, + updateLocalStorageDashboardVariables, }), // eslint-disable-next-line react-hooks/exhaustive-deps [ @@ -330,6 +333,8 @@ export function DashboardProvider({ dashboardId, layouts, toScrollWidgetId, + updateLocalStorageDashboardVariables, + currentDashboard, ], ); diff --git a/frontend/src/providers/Dashboard/types.ts b/frontend/src/providers/Dashboard/types.ts index a8e249015e..1f171cb621 100644 --- a/frontend/src/providers/Dashboard/types.ts +++ b/frontend/src/providers/Dashboard/types.ts @@ -19,4 +19,15 @@ export interface IDashboardContext { updatedTimeRef: React.MutableRefObject; toScrollWidgetId: string; setToScrollWidgetId: React.Dispatch>; + updateLocalStorageDashboardVariables: ( + id: string, + selectedValue: + | string + | number + | boolean + | (string | number | boolean)[] + | null + | undefined, + allSelected: boolean, + ) => void; }