1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29: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,4 +1,4 @@
import { useMutation, useQuery } from 'react-query';
import { UseQueryResult, useMutation, useQuery } from 'react-query';
import { Pod } from 'kubernetes-types/core/v1';
import { queryClient, withError } from '@/react-tools/react-query';
@ -27,7 +27,8 @@ const queryKeys = {
application: (
environmentId: EnvironmentId,
namespace: string,
name: string
name: string,
yaml?: boolean
) => [
'environments',
environmentId,
@ -35,6 +36,7 @@ const queryKeys = {
'applications',
namespace,
name,
yaml,
],
applicationRevisions: (
environmentId: EnvironmentId,
@ -120,18 +122,23 @@ export function useApplicationsForCluster(
);
}
// useQuery to get an application by environmentId, namespace and name
export function useApplication(
// when yaml is set to true, the expected return type is a string
export function useApplication<T extends Application | string = Application>(
environmentId: EnvironmentId,
namespace: string,
name: string,
appKind?: AppKind
) {
appKind?: AppKind,
options?: { autoRefreshRate?: number; yaml?: boolean }
): UseQueryResult<T> {
return useQuery(
queryKeys.application(environmentId, namespace, name),
() => getApplication(environmentId, namespace, name, appKind),
queryKeys.application(environmentId, namespace, name, options?.yaml),
() =>
getApplication<T>(environmentId, namespace, name, appKind, options?.yaml),
{
...withError('Unable to retrieve application'),
refetchInterval() {
return options?.autoRefreshRate ?? false;
},
}
);
}
@ -212,7 +219,7 @@ export function useApplicationServices(
}
// useApplicationHorizontalPodAutoscalers returns a query for horizontal pod autoscalers that are related to the application
export function useApplicationHorizontalPodAutoscalers(
export function useApplicationHorizontalPodAutoscaler(
environmentId: EnvironmentId,
namespace: string,
appName: string,
@ -231,7 +238,7 @@ export function useApplicationHorizontalPodAutoscalers(
const horizontalPodAutoscalers =
await getNamespaceHorizontalPodAutoscalers(environmentId, namespace);
const filteredHorizontalPodAutoscalers =
const matchingHorizontalPodAutoscaler =
horizontalPodAutoscalers.find((horizontalPodAutoscaler) => {
const scaleTargetRef = horizontalPodAutoscaler.spec?.scaleTargetRef;
if (scaleTargetRef) {
@ -245,11 +252,11 @@ export function useApplicationHorizontalPodAutoscalers(
}
return false;
}) || null;
return filteredHorizontalPodAutoscalers;
return matchingHorizontalPodAutoscaler;
},
{
...withError(
`Unable to get horizontal pod autoscalers${
`Unable to get horizontal pod autoscaler${
app ? ` for ${app.metadata?.name}` : ''
}`
),
@ -263,7 +270,8 @@ export function useApplicationPods(
environmentId: EnvironmentId,
namespace: string,
appName: string,
app?: Application
app?: Application,
options?: { autoRefreshRate?: number }
) {
return useQuery(
queryKeys.applicationPods(environmentId, namespace, appName),
@ -287,6 +295,9 @@ export function useApplicationPods(
{
...withError(`Unable to get pods for ${appName}`),
enabled: !!app,
refetchInterval() {
return options?.autoRefreshRate ?? false;
},
}
);
}