mirror of https://github.com/portainer/portainer
22 lines
702 B
TypeScript
22 lines
702 B
TypeScript
import { Node } from 'docker-types/generated/1.41';
|
|
import { useQuery } from 'react-query';
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
|
|
import { buildUrl } from './build-url';
|
|
import { queryKeys } from './query-keys';
|
|
|
|
export function useNodes(environmentId: EnvironmentId) {
|
|
return useQuery(queryKeys.base(environmentId), () => getNodes(environmentId));
|
|
}
|
|
|
|
async function getNodes(environmentId: EnvironmentId) {
|
|
try {
|
|
const { data } = await axios.get<Array<Node>>(buildUrl(environmentId));
|
|
return data;
|
|
} catch (error) {
|
|
throw parseAxiosError(error, 'Unable to retrieve nodes');
|
|
}
|
|
}
|