UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

95 lines (94 loc) 3.89 kB
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 { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import Event from '../../lib/k8s/event'; import { localeDate, timeAgo } from '../../lib/util'; import { HeadlampEventType, useEventCallback } from '../../redux/headlampEventSlice'; import { HoverInfoLabel } from '../common/Label'; import SectionBox from '../common/SectionBox'; import SimpleTable from '../common/SimpleTable'; import ShowHideLabel from './ShowHideLabel'; export default function ObjectEventList(props) { const [events, setEvents] = useState([]); const dispatchEventList = useEventCallback(HeadlampEventType.OBJECT_EVENTS); useEffect(() => { if (events) { dispatchEventList(events, props.object); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [events]); async function fetchEvents() { try { const events = await Event.objectEvents(props.object); setEvents(events.map((e) => new Event(e))); } catch (e) { console.error('Failed to fetch events for object:', props.object, e); } } const { t } = useTranslation(['translation', 'glossary']); useEffect(() => { fetchEvents(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (_jsx(SectionBox, { title: t('glossary|Events'), children: _jsx(SimpleTable, { columns: [ { label: t('Type'), getter: item => { return item.type; }, }, { label: t('Reason'), getter: item => { return item.reason; }, }, { label: t('From'), getter: item => { return item.source.component; }, }, { label: t('Message'), getter: item => { return (item && (_jsx(ShowHideLabel, { labelId: item?.metadata?.uid || '', children: item.message || '' }))); }, }, { label: t('Age'), getter: item => { const eventDate = timeAgo(item.lastOccurrence, { format: 'mini' }); let label; if (item.count > 1) { label = t('{{ eventDate }} ({{ count }} times since {{ firstEventDate }})', { eventDate, count: item.count, firstEventDate: timeAgo(item.firstOccurrence), }); } else { label = eventDate; } return (_jsx(HoverInfoLabel, { label: label, hoverInfo: localeDate(item.lastOccurrence), icon: "mdi:calendar" })); }, sort: (item) => -new Date(item.lastOccurrence).getTime(), }, ], data: events }) })); }