Skip to content

Commit

Permalink
Fix compare and explorer modal interaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
na9da committed Nov 9, 2021
1 parent c95cdbe commit 3d1e55a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
16 changes: 13 additions & 3 deletions lib/ReactViews/Compare/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ItemList from "./ItemList";
import ItemSelector from "./ItemSelector";
import LocationDateFilter from "./LocationDateFilter";
import { Panel, PanelMenu } from "./Panel";
import { ExplorerWindowElementName } from "../ExplorerWindow/ExplorerWindow";

export type PropsType = {
viewState: ViewState;
Expand Down Expand Up @@ -229,9 +230,18 @@ const Compare: React.FC<PropsType> = observer(props => {
show ? showItem(item, ImagerySplitDirection.NONE) : hideItem(item)
);

const openCatalogExplorer = action(() => {
viewState.explorerPanelIsVisible = true;
});
const openCatalogExplorer = action(
(event: React.MouseEvent<HTMLButtonElement>) => {
viewState.explorerPanelIsVisible = true;
viewState.setTopElement(ExplorerWindowElementName);
// Call to stopPropagation is required to prevent the parent
// WorkflowPanel from capturing the click and setting itself as the top
// element. If that happens the ExplorerWindow modal will no longer be
// the top element and will not hide itself when clicking the workflow
// panel.
event.stopPropagation();
}
);

const hideAllContextItems = () => {
contextItems.forEach(hideItem);
Expand Down
24 changes: 21 additions & 3 deletions lib/ReactViews/Compare/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const Content = styled.div`
`;

type PanelMenuProps = {
options: { text: string; onSelect: () => void; disabled?: boolean }[];
options: {
text: string;
onSelect: React.MouseEventHandler<HTMLButtonElement>;
disabled?: boolean;
}[];
};

/**
Expand All @@ -85,6 +89,17 @@ export const PanelMenu: React.FC<PanelMenuProps> = ({ options }) => {
[isOpen]
);

const handleClick = (
onSelect: React.MouseEventHandler<HTMLButtonElement>,
event: React.MouseEvent<HTMLButtonElement>
) => {
// If onSelect decides to stop event propogation,
// clickAnywhereToCloseMenu() will not work. So we close the menu before
// calling onSelect.
setIsOpen(false);
onSelect(event);
};

return (
<PanelMenuContainer>
<PanelMenuButton isOpen={isOpen} onClick={() => setIsOpen(true)}>
Expand All @@ -93,8 +108,11 @@ export const PanelMenu: React.FC<PanelMenuProps> = ({ options }) => {
{isOpen && (
<ul>
{options.map(({ text, onSelect, disabled }) => (
<li>
<PanelMenuItem key={text} onClick={onSelect} disabled={disabled}>
<li key={text}>
<PanelMenuItem
onClick={e => handleClick(onSelect, e)}
disabled={disabled}
>
<Text noWrap medium textLight>
{text}
</Text>
Expand Down
6 changes: 5 additions & 1 deletion lib/ReactViews/ExplorerWindow/ExplorerWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import ModalPopup from "./ModalPopup";
import Tabs from "./Tabs";
import { runInAction } from "mobx";

export const ExplorerWindowElementName = "AddData";

const ExplorerWindow = observer(
createReactClass({
displayName: "ExplorerWindow",
Expand Down Expand Up @@ -46,7 +48,9 @@ const ExplorerWindow = observer(
<ModalPopup
viewState={this.props.viewState}
isVisible={this.isVisible()}
isTopElement={this.props.viewState.topElement === "AddData"}
isTopElement={
this.props.viewState.topElement === ExplorerWindowElementName
}
onClose={this.onClose}
onStartAnimatingIn={this.onStartAnimatingIn}
onDoneAnimatingIn={this.onDoneAnimatingIn}
Expand Down
7 changes: 3 additions & 4 deletions lib/ReactViews/SidePanel/SidePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import Icon, { StyledIcon } from "../../Styled/Icon";
import SearchBoxAndResults from "../Search/SearchBoxAndResults";
import Workbench from "../Workbench/Workbench";
import FullScreenButton from "./FullScreenButton";

import { useRefForTerria } from "../Hooks/useRefForTerria";

import Box from "../../Styled/Box";
import Spacing from "../../Styled/Spacing";
import Text from "../../Styled/Text";
import Button from "../../Styled/Button";
import { ExplorerWindowElementName } from "../ExplorerWindow/ExplorerWindow";

const BoxHelpfulHints = styled(Box)``;

Expand Down Expand Up @@ -140,13 +139,13 @@ const SidePanel = observer(

onAddDataClicked(e) {
e.stopPropagation();
this.props.viewState.setTopElement("AddData");
this.props.viewState.setTopElement(ExplorerWindowElementName);
this.props.viewState.openAddData();
},

onAddLocalDataClicked(e) {
e.stopPropagation();
this.props.viewState.setTopElement("AddData");
this.props.viewState.setTopElement(ExplorerWindowElementName);
this.props.viewState.openUserData();
},
render() {
Expand Down
3 changes: 2 additions & 1 deletion lib/ReactViews/WelcomeMessage/WelcomeMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import VideoGuide from "../Map/Panels/HelpPanel/VideoGuide";
import { TourPortalDisplayName } from "../Tour/TourPortal";
import FadeIn from "../Transitions/FadeIn/FadeIn";
import SlideUpFadeIn from "../Transitions/SlideUpFadeIn/SlideUpFadeIn";
import { ExplorerWindowElementName } from "../ExplorerWindow/ExplorerWindow";

export const WELCOME_MESSAGE_NAME = "welcomeMessage";
export const LOCAL_PROPERTY_KEY = `${WELCOME_MESSAGE_NAME}Prompted`;
Expand Down Expand Up @@ -128,7 +129,7 @@ export const WelcomeMessagePure = props => {
if (shouldExploreData) {
setShouldExploreData(false);
viewState.openAddData();
viewState.setTopElement("AddData");
viewState.setTopElement(ExplorerWindowElementName);
}
if (shouldOpenHelp) {
setShouldOpenHelp(false);
Expand Down

0 comments on commit 3d1e55a

Please sign in to comment.