Files
helm-dashboard/frontend/src/API/repositories.ts
yuri-sakharov c9b8fb7809 Introduced tsconfig.app.json and tsconfig.base.json + Refactored eslint.config.js to the latest structure (#652)
* 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
2026-02-15 17:41:04 +00:00

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),
});
}