import { runInAction } from "mobx"; import { FC } from "react"; import TerriaError from "../../Core/TerriaError"; import ViewState from "../../ReactViewModels/ViewState"; import Box from "../../Styled/Box"; import { RawButton } from "../../Styled/Button"; import Spacing from "../../Styled/Spacing"; import { TextSpan } from "../../Styled/Text"; import FeedbackLinkCustomComponent, { FeedbackLink } from "../Custom/FeedbackLinkCustomComponent"; import parseCustomMarkdownToReact from "../Custom/parseCustomMarkdownToReact"; // Hard code colour for now const warningColor = "#f69900"; const showErrorNotification = (viewState: ViewState, error: TerriaError) => { runInAction(() => { error.showDetails = true; }); viewState.terria.raiseErrorToUser(error, undefined, true); }; const WarningBox: FC<{ children?: React.ReactNode; error?: TerriaError; viewState?: ViewState; }> = (props) => { // We only show FeedbankLink if the error message doesn't include the custom component (so we don't get duplicates) const includesFeedbackLink = props.error?.highestImportanceError.message.includes( `<${FeedbackLinkCustomComponent.componentName}` ); return ( {props.error ? (
{parseCustomMarkdownToReact( `### ${props.error?.highestImportanceError?.title}` )} {parseCustomMarkdownToReact( props.error?.highestImportanceError?.message, { viewState: props.viewState, terria: props.viewState?.terria } )} {props.viewState && !includesFeedbackLink ? ( ) : null} {/* Add "show details" button if there are nested errors */} {props.viewState && Array.isArray(props.error!.originalError) && props.error!.originalError.length > 0 ? (
showErrorNotification(props.viewState!, props.error!) } > See details
) : null}
) : ( props.children )}
); }; // Equilateral triangle const WarningIcon = () => (

!

); export default WarningBox;