2023-09-04 18:07:29 +00:00
|
|
|
import { useQuery } from 'react-query';
|
2023-09-07 14:14:03 +00:00
|
|
|
import { SystemVersion } from 'docker-types/generated/1.41';
|
2023-09-04 18:07:29 +00:00
|
|
|
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
|
|
|
|
|
|
import { buildUrl } from './build-url';
|
|
|
|
|
|
|
|
export async function getVersion(environmentId: EnvironmentId) {
|
|
|
|
try {
|
2023-09-07 14:14:03 +00:00
|
|
|
const { data } = await axios.get<SystemVersion>(
|
2023-09-04 18:07:29 +00:00
|
|
|
buildUrl(environmentId, 'version')
|
|
|
|
);
|
|
|
|
return data;
|
|
|
|
} catch (err) {
|
|
|
|
throw parseAxiosError(err as Error, 'Unable to retrieve version');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-07 14:14:03 +00:00
|
|
|
export function useVersion<TSelect = SystemVersion>(
|
2023-09-04 18:07:29 +00:00
|
|
|
environmentId: EnvironmentId,
|
2023-09-07 14:14:03 +00:00
|
|
|
select?: (info: SystemVersion) => TSelect
|
2023-09-04 18:07:29 +00:00
|
|
|
) {
|
|
|
|
return useQuery(
|
|
|
|
['environment', environmentId, 'docker', 'version'],
|
|
|
|
() => getVersion(environmentId),
|
|
|
|
{
|
|
|
|
select,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2023-09-07 14:14:03 +00:00
|
|
|
|
|
|
|
export function useApiVersion(environmentId: EnvironmentId) {
|
|
|
|
const query = useVersion(environmentId, (info) => info.ApiVersion);
|
|
|
|
return query.data ? parseFloat(query.data) : 0;
|
|
|
|
}
|