import React from "react"; import { formatLayerId } from "../libs/format"; import { type LayerSpecification, type StyleSpecification } from "maplibre-gl"; import { type WithTranslation, withTranslation } from "react-i18next"; import { type MappedError } from "../libs/definitions"; type AppMessagePanelInternalProps = { errors?: MappedError[] infos?: string[] mapStyle?: StyleSpecification onLayerSelect?(index: number): void; currentLayer?: LayerSpecification selectedLayerIndex?: number } & WithTranslation; class AppMessagePanelInternal extends React.Component { static defaultProps = { onLayerSelect: () => { }, }; render() { const { t, selectedLayerIndex } = this.props; const errors = this.props.errors?.map((error, idx) => { let content; if (error.parsed && error.parsed.type === "layer") { const { parsed } = error; const layerId = this.props.mapStyle?.layers[parsed.data.index].id; content = ( <> {t("Layer")} {formatLayerId(layerId)}: {parsed.data.message} {selectedLayerIndex !== parsed.data.index && <>  —  } ); } else { content = error.message; } return

{content}

; }); const infos = this.props.infos?.map((m, i) => { return

{m}

; }); return
{errors} {infos}
; } } const AppMessagePanel = withTranslation()(AppMessagePanelInternal); export default AppMessagePanel;