mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48: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
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
|
|
|
|
import apiService from "./apiService";
|
|
import type {
|
|
K8sResource,
|
|
K8sResourceList,
|
|
KubectlContexts,
|
|
} from "./interfaces";
|
|
|
|
// Get list of kubectl contexts configured locally
|
|
// @ts-expect-error unused
|
|
function useGetKubectlContexts(options?: UseQueryOptions<KubectlContexts>) {
|
|
return useQuery<KubectlContexts>({
|
|
queryKey: ["k8s", "contexts"],
|
|
queryFn: () =>
|
|
apiService.fetchWithSafeDefaults<KubectlContexts>({
|
|
url: "/api/k8s/contexts",
|
|
fallback: { contexts: [] },
|
|
}),
|
|
...(options ?? {}),
|
|
});
|
|
}
|
|
|
|
// Get resources information
|
|
// @ts-expect-error unused
|
|
function useGetK8sResource(
|
|
kind: string,
|
|
name: string,
|
|
namespace: string,
|
|
options?: UseQueryOptions<K8sResource>
|
|
) {
|
|
return useQuery<K8sResource>({
|
|
queryKey: ["k8s", kind, "get", name, namespace],
|
|
queryFn: () =>
|
|
apiService.fetchWithSafeDefaults<K8sResource>({
|
|
url: `/api/k8s/${kind}/get?name=${name}&namespace=${namespace}`,
|
|
fallback: { kind: "", name: "", namespace: "" },
|
|
}),
|
|
...(options ?? {}),
|
|
});
|
|
}
|
|
|
|
// Get list of resources
|
|
// @ts-expect-error unused
|
|
function useGetK8sResourceList(
|
|
kind: string,
|
|
options?: UseQueryOptions<K8sResourceList>
|
|
) {
|
|
return useQuery<K8sResourceList>({
|
|
queryKey: ["k8s", kind, "list"],
|
|
queryFn: () =>
|
|
apiService.fetchWithSafeDefaults<K8sResourceList>({
|
|
url: `/api/k8s/${kind}/list`,
|
|
fallback: { items: [] },
|
|
}),
|
|
...(options ?? {}),
|
|
});
|
|
}
|
|
|
|
// Get describe text for kubernetes resource
|
|
// @ts-expect-error unused
|
|
function useGetK8sResourceDescribe(
|
|
kind: string,
|
|
name: string,
|
|
namespace: string,
|
|
options?: UseQueryOptions<string>
|
|
) {
|
|
return useQuery<string>({
|
|
queryKey: ["k8s", kind, "describe", name, namespace],
|
|
queryFn: () =>
|
|
apiService.fetchWithDefaults<string>(
|
|
`/api/k8s/${kind}/describe?name=${name}&namespace=${namespace}`,
|
|
{
|
|
headers: {
|
|
Accept: "text/plain",
|
|
},
|
|
}
|
|
),
|
|
...(options ?? {}),
|
|
});
|
|
}
|