17971a10cc
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
30 lines
759 B
TypeScript
30 lines
759 B
TypeScript
import { useQuery } from 'react-query';
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
import { withError } from '@/react-tools/react-query';
|
|
|
|
import { Stack, StackId } from '../types';
|
|
|
|
import { stacksQueryKeys } from './query-keys';
|
|
import { buildStackUrl } from './buildUrl';
|
|
|
|
export function useStack(stackId?: StackId) {
|
|
return useQuery(
|
|
stacksQueryKeys.stackFile(stackId || 0),
|
|
() => getStack(stackId!),
|
|
{
|
|
...withError('Unable to retrieve stack'),
|
|
enabled: !!stackId,
|
|
}
|
|
);
|
|
}
|
|
|
|
async function getStack(stackId: StackId) {
|
|
try {
|
|
const { data } = await axios.get<Stack>(buildStackUrl(stackId));
|
|
return data;
|
|
} catch (err) {
|
|
throw parseAxiosError(err, 'Unable to retrieve stack');
|
|
}
|
|
}
|