@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
49 lines (48 loc) • 3.43 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/*
* Copyright 2025 The Kubernetes Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Icon } from '@iconify/react';
import Accordion from '@mui/material/Accordion';
import AccordionDetails from '@mui/material/AccordionDetails';
import AccordionSummary from '@mui/material/AccordionSummary';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Grid from '@mui/material/Grid';
import Link from '@mui/material/Link';
import Typography from '@mui/material/Typography';
import { styled } from '@mui/system';
import { Trans, useTranslation } from 'react-i18next';
import headlampBrokenImage from '../../../assets/headlamp-broken.svg';
const WidthImg = styled('img')({
width: '100%',
});
export default function ErrorComponent(props) {
const { t } = useTranslation();
const { title = t('Uh-oh! Something went wrong.'), message = '', withTypography = true,
// In vite headlampBrokenImage is a string, but in webpack it is an object
// TODO: Remove this once we migrate plugins to vite
graphic = headlampBrokenImage, error, } = props;
return (_jsxs(Grid, { container: true, spacing: 0, direction: "column", alignItems: "center", justifyContent: "center", sx: { textAlign: 'center' }, children: [_jsxs(Grid, { item: true, xs: 12, children: [typeof graphic === 'string' ? _jsx(WidthImg, { src: graphic, alt: "" }) : graphic, withTypography ? (_jsx(Typography, { variant: "h1", sx: { fontSize: '2.125rem', lineHeight: 1.2, fontWeight: 400 }, children: title })) : (title), withTypography ? (_jsx(Typography, { variant: "h2", sx: { fontSize: '1.25rem', lineHeight: 3.6, fontWeight: 500 }, children: !!message ? (message) : (_jsxs(Trans, { t: t, children: ["Head back ", _jsx(Link, { href: window.desktopApi ? '#' : '/', children: "home" }), "."] })) })) : (message)] }), !!error?.stack && (_jsx(Grid, { item: true, xs: 12, children: _jsx(Box, { sx: {
width: '100%',
maxWidth: 800,
}, children: _jsxs(Accordion, { children: [_jsx(AccordionSummary, { expandIcon: _jsx(Icon, { icon: "mdi:chevron-down" }), children: _jsx(Typography, { children: t('translation|Error Details') }) }), _jsxs(AccordionDetails, { children: [_jsx(Box, { textAlign: "right", children: _jsx(Button, { onClick: () => {
navigator.clipboard.writeText(error.stack);
}, children: t('translation|Copy') }) }), _jsx(Typography, { variant: "body2", component: "pre", sx: {
textWrapMode: 'wrap',
textAlign: 'left',
overflowWrap: 'anywhere',
}, children: error.stack })] })] }) }) }))] }));
}