mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +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
86
app/react/kubernetes/queries/useEvents.ts
Normal file
86
app/react/kubernetes/queries/useEvents.ts
Normal file
|
@ -0,0 +1,86 @@
|
|||
import { EventList } from 'kubernetes-types/core/v1';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios from '@/portainer/services/axios';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
|
||||
import { parseKubernetesAxiosError } from '../axiosError';
|
||||
|
||||
import { queryKeys as environmentQueryKeys } from './query-keys';
|
||||
|
||||
type RequestOptions = {
|
||||
/** if undefined, events are fetched at the cluster scope */
|
||||
namespace?: string;
|
||||
params?: {
|
||||
/** https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors */
|
||||
labelSelector?: string;
|
||||
/** https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors */
|
||||
fieldSelector?: string;
|
||||
};
|
||||
};
|
||||
|
||||
const queryKeys = {
|
||||
base: (environmentId: number, { namespace, params }: RequestOptions) => {
|
||||
if (namespace) {
|
||||
return [
|
||||
...environmentQueryKeys.base(environmentId),
|
||||
'events',
|
||||
namespace,
|
||||
params,
|
||||
] as const;
|
||||
}
|
||||
return [
|
||||
...environmentQueryKeys.base(environmentId),
|
||||
'events',
|
||||
params,
|
||||
] as const;
|
||||
},
|
||||
};
|
||||
|
||||
async function getEvents(
|
||||
environmentId: EnvironmentId,
|
||||
options?: RequestOptions
|
||||
) {
|
||||
const { namespace, params } = options ?? {};
|
||||
try {
|
||||
const { data } = await axios.get<EventList>(
|
||||
buildUrl(environmentId, namespace),
|
||||
{
|
||||
params,
|
||||
}
|
||||
);
|
||||
return data.items;
|
||||
} catch (e) {
|
||||
throw parseKubernetesAxiosError(e, 'Unable to retrieve events');
|
||||
}
|
||||
}
|
||||
|
||||
type QueryOptions = {
|
||||
queryOptions?: {
|
||||
autoRefreshRate?: number;
|
||||
};
|
||||
} & RequestOptions;
|
||||
|
||||
export function useEvents(
|
||||
environmentId: EnvironmentId,
|
||||
options?: QueryOptions
|
||||
) {
|
||||
const { queryOptions, params, namespace } = options ?? {};
|
||||
return useQuery(
|
||||
queryKeys.base(environmentId, { params, namespace }),
|
||||
() => getEvents(environmentId, { params, namespace }),
|
||||
{
|
||||
...withError('Unable to retrieve events'),
|
||||
refetchInterval() {
|
||||
return queryOptions?.autoRefreshRate ?? false;
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function buildUrl(environmentId: EnvironmentId, namespace?: string) {
|
||||
return namespace
|
||||
? `/endpoints/${environmentId}/kubernetes/api/v1/namespaces/${namespace}/events`
|
||||
: `/endpoints/${environmentId}/kubernetes/api/v1/events`;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue