import { observer } from "mobx-react"; import { FC, ComponentPropsWithoutRef, Ref, MouseEventHandler, forwardRef } from "react"; import { useTranslation, withTranslation } from "react-i18next"; import styled, { DefaultTheme, withTheme } from "styled-components"; import ViewState from "../../ReactViewModels/ViewState"; import Box from "../../Styled/Box"; import Button from "../../Styled/Button"; import Icon, { StyledIcon } from "../../Styled/Icon"; import Spacing from "../../Styled/Spacing"; import Text from "../../Styled/Text"; import { ExplorerWindowElementName } from "../ExplorerWindow/ExplorerWindow"; import { useRefForTerria } from "../Hooks/useRefForTerria"; import SearchBoxAndResults from "../Search/SearchBoxAndResults"; import { useViewState, withViewState } from "../Context"; import Workbench from "../Workbench/Workbench"; import { applyTranslationIfExists } from "../../Language/languageHelpers"; import { Category, HelpAction } from "../../Core/AnalyticEvents/analyticEvents"; import { runInAction } from "mobx"; const BoxHelpfulHints = styled(Box)` align-self: flex-end; margin-top: auto; color: ${(p) => p.theme.greyLighter}; `; interface EmptyWorkbenchProps { theme: DefaultTheme; } type TransContent = { heading?: string; body?: string; list?: string[]; }[]; const EmptyWorkbench: FC = observer(() => { const { t } = useTranslation(); const viewState = useViewState(); const transContent = t("emptyWorkbenchInfo", { returnObjects: true }) as TransContent; return ( {/*hacky margin fix for spacing */} {transContent.map((content, idx) => (
{content.heading && ( {content.heading}{" "} )} {content.body && {content.body}} {content.list && (
    {content.list.map((item) => (
  • {item}
  • ))}
)}
))}
); }); type SidePanelButtonProps = { btnText?: string; children?: React.ReactNode; } & ComponentPropsWithoutRef; const SidePanelButton = forwardRef( function SidePanelButton(props, ref) { const { btnText, ...rest } = props; return ( ); } ); export const EXPLORE_MAP_DATA_NAME = "ExploreMapDataButton"; export const SIDE_PANEL_UPLOAD_BUTTON_NAME = "SidePanelUploadButton"; interface SidePanelProps { viewState: ViewState; refForExploreMapData: Ref; refForUploadData: Ref; theme: DefaultTheme; } const SidePanel = observer>( ({ viewState, theme, refForExploreMapData, refForUploadData }) => { const terria = viewState.terria; const { t, i18n } = useTranslation(); const onAddDataClicked: MouseEventHandler = (e) => { e.stopPropagation(); viewState.setTopElement(ExplorerWindowElementName); viewState.openAddData(); }; const onAddLocalDataClicked: MouseEventHandler = (e) => { e.stopPropagation(); viewState.setTopElement(ExplorerWindowElementName); viewState.openUserData(); }; const addData = t("addData.addDataBtnText"); const uploadText = t("models.catalog.upload"); return (
{terria.workbench.items.length > 0 ? ( ) : ( )}
); } ); // Used to create two refs for to consume, rather than // using the withTerriaRef() HOC twice, designed for a single ref const SidePanelWithRefs: FC< Omit > = (props) => { const refForExploreMapData = useRefForTerria( EXPLORE_MAP_DATA_NAME, props.viewState ); const refForUploadData = useRefForTerria( SIDE_PANEL_UPLOAD_BUTTON_NAME, props.viewState ); return ( } refForUploadData={refForUploadData as Ref} /> ); }; export default withTranslation()(withViewState(withTheme(SidePanelWithRefs)));