@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
46 lines (45 loc) • 1.89 kB
JavaScript
import { jsx as _jsx, 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 { useSelector } from 'react-redux';
import { KubeObject } from '../../../lib/k8s/KubeObject';
import { KubeObjectGlance } from './KubeObjectGlance';
/**
* Generic glance component for rendering node previews in Headlamp's graph view.
* Renders KubeObjectGlance for Kubernetes objects or a plugin-provided glance for other nodes.
*/
export const NodeGlance = ({ node }) => {
const glances = useSelector((state) => state.graphView.glances);
const glanceResults = Object.values(glances).map(glance => {
const GlanceComponent = glance.component;
return _jsx(GlanceComponent, { node: node }, glance.id);
});
const validGlanceResults = glanceResults.filter(result => result !== null);
const results = [...validGlanceResults];
if (node.kubeObject instanceof KubeObject) {
results.push(_jsx(KubeObjectGlance, { resource: node.kubeObject }, "kube-object-glance"));
}
/**
* Return null if no components are available to render.
*/
if (results.length === 0) {
return null;
}
/**
* Render all components (custom glances and KubeObjectGlance) within a fragment.
*/
return _jsx(_Fragment, { children: results });
};