From 8aafc95946b9d85bb802853f94a2e71eded2182e Mon Sep 17 00:00:00 2001 From: ashu8192 Date: Wed, 3 Jan 2024 20:53:11 +0530 Subject: [PATCH] frontend: Add event for list, detail and objectEvent Signed-off-by: ashu8192 --- .../src/components/common/ObjectEventList.tsx | 9 ++++++++- .../MainInfoSection/MainInfoSection.tsx | 14 +++++++++++++- .../src/components/common/Resource/Resource.tsx | 14 ++++++++++++++ .../common/Resource/ResourceTable.tsx | 17 ++++++++++++++++- frontend/src/redux/eventCallbackSlice.ts | 3 +++ 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/common/ObjectEventList.tsx b/frontend/src/components/common/ObjectEventList.tsx index a0cb906ab5d..393df03e8c1 100644 --- a/frontend/src/components/common/ObjectEventList.tsx +++ b/frontend/src/components/common/ObjectEventList.tsx @@ -2,7 +2,8 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { KubeObject } from '../../lib/k8s/cluster'; import Event, { KubeEvent } from '../../lib/k8s/event'; -import { localeDate, timeAgo } from '../../lib/util'; +import { dispatchHeadlampEvent, localeDate, timeAgo } from '../../lib/util'; +import { HeadlampEventType } from '../../redux/eventCallbackSlice'; import { HoverInfoLabel, SectionBox, SimpleTable } from '../common'; import ShowHideLabel from './ShowHideLabel'; @@ -13,6 +14,12 @@ export interface ObjectEventListProps { export default function ObjectEventList(props: ObjectEventListProps) { const [events, setEvents] = useState([]); + useEffect(() => { + if (events) { + dispatchHeadlampEvent({ type: HeadlampEventType.OBJECT_EVENT, data: events }); + } + }, [events]); + async function fetchEvents() { const events = await Event.objectEvents(props.object); setEvents(events); diff --git a/frontend/src/components/common/Resource/MainInfoSection/MainInfoSection.tsx b/frontend/src/components/common/Resource/MainInfoSection/MainInfoSection.tsx index 29641668d48..3cad28a4416 100644 --- a/frontend/src/components/common/Resource/MainInfoSection/MainInfoSection.tsx +++ b/frontend/src/components/common/Resource/MainInfoSection/MainInfoSection.tsx @@ -1,10 +1,12 @@ import Paper from '@mui/material/Paper'; -import React from 'react'; +import React, { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useLocation } from 'react-router-dom'; import { KubeObject } from '../../../../lib/k8s/cluster'; import { createRouteURL } from '../../../../lib/router'; +import { dispatchHeadlampEvent } from '../../../../lib/util'; import { HeaderAction } from '../../../../redux/actionButtonsSlice'; +import { HeadlampEventType } from '../../../../redux/eventCallbackSlice'; import Loader from '../../../common/Loader'; import { HeaderStyleProps } from '../../../common/SectionHeader'; import { NameValueTableRow } from '../../../common/SimpleTable'; @@ -58,6 +60,16 @@ export function MainInfoSection(props: MainInfoSectionProps) { } } + useEffect(() => { + dispatchHeadlampEvent({ + type: HeadlampEventType.DETAILS_VIEW_LOADED, + data: { + title: resource?.jsonData.kind, + resource: resource, + }, + }); + }, [resource]); + return ( ({}); + React.useEffect(() => { + if (item) { + dispatchHeadlampEvent({ + type: HeadlampEventType.DETAILS_VIEW_LOADED, + data: { + title: item?.jsonData.kind, + resource: item, + }, + }); + } + }, [item]); + React.useEffect(() => { // We cannot call this callback more than once on each version of the item, in order to avoid // infinite loops. diff --git a/frontend/src/components/common/Resource/ResourceTable.tsx b/frontend/src/components/common/Resource/ResourceTable.tsx index ead666d40b7..86d6f3960b0 100644 --- a/frontend/src/components/common/Resource/ResourceTable.tsx +++ b/frontend/src/components/common/Resource/ResourceTable.tsx @@ -3,7 +3,8 @@ import { useEffect, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import helpers from '../../../helpers'; import { KubeObject } from '../../../lib/k8s/cluster'; -import { useFilterFunc } from '../../../lib/util'; +import { dispatchHeadlampEvent, useFilterFunc } from '../../../lib/util'; +import { HeadlampEventType } from '../../../redux/eventCallbackSlice'; import { useTypedSelector } from '../../../redux/reducers/reducers'; import { useSettings } from '../../App/Settings/hook'; import { DateLabel } from '../Label'; @@ -102,6 +103,13 @@ function TableFromResourceClass(props: ResourceTableFromResourceClassProps) { // throttle the update of the table to once per second const throttledItems = useThrottle(items, 1000); + useEffect(() => { + dispatchHeadlampEvent({ + type: HeadlampEventType.LIST_VIEW_LOADED, + data: { title: resourceClass.pluralName, items }, + }); + }, [items]); + return ( { let sortingColumn = defaultSortingColumn; diff --git a/frontend/src/redux/eventCallbackSlice.ts b/frontend/src/redux/eventCallbackSlice.ts index ef011b03658..27896a5053a 100644 --- a/frontend/src/redux/eventCallbackSlice.ts +++ b/frontend/src/redux/eventCallbackSlice.ts @@ -17,6 +17,9 @@ export enum HeadlampEventType { CREATE_BUTTON = 'create-button', PLUGIN_LOADING_ERROR = 'plugin-loading-error', PLUGINS_LOADED = 'plugins-loaded', + DETAILS_VIEW_LOADED = 'details-view-loaded', + LIST_VIEW_LOADED = 'list-view-loaded', + OBJECT_EVENT = 'object-event', } export type HeadlampEvent = {