1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 15:29:42 +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

@ -0,0 +1,70 @@
import { NodeList, Node } from 'kubernetes-types/core/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';
const queryKeys = {
node: (environmentId: number, nodeName: string) => [
'environments',
environmentId,
'kubernetes',
'nodes',
nodeName,
],
nodes: (environmentId: number) => [
'environments',
environmentId,
'kubernetes',
'nodes',
],
};
async function getNode(environmentId: EnvironmentId, nodeName: string) {
const { data: node } = await axios.get<Node>(
`/endpoints/${environmentId}/kubernetes/api/v1/nodes/${nodeName}`
);
return node;
}
export function useNodeQuery(environmentId: EnvironmentId, nodeName: string) {
return useQuery(
queryKeys.node(environmentId, nodeName),
() => getNode(environmentId, nodeName),
{
...withError(
'Unable to get node details from the Kubernetes api',
'Failed to get node details'
),
}
);
}
// getNodes is used to get a list of nodes using the kubernetes API
async function getNodes(environmentId: EnvironmentId) {
const { data: nodeList } = await axios.get<NodeList>(
`/endpoints/${environmentId}/kubernetes/api/v1/nodes`
);
return nodeList.items;
}
// useNodesQuery is used to get an array of nodes using the kubernetes API
export function useNodesQuery(
environmentId: EnvironmentId,
options?: { autoRefreshRate?: number }
) {
return useQuery(
queryKeys.nodes(environmentId),
async () => getNodes(environmentId),
{
...withError(
'Failed to get nodes from the Kubernetes api',
'Failed to get nodes'
),
refetchInterval() {
return options?.autoRefreshRate ?? false;
},
}
);
}