mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 14:29:40 +02:00
refactor(app): app events datatable [EE-5355] (#10024)
This commit is contained in:
parent
0eaf296e1b
commit
c472fe9c18
19 changed files with 277 additions and 19 deletions
|
@ -0,0 +1,51 @@
|
|||
import { EventList } from 'kubernetes-types/core/v1';
|
||||
import { useQuery } from 'react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
|
||||
async function getNamespaceEvents(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
labelSelector?: string
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<EventList>(
|
||||
`/endpoints/${environmentId}/kubernetes/api/v1/namespaces/${namespace}/events`,
|
||||
{
|
||||
params: {
|
||||
labelSelector,
|
||||
},
|
||||
}
|
||||
);
|
||||
return data.items;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to retrieve events');
|
||||
}
|
||||
}
|
||||
|
||||
export function useNamespaceEventsQuery(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
options?: { autoRefreshRate?: number },
|
||||
labelSelector?: string
|
||||
) {
|
||||
return useQuery(
|
||||
[
|
||||
'environments',
|
||||
environmentId,
|
||||
'kubernetes',
|
||||
'events',
|
||||
namespace,
|
||||
labelSelector,
|
||||
],
|
||||
() => getNamespaceEvents(environmentId, namespace, labelSelector),
|
||||
{
|
||||
...withError('Unable to retrieve events'),
|
||||
refetchInterval() {
|
||||
return options?.autoRefreshRate ?? false;
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue