mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 14:59:41 +02:00
refactor(namespace): migrate namespace edit to react [r8s-125] (#38)
This commit is contained in:
parent
40c7742e46
commit
ce7e0d8d60
108 changed files with 3183 additions and 2194 deletions
|
@ -0,0 +1,34 @@
|
|||
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { PodMetrics } from '../types';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
export function useMetricsForNamespace<T = PodMetrics>(
|
||||
environmentId: EnvironmentId,
|
||||
namespaceName: string,
|
||||
queryOptions?: UseQueryOptions<PodMetrics, unknown, T>
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.namespaceMetrics(environmentId, namespaceName),
|
||||
queryFn: () => getMetricsForNamespace(environmentId, namespaceName),
|
||||
...queryOptions,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getMetricsForNamespace(
|
||||
environmentId: EnvironmentId,
|
||||
namespaceName: string
|
||||
) {
|
||||
try {
|
||||
const { data: pods } = await axios.get<PodMetrics>(
|
||||
`kubernetes/${environmentId}/metrics/pods/namespace/${namespaceName}`
|
||||
);
|
||||
return pods;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e, 'Unable to retrieve metrics for all pods');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue