@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
70 lines (69 loc) • 3.44 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 { Box } from '@mui/system';
import { memo, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import Deployment from '../../../lib/k8s/deployment';
import Endpoints from '../../../lib/k8s/endpoints';
import Event from '../../../lib/k8s/event';
import HPA from '../../../lib/k8s/hpa';
import Pod from '../../../lib/k8s/pod';
import ReplicaSet from '../../../lib/k8s/replicaSet';
import Service from '../../../lib/k8s/service';
import StatefulSet from '../../../lib/k8s/statefulSet';
import { DateLabel } from '../../common/Label';
import { DeploymentGlance } from './DeploymentGlance';
import { EndpointsGlance } from './EndpointsGlance';
import { HorizontalPodAutoscalerGlance } from './HorizontalPodAutoscalerGlance';
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(fetchedEvents => setEvents(fetchedEvents.map((event) => new Event(event))));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const sections = [];
if (Pod.isClassOf(resource)) {
sections.push(_jsx(PodGlance, { pod: resource }));
}
if (Deployment.isClassOf(resource)) {
sections.push(_jsx(DeploymentGlance, { deployment: resource }));
}
if (Service.isClassOf(resource)) {
sections.push(_jsx(ServiceGlance, { service: resource }));
}
if (Endpoints.isClassOf(resource)) {
sections.push(_jsx(EndpointsGlance, { endpoints: resource }));
}
if (ReplicaSet.isClassOf(resource) || StatefulSet.isClassOf(resource)) {
sections.push(_jsx(ReplicaSetGlance, { set: resource }));
}
if (HPA.isClassOf(resource)) {
sections.push(_jsx(HorizontalPodAutoscalerGlance, { hpa: 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;
});