UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

46 lines (45 loc) 2.68 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 Paper from '@mui/material/Paper'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { createRouteURL } from '../../../../lib/router/createRouteURL'; import Loader from '../../../common/Loader'; import Empty from '../../EmptyContent'; import SectionBox from '../../SectionBox'; import A8RInfo from '../A8RInfo'; import { MetadataDisplay } from '../MetadataDisplay'; import { MainInfoHeader } from './MainInfoSectionHeader'; export function MainInfoSection(props) { const { resource, headerSection, title, extraInfo = [], actions = [], headerStyle = 'main', noDefaultActions = false, backLink, error = null, } = props; const { t } = useTranslation(); const header = typeof headerSection === 'function' ? headerSection(resource) : headerSection; function getBackLink() { if (backLink === null) { return false; } if (!!backLink || backLink === '') { return backLink; } if (!!resource) { return createRouteURL(resource.listRoute); } } const annotations = resource?.metadata?.annotations ?? {}; const hasA8r = Object.keys(annotations).some(key => key.startsWith('a8r.io/')); return (_jsxs(_Fragment, { children: [_jsx(SectionBox, { "aria-busy": resource === null, "aria-live": "polite", title: _jsx(MainInfoHeader, { title: title, resource: resource, headerStyle: headerStyle, noDefaultActions: noDefaultActions, actions: actions }), backLink: getBackLink(), children: resource === null ? (!!error ? (_jsx(Paper, { variant: "outlined", children: _jsx(Empty, { color: "error", children: error.toString() }) })) : (_jsx(Loader, { title: t('translation|Loading resource data') }))) : (_jsxs(React.Fragment, { children: [header, _jsx(MetadataDisplay, { resource: resource, extraRows: extraInfo })] })) }), resource && hasA8r && (_jsx(SectionBox, { title: t('a8r.io Metadata'), children: _jsx(A8RInfo, { annotations: annotations }) }))] })); }