mirror of
https://github.com/portainer/portainer.git
synced 2025-07-18 21:09:40 +02:00
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
import { withGlobalError } from '@/react-tools/react-query';
|
|
|
|
type Params = {
|
|
/** The name of the chart to get the values for */
|
|
chart: string;
|
|
/** The repository URL or registry ID */
|
|
repo: string;
|
|
/** The version of the chart to get the values for */
|
|
version?: string;
|
|
};
|
|
|
|
async function getHelmChartValues(params: Params) {
|
|
try {
|
|
const response = await axios.get<string>(`/templates/helm/values`, {
|
|
params,
|
|
});
|
|
return response.data;
|
|
} catch (err) {
|
|
throw parseAxiosError(err, 'Unable to get Helm chart values');
|
|
}
|
|
}
|
|
|
|
export function useHelmChartValues(params: Params, isLatestVersion = false) {
|
|
const hasValidRepoUrl = !!params.repo;
|
|
return useQuery({
|
|
queryKey: [
|
|
'helm-chart-values',
|
|
params.repo,
|
|
params.chart,
|
|
// if the latest version is fetched, use the latest version key to cache the latest version
|
|
isLatestVersion ? 'latest' : params.version,
|
|
],
|
|
queryFn: () => getHelmChartValues(params),
|
|
enabled: !!params.chart && hasValidRepoUrl,
|
|
select: (data) => ({
|
|
values: data,
|
|
}),
|
|
retry: 1,
|
|
staleTime: 60 * 1000 * 20, // 60 minutes, because values are not expected to change often
|
|
...withGlobalError('Unable to get Helm chart values'),
|
|
});
|
|
}
|