From b5673346abe15530c03a7cc15d90c358c77ffa9d Mon Sep 17 00:00:00 2001 From: Murad CDC Date: Tue, 12 Nov 2024 14:06:07 -0500 Subject: [PATCH 1/2] [DEV-9791] Fix active button issue --- packages/editor/src/components/ChooseTab.tsx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/editor/src/components/ChooseTab.tsx b/packages/editor/src/components/ChooseTab.tsx index 7704c2d1e..ac69edb26 100644 --- a/packages/editor/src/components/ChooseTab.tsx +++ b/packages/editor/src/components/ChooseTab.tsx @@ -1,10 +1,9 @@ -import React, { useContext, useEffect, useState } from 'react' +import React, { useContext } from 'react' import '../scss/choose-vis-tab.scss' import ConfigContext, { EditorDispatchContext } from '../ConfigContext' import Tooltip from '@cdc/core/components/ui/Tooltip' -import InfoIcon from '@cdc/core/assets/icon-info.svg' import DashboardIcon from '@cdc/core/assets/icon-dashboard.svg' import BarIcon from '@cdc/core/assets/icon-chart-bar.svg' import LineIcon from '@cdc/core/assets/icon-chart-line.svg' @@ -40,9 +39,7 @@ interface ButtonProps { const ChooseTab: React.FC = (): JSX.Element => { const { config } = useContext(ConfigContext) - const [activeButtonId, setActiveButtonId] = useState(() => { - return localStorage.getItem('activeButtonId') || null - }) + const dispatch = useContext(EditorDispatchContext) const rowLabels = ['General', , 'Charts', 'Maps'] @@ -105,18 +102,14 @@ const ChooseTab: React.FC = (): JSX.Element => { const configureTabs = props => { const newConfig = generateNewConfig(props) - dispatch({ type: 'EDITOR_SET_CONFIG', payload: { ...config, ...newConfig } }) + dispatch({ type: 'EDITOR_SET_CONFIG', payload: { ...config, ...newConfig, activeVizButtonID: props.id } }) dispatch({ type: 'EDITOR_SET_GLOBALACTIVE', payload: 1 }) } const VizButton: React.FC = props => { const { label, icon, id } = props - const isActive = id === Number(activeButtonId) + const isActive = id === config?.activeVizButtonID || 0 const handleClick = () => { - const newActiveId = id.toString() - localStorage.setItem('activeButtonId', newActiveId) - setActiveButtonId(newActiveId) - configureTabs(props) } From 4bc607e00a32ea29087824a753353fd19fa0d16b Mon Sep 17 00:00:00 2001 From: Murad CDC Date: Tue, 12 Nov 2024 14:17:56 -0500 Subject: [PATCH 2/2] [DEV-9791] Add temp config --- packages/editor/src/components/ChooseTab.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/components/ChooseTab.tsx b/packages/editor/src/components/ChooseTab.tsx index ac69edb26..25af3f980 100644 --- a/packages/editor/src/components/ChooseTab.tsx +++ b/packages/editor/src/components/ChooseTab.tsx @@ -38,7 +38,7 @@ interface ButtonProps { } const ChooseTab: React.FC = (): JSX.Element => { - const { config } = useContext(ConfigContext) + const { config, tempConfig } = useContext(ConfigContext) const dispatch = useContext(EditorDispatchContext) const rowLabels = ['General', , 'Charts', 'Maps'] @@ -113,6 +113,10 @@ const ChooseTab: React.FC = (): JSX.Element => { configureTabs(props) } + if (tempConfig) { + dispatch({ type: 'EDITOR_SAVE', payload: tempConfig }) + } + return (