@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
95 lines (94 loc) • 4.39 kB
JavaScript
import { jsx as _jsx } 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 Box from '@mui/system/Box';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import Gateway from '../../lib/k8s/gateway';
import { EmptyContent, StatusLabel } from '../common';
import Link from '../common/Link';
import { ConditionsTable, DetailsGrid } from '../common/Resource';
import SectionBox from '../common/SectionBox';
import SimpleTable, { NameValueTable } from '../common/SimpleTable';
function GatewayListenerTable(props) {
const { listener, status } = props;
const { t } = useTranslation(['glossary', 'translation']);
function makeStatusLabel(condition) {
let status = '';
if (condition.type === 'Available') {
status = condition.status === 'True' ? 'success' : 'error';
}
return (_jsx(Box, { display: "inline-block", sx: theme => ({ paddingRight: theme.spacing(1) }), children: _jsx(StatusLabel, { status: status, children: condition.type }) }));
}
const mainRows = [
{
name: listener.name,
withHighlightStyle: true,
},
{
name: t('translation|Hostname'),
value: listener.hostname,
},
{
name: t('translation|Port'),
value: listener.port,
},
{
name: t('translation|Protocol'),
value: listener.protocol,
},
{
name: t('translation|Conditions'),
value: status?.conditions.map(c => makeStatusLabel(c)),
},
];
return _jsx(NameValueTable, { rows: mainRows });
}
export default function GatewayDetails(props) {
const params = useParams();
const { name = params.name, namespace = params.namespace } = props;
const { t } = useTranslation(['glossary', 'translation']);
return (_jsx(DetailsGrid, { resourceType: Gateway, name: name, namespace: namespace, withEvents: true, extraInfo: gateway => gateway && [
{
name: t('Class Name'),
value: gateway.spec?.gatewayClassName ? (_jsx(Link, { routeName: "gatewayclass", params: { name: gateway.spec?.gatewayClassName }, activeCluster: gateway.cluster, children: gateway.spec?.gatewayClassName })) : null,
},
], extraSections: (item) => item && [
{
id: 'headlamp.gateway-addresses',
section: item && (_jsx(SectionBox, { title: t('Addresses'), children: _jsx(SimpleTable, { emptyMessage: t('translation|No addresses data to be shown.'), columns: [
{
label: t('translation|Type'),
getter: (data) => data.type,
},
{
label: t('translation|Value'),
getter: (data) => data.value,
},
], data: item?.getAddresses() || [], reflectInURL: "addresses" }) })),
},
{
id: 'headlamp.gateway-listeners',
section: item && (_jsx(SectionBox, { title: t('Listeners'), children: item.getListeners().length === 0 ? (_jsx(EmptyContent, { children: t('No data') })) : (item
.getListeners()
.map((listener) => (_jsx(GatewayListenerTable, { listener: listener, status: item.getListernerStatusByName(listener.name) })))) })),
},
{
id: 'headlamp.gateway-conditions',
section: (_jsx(SectionBox, { title: t('translation|Conditions'), children: _jsx(ConditionsTable, { resource: item.jsonData, showLastUpdate: false }) })),
},
] }));
}