From aa9e4d4d2044ea819fd0f70b30235edf54e20a52 Mon Sep 17 00:00:00 2001 From: Horia Miron Date: Mon, 5 Oct 2020 11:50:14 +0300 Subject: [PATCH] fix: Org switcher displays the correct selection [EP-3007] --- packages/earth-admin/src/layouts/Sidebar.tsx | 2 +- packages/earth-map/src/components/header/component.tsx | 2 +- .../app-context-switcher/AppContextSwitcher.tsx | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/earth-admin/src/layouts/Sidebar.tsx b/packages/earth-admin/src/layouts/Sidebar.tsx index 9d2f812a..b68351c6 100644 --- a/packages/earth-admin/src/layouts/Sidebar.tsx +++ b/packages/earth-admin/src/layouts/Sidebar.tsx @@ -55,7 +55,7 @@ const SidebarLayout = (props: IProps) => { { if (selectedValue === 'map-view') { window.location.assign(urljoin(MAP_PATH, 'earth')); diff --git a/packages/earth-map/src/components/header/component.tsx b/packages/earth-map/src/components/header/component.tsx index 685f4fa6..ad48b49a 100644 --- a/packages/earth-map/src/components/header/component.tsx +++ b/packages/earth-map/src/components/header/component.tsx @@ -184,7 +184,7 @@ const Header = (props: IProps) => { window.location.assign(`${ADMIN_URL}${g}`)} diff --git a/packages/earth-shared/src/components/app-context-switcher/AppContextSwitcher.tsx b/packages/earth-shared/src/components/app-context-switcher/AppContextSwitcher.tsx index 03801d43..be753af4 100644 --- a/packages/earth-shared/src/components/app-context-switcher/AppContextSwitcher.tsx +++ b/packages/earth-shared/src/components/app-context-switcher/AppContextSwitcher.tsx @@ -30,7 +30,7 @@ import { Option } from './Option'; interface IProps { label: string; logo?: React.ReactNode; - defaultValue?: string; + value?: any; checkedCount?: number; renderDropdown?: boolean; children?: React.ReactChildren | Array; @@ -41,14 +41,13 @@ const AppContextSwitcher = (props: IProps) => { const { label, logo, - defaultValue, + value, checkedCount = 0, renderDropdown = true, children, onChange = noop, } = props; - const [selectedValue, setSelectedValue] = useState(defaultValue); const [isOpen, setIsOpen] = useState(false); const toggleDropdown = () => setIsOpen(!isOpen); const closeDropdown = () => setIsOpen(false); @@ -96,13 +95,12 @@ const AppContextSwitcher = (props: IProps) => { return; } const isOptionElement = child.props.value; - const selected = child.props.value === selectedValue; + const selected = child.props.value === value; return isOptionElement ? cloneElement(child, { selected, onClick: (value: any) => { if (!selected) { - setSelectedValue(value); onChange(value); } closeDropdown();