mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-26 14:28:04 +00:00
* Introduced tsconfig.app.json and tsconfig.base.json * yarn.lock * Introduced tsconfig.app.json, tsconfig.base.jsonfig. * Refactored eslint.config.js to latest structure * Returned previous recommended rules. * More rules * Force import rules * Check * Check * Cleanup ESLint configuration and plugins * Cleanup heap: "writable",DD_RUM: "writable" from ESLint configuration * "scripts" moved to the top of package.json
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import {
|
|
type UseMutationOptions,
|
|
type UseQueryOptions,
|
|
useMutation,
|
|
useQuery,
|
|
} from "@tanstack/react-query";
|
|
|
|
import apiService from "./apiService";
|
|
import type { HelmRepositories } from "./interfaces";
|
|
|
|
// Get list of Helm repositories
|
|
export function useGetRepositories(
|
|
options?: UseQueryOptions<HelmRepositories>
|
|
) {
|
|
return useQuery<HelmRepositories>({
|
|
queryKey: ["helm", "repositories"],
|
|
queryFn: () =>
|
|
apiService.fetchWithSafeDefaults<HelmRepositories>({
|
|
url: "/api/helm/repositories",
|
|
fallback: [],
|
|
}),
|
|
select: (data) => data?.sort((a, b) => a?.name?.localeCompare(b?.name)),
|
|
...(options ?? {}),
|
|
});
|
|
}
|
|
|
|
// Update repository from remote
|
|
export function useUpdateRepo(
|
|
repo: string,
|
|
options?: UseMutationOptions<string, Error>
|
|
) {
|
|
return useMutation<string, Error>({
|
|
mutationFn: () => {
|
|
return apiService.fetchWithDefaults<string>(
|
|
`/api/helm/repositories/${repo}`,
|
|
{
|
|
method: "POST",
|
|
}
|
|
);
|
|
},
|
|
...(options ?? {}),
|
|
});
|
|
}
|
|
|
|
// Remove repository
|
|
export function useDeleteRepo(
|
|
repo: string,
|
|
options?: UseMutationOptions<string, Error>
|
|
) {
|
|
return useMutation<string, Error>({
|
|
mutationFn: () => {
|
|
return apiService.fetchWithDefaults<string>(
|
|
`/api/helm/repositories/${repo}`,
|
|
{
|
|
method: "DELETE",
|
|
}
|
|
);
|
|
},
|
|
...(options ?? {}),
|
|
});
|
|
}
|
|
|
|
export function useChartRepoValues({
|
|
version,
|
|
chart,
|
|
}: {
|
|
version: string;
|
|
chart: string;
|
|
}) {
|
|
return useQuery<string>({
|
|
queryKey: ["helm", "repositories", "values", chart, version],
|
|
queryFn: () =>
|
|
apiService.fetchWithDefaults<string>(
|
|
`/api/helm/repositories/values?chart=${chart}&version=${version}`,
|
|
{
|
|
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
|
}
|
|
),
|
|
enabled: Boolean(version) && Boolean(chart),
|
|
});
|
|
}
|