1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

feat(app): migrate app parent view to react [EE-5361] (#10086)

Co-authored-by: testa113 <testa113>
This commit is contained in:
Ali 2023-08-27 23:01:35 +02:00 committed by GitHub
parent 531f88b947
commit 841ca1ebd4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 1448 additions and 810 deletions

View file

@ -1,14 +1,88 @@
import { HorizontalPodAutoscalerList } from 'kubernetes-types/autoscaling/v1';
import {
HorizontalPodAutoscaler,
HorizontalPodAutoscalerList,
} from 'kubernetes-types/autoscaling/v1';
import { useQuery } from 'react-query';
import axios from '@/portainer/services/axios';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { withError } from '@/react-tools/react-query';
import { parseKubernetesAxiosError } from '../axiosError';
// when yaml is set to true, the expected return type is a string
export function useHorizontalAutoScalarQuery<
T extends HorizontalPodAutoscaler | string = HorizontalPodAutoscaler
>(
environmentId: EnvironmentId,
namespace: string,
name?: string,
options?: { yaml?: boolean }
) {
return useQuery(
[
'environments',
environmentId,
'kubernetes',
'namespaces',
namespace,
'horizontalpodautoscalers',
name,
options?.yaml,
],
() =>
name
? getNamespaceHorizontalPodAutoscaler<T>(
environmentId,
namespace,
name,
options
)
: undefined,
{ ...withError('Unable to get horizontal pod autoscaler'), enabled: !!name }
);
}
export async function getNamespaceHorizontalPodAutoscalers(
environmentId: EnvironmentId,
namespace: string
) {
const { data: autoScalarList } = await axios.get<HorizontalPodAutoscalerList>(
`/endpoints/${environmentId}/kubernetes/apis/autoscaling/v1/namespaces/${namespace}/horizontalpodautoscalers`
);
return autoScalarList.items;
try {
const { data: autoScalarList } =
await axios.get<HorizontalPodAutoscalerList>(
`/endpoints/${environmentId}/kubernetes/apis/autoscaling/v1/namespaces/${namespace}/horizontalpodautoscalers`
);
return autoScalarList.items;
} catch (e) {
throw parseKubernetesAxiosError(
e as Error,
'Unable to retrieve horizontal pod autoscalers'
);
}
}
export async function getNamespaceHorizontalPodAutoscaler<
T extends HorizontalPodAutoscaler | string = HorizontalPodAutoscaler
>(
environmentId: EnvironmentId,
namespace: string,
name: string,
options?: { yaml?: boolean }
) {
try {
const { data: autoScalar } = await axios.get<T>(
`/endpoints/${environmentId}/kubernetes/apis/autoscaling/v1/namespaces/${namespace}/horizontalpodautoscalers/${name}`,
{
headers: {
Accept: options?.yaml ? 'application/yaml' : 'application/json',
},
}
);
return autoScalar;
} catch (e) {
throw parseKubernetesAxiosError(
e as Error,
'Unable to retrieve horizontal pod autoscaler'
);
}
}