1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 00:09:40 +02:00

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>
This commit is contained in:
Ali 2025-04-10 16:08:24 +12:00 committed by GitHub
parent 46eddbe7b9
commit 0ca9321db1
57 changed files with 2635 additions and 222 deletions

View file

@ -2,55 +2,33 @@ import { useQuery } from '@tanstack/react-query';
import { EnvironmentId } from '@/react/portainer/environments/types';
import { withGlobalError } from '@/react-tools/react-query';
import PortainerError from 'Portainer/error';
import axios, { parseAxiosError } from '@/portainer/services/axios';
interface HelmRelease {
name: string;
chart: string;
app_version: string;
}
/**
* List all helm releases based on passed in options
* @param environmentId - Environment ID
* @param options - Options for filtering releases
* @returns List of helm releases
*/
export async function listReleases(
environmentId: EnvironmentId,
options: {
namespace?: string;
filter?: string;
selector?: string;
output?: string;
} = {}
): Promise<HelmRelease[]> {
try {
const { namespace, filter, selector, output } = options;
const url = `endpoints/${environmentId}/kubernetes/helm`;
const { data } = await axios.get<HelmRelease[]>(url, {
params: { namespace, filter, selector, output },
});
return data;
} catch (e) {
throw parseAxiosError(e as Error, 'Unable to retrieve release list');
}
}
import { HelmRelease } from '../../types';
/**
* React hook to fetch a specific Helm release
*/
export function useHelmRelease(
export function useHelmRelease<T = HelmRelease>(
environmentId: EnvironmentId,
name: string,
namespace: string
namespace: string,
options: {
select?: (data: HelmRelease) => T;
showResources?: boolean;
} = {}
) {
return useQuery(
[environmentId, 'helm', namespace, name],
() => getHelmRelease(environmentId, name, namespace),
[environmentId, 'helm', 'releases', namespace, name, options.showResources],
() =>
getHelmRelease(environmentId, name, {
namespace,
showResources: options.showResources,
}),
{
enabled: !!environmentId,
enabled: !!environmentId && !!name && !!namespace,
...withGlobalError('Unable to retrieve helm application details'),
select: options.select,
}
);
}
@ -61,23 +39,20 @@ export function useHelmRelease(
async function getHelmRelease(
environmentId: EnvironmentId,
name: string,
namespace: string
): Promise<HelmRelease> {
params: {
namespace: string;
showResources?: boolean;
}
) {
try {
const releases = await listReleases(environmentId, {
filter: `^${name}$`,
namespace,
});
if (releases.length > 0) {
return releases[0];
}
throw new PortainerError(`Release ${name} not found`);
} catch (err) {
throw new PortainerError(
'Unable to retrieve helm application details',
err as Error
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');
}
}