UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

53 lines (52 loc) 2.54 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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 Alert from '@mui/material/Alert'; import AlertTitle from '@mui/material/AlertTitle'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import { useTheme } from '@mui/material/styles'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useSelectedClusters } from '../../lib/k8s'; export function ClusterGroupErrorMessage({ errors }) { if (!errors || errors?.length === 0) { return null; } return errors.map((error, i) => _jsx(ErrorMessage, { error: error }, error.stack ?? i)); } function ErrorMessage({ error }) { const theme = useTheme(); const { t } = useTranslation(); const showClusterName = useSelectedClusters().length > 1; const [showMessage, setShowMessage] = useState(false); const defaultTitle = t('Failed to load resources'); const forbiddenTitle = t("You don't have permissions to view this resource"); const notFoundTitile = t('Resource not found'); const isForbidden = error.status === 403; let title = defaultTitle; if (error.status === 404) { title = notFoundTitile; } else if (isForbidden) { title = forbiddenTitle; } const severity = isForbidden ? 'info' : 'warning'; return (_jsxs(Alert, { severity: severity, sx: { mb: 1 }, action: _jsx(Button, { size: "small", color: severity, onClick: () => setShowMessage(it => !it), sx: { whiteSpace: 'nowrap' }, children: showMessage ? t('Hide details') : t('Show details') }), children: [_jsx(AlertTitle, { sx: { mb: showMessage ? undefined : 0, color: theme.palette.text.primary, }, children: title }), showMessage && (_jsxs(_Fragment, { children: [showClusterName ? _jsxs(Box, { children: ["Cluster: ", error.cluster] }) : null, error.message] }))] })); }