mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
refactor(kube): events datatable react migration [EE-6450] (#11583)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Co-authored-by: testa113 <testa113>
This commit is contained in:
parent
c15789eb73
commit
bb61e73464
24 changed files with 233 additions and 306 deletions
|
@ -0,0 +1,51 @@
|
|||
import { Event } from 'kubernetes-types/core/v1';
|
||||
import { History } from 'lucide-react';
|
||||
|
||||
import { IndexOptional } from '@/react/kubernetes/configs/types';
|
||||
import { TableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings';
|
||||
|
||||
import { Datatable, TableSettingsMenu } from '@@/datatables';
|
||||
import { TableSettingsMenuAutoRefresh } from '@@/datatables/TableSettingsMenuAutoRefresh';
|
||||
import { TableState } from '@@/datatables/useTableState';
|
||||
|
||||
import { columns } from './columns';
|
||||
|
||||
type Props = {
|
||||
dataset: Event[];
|
||||
tableState: TableState<TableSettings>;
|
||||
isLoading: boolean;
|
||||
'data-cy': string;
|
||||
noWidget?: boolean;
|
||||
};
|
||||
|
||||
export function EventsDatatable({
|
||||
dataset,
|
||||
tableState,
|
||||
isLoading,
|
||||
'data-cy': dataCy,
|
||||
noWidget,
|
||||
}: Props) {
|
||||
return (
|
||||
<Datatable<IndexOptional<Event>>
|
||||
dataset={dataset}
|
||||
columns={columns}
|
||||
settingsManager={tableState}
|
||||
isLoading={isLoading}
|
||||
emptyContentLabel="No event available."
|
||||
title="Events"
|
||||
titleIcon={History}
|
||||
getRowId={(row) => row.metadata?.uid || ''}
|
||||
disableSelect
|
||||
renderTableSettings={() => (
|
||||
<TableSettingsMenu>
|
||||
<TableSettingsMenuAutoRefresh
|
||||
value={tableState.autoRefreshRate}
|
||||
onChange={(value) => tableState.setAutoRefreshRate(value)}
|
||||
/>
|
||||
</TableSettingsMenu>
|
||||
)}
|
||||
data-cy={dataCy}
|
||||
noWidget={noWidget}
|
||||
/>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
import { useCurrentStateAndParams } from '@uirouter/react';
|
||||
|
||||
import { useKubeStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
|
||||
import { useEvents } from '@/react/kubernetes/queries/useEvents';
|
||||
import { EventsDatatable } from '@/react/kubernetes/components/EventsDatatable';
|
||||
|
||||
type Props = {
|
||||
storageKey: string;
|
||||
/** if undefined, all resources for the namespace (or cluster are returned) */
|
||||
resourceId?: string;
|
||||
/** if undefined, events are fetched for the cluster */
|
||||
namespace?: string;
|
||||
};
|
||||
|
||||
/** ResourceEventsDatatable returns the EventsDatatable for all events that relate to a specific resource id */
|
||||
export function ResourceEventsDatatable({
|
||||
storageKey,
|
||||
resourceId,
|
||||
namespace,
|
||||
}: Props) {
|
||||
const tableState = useKubeStore(storageKey, {
|
||||
id: 'Date',
|
||||
desc: true,
|
||||
});
|
||||
|
||||
const {
|
||||
params: { endpointId },
|
||||
} = useCurrentStateAndParams();
|
||||
|
||||
const params = resourceId
|
||||
? { fieldSelector: `involvedObject.uid=${resourceId}` }
|
||||
: {};
|
||||
const resourceEventsQuery = useEvents(endpointId, {
|
||||
namespace,
|
||||
params,
|
||||
queryOptions: {
|
||||
autoRefreshRate: tableState.autoRefreshRate
|
||||
? tableState.autoRefreshRate * 1000
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
const nodeEvents = resourceEventsQuery.data || [];
|
||||
|
||||
return (
|
||||
<EventsDatatable
|
||||
dataset={nodeEvents}
|
||||
tableState={tableState}
|
||||
isLoading={resourceEventsQuery.isLoading}
|
||||
data-cy="k8sNodeDetail-eventsTable"
|
||||
noWidget
|
||||
/>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { formatDate } from '@/portainer/filters/filters';
|
||||
|
||||
import { columnHelper } from './helper';
|
||||
|
||||
export const date = columnHelper.accessor(
|
||||
(event) => formatDate(event.lastTimestamp || event.eventTime),
|
||||
{
|
||||
header: 'Date',
|
||||
id: 'Date',
|
||||
}
|
||||
);
|
|
@ -0,0 +1,21 @@
|
|||
import { Badge, BadgeType } from '@@/Badge';
|
||||
|
||||
import { columnHelper } from './helper';
|
||||
|
||||
export const eventType = columnHelper.accessor('type', {
|
||||
header: 'Type',
|
||||
cell: ({ getValue }) => (
|
||||
<Badge type={getBadgeColor(getValue())}>{getValue()}</Badge>
|
||||
),
|
||||
});
|
||||
|
||||
function getBadgeColor(status?: string): BadgeType {
|
||||
switch (status?.toLowerCase()) {
|
||||
case 'normal':
|
||||
return 'info';
|
||||
case 'warning':
|
||||
return 'warn';
|
||||
default:
|
||||
return 'danger';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
import { createColumnHelper } from '@tanstack/react-table';
|
||||
import { Event } from 'kubernetes-types/core/v1';
|
||||
|
||||
export const columnHelper = createColumnHelper<Event>();
|
|
@ -0,0 +1,6 @@
|
|||
import { date } from './date';
|
||||
import { kind } from './kind';
|
||||
import { eventType } from './eventType';
|
||||
import { message } from './message';
|
||||
|
||||
export const columns = [date, kind, eventType, message];
|
|
@ -0,0 +1,8 @@
|
|||
import { columnHelper } from './helper';
|
||||
|
||||
export const kind = columnHelper.accessor(
|
||||
(event) => event.involvedObject.kind,
|
||||
{
|
||||
header: 'Kind',
|
||||
}
|
||||
);
|
|
@ -0,0 +1,5 @@
|
|||
import { columnHelper } from './helper';
|
||||
|
||||
export const message = columnHelper.accessor('message', {
|
||||
header: 'Message',
|
||||
});
|
1
app/react/kubernetes/components/EventsDatatable/index.ts
Normal file
1
app/react/kubernetes/components/EventsDatatable/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export { EventsDatatable } from './EventsDatatable';
|
Loading…
Add table
Add a link
Reference in a new issue