Skip to content

Commit

Permalink
fix: Org switcher displays the correct selection [EP-3007]
Browse files Browse the repository at this point in the history
  • Loading branch information
ancashoria committed Oct 5, 2020
1 parent e687b8c commit aa9e4d4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/earth-admin/src/layouts/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const SidebarLayout = (props: IProps) => {
<AppContextSwitcher
logo={logo}
label={selectedGroup}
defaultValue={selectedGroup}
value={selectedGroup}
onChange={(selectedValue) => {
if (selectedValue === 'map-view') {
window.location.assign(urljoin(MAP_PATH, 'earth'));
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-map/src/components/header/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const Header = (props: IProps) => {
<AppContextSwitcher
logo={logo}
label="Map View"
defaultValue="map-view"
value="map-view"
checkedCount={selectedGroups.length}
renderDropdown={isAuthenticated}
onChange={(g) => window.location.assign(`${ADMIN_URL}${g}`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.ReactChildren>;
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit aa9e4d4

Please sign in to comment.