import { action, runInAction, makeObservable } from "mobx"; import { observer } from "mobx-react"; import { Component } from "react"; import { withTranslation, WithTranslation, TFunction } from "react-i18next"; import getPath from "../../Core/getPath"; import Terria from "../../Models/Terria"; import ViewState from "../../ReactViewModels/ViewState"; import Box from "../../Styled/Box"; import { RawButton } from "../../Styled/Button"; import { TextSpan } from "../../Styled/Text"; import BadgeBar from "../BadgeBar"; import Icon, { StyledIcon } from "../../Styled/Icon"; import WorkbenchList from "./WorkbenchList"; import { Category, DataSourceAction } from "../../Core/AnalyticEvents/analyticEvents"; import MappableMixin from "../../ModelMixins/MappableMixin"; interface IProps extends WithTranslation { terria: Terria; viewState: ViewState; t: TFunction; } @observer class Workbench extends Component { constructor(props: IProps) { super(props); makeObservable(this); } disableAll() { this.props.terria.workbench.disableAll(); } enableAll() { this.props.terria.workbench.enableAll(); } @action.bound collapseAll() { runInAction(() => { this.props.terria.workbench.collapseAll(); }); } @action.bound expandAll() { runInAction(() => { this.props.terria.workbench.expandAll(); }); } @action.bound removeAll() { this.props.terria.workbench.items.forEach((item) => { this.props.terria.analytics?.logEvent( Category.dataSource, DataSourceAction.removeAllFromWorkbench, getPath(item) ); this.props.terria.removeSelectedFeaturesForModel(item); }); this.props.terria.workbench.removeAll(); (this.props.terria.timelineStack.items as any).clear(); } render() { const { t } = this.props; const shouldExpandAll = this.props.terria.workbench.shouldExpandAll; // show enable all button if all items are disabled const showEnableAll = this.props.terria.workbench.items .filter((it): it is MappableMixin.Instance => MappableMixin.isMixedInto(it) ) .every((it) => !it.show); return ( {showEnableAll ? ( this.enableAll()} css={` display: flex; align-items: center; padding-left: 5px; min-width: 90px; justify-content: space-evenly; `} > {t("workbench.enableAll")} ) : ( this.disableAll()} css={` display: flex; align-items: center; padding-left: 5px; min-width: 90px; justify-content: space-evenly; `} > {t("workbench.disableAll")} )} {shouldExpandAll ? ( {t("workbench.expandAll")} ) : ( {t("workbench.collapseAll")} )} {t("workbench.removeAll")} ); } } export default withTranslation()(Workbench);