Commit de6e86b8 authored by Sebastian Malton's avatar Sebastian Malton
Browse files

Fix CustomResourceDefinitions not being navigable


- Make buildURL more type safe
Signed-off-by: default avatarSebastian Malton <sebastian@malton.name>
parent 06ec1b39
Showing with 44 additions and 72 deletions
+44 -72
......@@ -5,7 +5,7 @@
import { KubeCreationError, KubeObject } from "../kube-object";
import { KubeApi } from "../kube-api";
import { crdResourcesURL } from "../../routes";
import { customResourceDefinitionsURL } from "../../routes";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeJsonApiData } from "../kube-json-api";
......@@ -99,7 +99,7 @@ export class CustomResourceDefinition extends KubeObject {
}
getResourceUrl() {
return crdResourcesURL({
return customResourceDefinitionsURL({
params: {
group: this.getGroup(),
name: this.getPluralName(),
......
......@@ -11,7 +11,7 @@ import { helmChartStore } from "../../../renderer/components/+helm-charts/helm-c
import type { ItemObject } from "../../item.store";
import { KubeObject } from "../kube-object";
import type { JsonApiData } from "../json-api";
import { buildURLPositional } from "../../utils/buildUrl";
import { buildURL } from "../../utils/buildUrl";
import type { KubeJsonApiData } from "../kube-json-api";
interface IReleasePayload {
......@@ -77,16 +77,16 @@ interface EndpointQuery {
all?: boolean;
}
const endpoint = buildURLPositional<EndpointParams, EndpointQuery>("/v2/releases/:namespace?/:name?/:route?");
const endpoint = buildURL<EndpointParams, EndpointQuery>("/v2/releases/:namespace?/:name?/:route?");
export async function listReleases(namespace?: string): Promise<HelmRelease[]> {
const releases = await apiBase.get<HelmReleaseDto[]>(endpoint({ namespace }));
const releases = await apiBase.get<HelmReleaseDto[]>(endpoint({ params: { namespace }}));
return releases.map(toHelmRelease);
}
export async function getRelease(name: string, namespace: string): Promise<IReleaseDetails> {
const path = endpoint({ name, namespace });
const path = endpoint({ params: { name, namespace }});
const { resources: rawResources, ...details } = await apiBase.get<IReleaseRawDetails>(path);
const resources = rawResources.map(KubeObject.create);
......@@ -115,7 +115,7 @@ export async function updateRelease(name: string, namespace: string, payload: IR
const chart = `${repo}/${rawChart}`;
const values = yaml.load(rawValues);
return apiBase.put(endpoint({ name, namespace }), {
return apiBase.put(endpoint({ params: { name, namespace }}), {
data: {
chart,
values,
......@@ -125,28 +125,28 @@ export async function updateRelease(name: string, namespace: string, payload: IR
}
export async function deleteRelease(name: string, namespace: string): Promise<JsonApiData> {
const path = endpoint({ name, namespace });
const path = endpoint({ params: { name, namespace }});
return apiBase.del(path);
}
export async function getReleaseValues(name: string, namespace: string, all?: boolean): Promise<string> {
const route = "values";
const path = endpoint({ name, namespace, route }, { all });
const path = endpoint({ params: { name, namespace, route }, query: { all }});
return apiBase.get<string>(path);
}
export async function getReleaseHistory(name: string, namespace: string): Promise<IReleaseRevision[]> {
const route = "history";
const path = endpoint({ name, namespace, route });
const path = endpoint({ params: { name, namespace, route }});
return apiBase.get(path);
}
export async function rollbackRelease(name: string, namespace: string, revision: number): Promise<JsonApiData> {
const route = "rollback";
const path = endpoint({ name, namespace, route });
const path = endpoint({ params: { name, namespace, route }});
const data = { revision };
return apiBase.put(path, { data });
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const addClusterRoute: RouteProps = {
path: "/add-cluster",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export interface CatalogViewRouteParam {
group?: string;
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export interface ClusterViewRouteParams {
clusterId: string;
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const clusterRoute: RouteProps = {
path: "/overview",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const configMapsRoute: RouteProps = {
path: "/configmaps",
......
......@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import type { RouteProps as RouterProps } from "react-router";
import type { URLParams } from "../utils/buildUrl";
import { configMapsRoute, configMapsURL } from "./config-maps";
import { hpaRoute } from "./hpa";
......@@ -12,15 +12,15 @@ import { pdbRoute } from "./pod-disruption-budgets";
import { resourceQuotaRoute } from "./resource-quotas";
import { secretsRoute } from "./secrets";
export const configRoute: RouteProps = {
export const configRoute: RouterProps = {
path: [
configMapsRoute,
secretsRoute,
resourceQuotaRoute,
limitRangesRoute,
hpaRoute,
pdbRoute,
].map(route => route.path.toString()),
configMapsRoute.path,
secretsRoute.path,
resourceQuotaRoute.path,
limitRangesRoute.path,
hpaRoute.path,
pdbRoute.path,
],
};
export const configURL = (params?: URLParams) => configMapsURL(params);
......@@ -3,29 +3,17 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const crdRoute: RouteProps = {
path: "/crd",
};
export const crdDefinitionsRoute: RouteProps = {
path: `${crdRoute.path}/definitions`,
};
export const customResourcesRoute = "/crd";
export const crdResourcesRoute: RouteProps = {
path: `${crdRoute.path}/:group/:name`,
export const customResourceDefinitionsRoute: RouteProps = {
path: `${customResourcesRoute}/definitions/:group?/:name?`,
};
export interface CRDListQuery {
groups?: string;
}
export interface CRDRouteParams {
group: string;
name: string;
export interface CustomResourceDefinitionsRouteParams {
group?: string;
name?: string;
}
export const crdURL = buildURL<{}, CRDListQuery>(crdDefinitionsRoute.path);
export const crdResourcesURL = buildURL<CRDRouteParams>(crdResourcesRoute.path);
export const customResourceDefinitionsURL = buildURL<CustomResourceDefinitionsRouteParams>(customResourceDefinitionsRoute.path);
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const endpointRoute: RouteProps = {
path: "/endpoints",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export interface EntitySettingsRouteParams {
entityId: string;
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const eventRoute: RouteProps = {
path: "/events",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const extensionsRoute: RouteProps = {
path: "/extensions",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
import { helmRoute } from "./helm";
export const helmChartsRoute: RouteProps = {
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const helmRoute: RouteProps = {
path: "/helm",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const hpaRoute: RouteProps = {
path: "/hpa",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const ingressRoute: RouteProps = {
path: "/ingresses",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const limitRangesRoute: RouteProps = {
path: "/limitranges",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const namespacesRoute: RouteProps = {
path: "/namespaces",
......
......@@ -3,8 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RouteProps } from "react-router";
import { buildURL } from "../utils/buildUrl";
import { buildURL, RouteProps } from "../utils/buildUrl";
export const networkPoliciesRoute: RouteProps = {
path: "/network-policies",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment