UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

59 lines (58 loc) 2.75 kB
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 { Box } from '@mui/system'; import { memo, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import Event from '../../../lib/k8s/event'; import { DateLabel } from '../../common/Label'; import { DeploymentGlance } from './DeploymentGlance'; import { EndpointsGlance } from './EndpointsGlance'; import { PodGlance } from './PodGlance'; import { ReplicaSetGlance } from './ReplicaSetGlance'; import { ServiceGlance } from './ServiceGlance'; /** * Little Popup preview of a Kube object */ export const KubeObjectGlance = memo(({ resource }) => { const { t } = useTranslation(); const [events, setEvents] = useState([]); useEffect(() => { Event.objectEvents(resource).then(it => setEvents(it)); }, []); const kind = resource.kind; const sections = []; if (kind === 'Pod') { sections.push(_jsx(PodGlance, { pod: resource })); } if (kind === 'Deployment') { sections.push(_jsx(DeploymentGlance, { deployment: resource })); } if (kind === 'Service') { sections.push(_jsx(ServiceGlance, { service: resource })); } if (kind === 'Endpoints') { sections.push(_jsx(EndpointsGlance, { endpoints: resource })); } if (kind === 'ReplicaSet' || kind === 'StatefulSet') { sections.push(_jsx(ReplicaSetGlance, { set: resource })); } if (events.length > 0) { sections.push(_jsxs(Box, { mt: 2, children: [_jsxs(Box, { display: "flex", alignItems: "center", gap: 1, mb: 1, fontSize: 14, children: [_jsx(Icon, { icon: "mdi:message-notification" }), t('glossary|Events')] }), events.slice(0, 5).map(it => (_jsxs(Box, { display: "flex", gap: 1, alignItems: "center", mb: 0.5, width: "100%", children: [_jsx(Box, { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", mr: "auto", maxWidth: "300px", title: it.message, children: it.message }), _jsx(DateLabel, { date: it.lastOccurrence, format: "mini" })] }, it.message + it.lastOccurrence)))] }, "events")); } return sections; });