1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00
portainer/app/react/kubernetes/helm/HelmApplicationView/queries/useHelmRelease.ts
Ali 0ca9321db1 feat(helm): update helm view [r8s-256] (#582)
Co-authored-by: Cara Ryan <cara.ryan@portainer.io>
Co-authored-by: James Player <james.player@portainer.io>
Co-authored-by: stevensbkang <skan070@gmail.com>
2025-04-10 16:08:24 +12:00

58 lines
1.4 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { withGlobalError } from '@/react-tools/react-query';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { HelmRelease } from '../../types';
/**
* React hook to fetch a specific Helm release
*/
export function useHelmRelease<T = HelmRelease>(
environmentId: EnvironmentId,
name: string,
namespace: string,
options: {
select?: (data: HelmRelease) => T;
showResources?: boolean;
} = {}
) {
return useQuery(
[environmentId, 'helm', 'releases', namespace, name, options.showResources],
() =>
getHelmRelease(environmentId, name, {
namespace,
showResources: options.showResources,
}),
{
enabled: !!environmentId && !!name && !!namespace,
...withGlobalError('Unable to retrieve helm application details'),
select: options.select,
}
);
}
/**
* Get a specific Helm release
*/
async function getHelmRelease(
environmentId: EnvironmentId,
name: string,
params: {
namespace: string;
showResources?: boolean;
}
) {
try {
const { data } = await axios.get<HelmRelease>(
`endpoints/${environmentId}/kubernetes/helm/${name}`,
{
params,
}
);
return data;
} catch (err) {
throw parseAxiosError(err, 'Unable to retrieve helm application details');
}
}