Move all RouteParam's and URL builders to src/common (#2778)

- Prevents some circular dependencies

- Allowed main to use them as needed

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-06-10 08:52:09 -04:00
1 parent 540c6dac37
commit 5ee2ab5b4a
134 files changed
+462 -515

No files matched your search

@@ -19,7 +19,6 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
export * from "./workloads.route";
export * from "./workloads";
export * from "./workloads.stores";
export * from "./workloads.command";
@@ -21,46 +21,46 @@
import { navigate } from "../../navigation";
import { commandRegistry } from "../../../extensions/registries/command-registry";
import { cronJobsURL, daemonSetsURL, deploymentsURL, jobsURL, podsURL, statefulSetsURL } from "./workloads.route";
import * as routes from "../../../common/routes";
commandRegistry.add({
id: "cluster.viewPods",
title: "Cluster: View Pods",
scope: "entity",
action: () => navigate(podsURL())
action: () => navigate(routes.podsURL())
});
commandRegistry.add({
id: "cluster.viewDeployments",
title: "Cluster: View Deployments",
scope: "entity",
action: () => navigate(deploymentsURL())
action: () => navigate(routes.deploymentsURL())
});
commandRegistry.add({
id: "cluster.viewDaemonSets",
title: "Cluster: View DaemonSets",
scope: "entity",
action: () => navigate(daemonSetsURL())
action: () => navigate(routes.daemonSetsURL())
});
commandRegistry.add({
id: "cluster.viewStatefulSets",
title: "Cluster: View StatefulSets",
scope: "entity",
action: () => navigate(statefulSetsURL())
action: () => navigate(routes.statefulSetsURL())
});
commandRegistry.add({
id: "cluster.viewJobs",
title: "Cluster: View Jobs",
scope: "entity",
action: () => navigate(jobsURL())
action: () => navigate(routes.jobsURL())
});
commandRegistry.add({
id: "cluster.viewCronJobs",
title: "Cluster: View CronJobs",
scope: "entity",
action: () => navigate(cronJobsURL())
action: () => navigate(routes.cronJobsURL())
});
@@ -1,109 +0,0 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import type { RouteProps } from "react-router";
import { buildURL, IURLParams } from "../../../common/utils/buildUrl";
import type { KubeResource } from "../../../common/rbac";
// Routes
export const overviewRoute: RouteProps = {
path: "/workloads"
};
export const podsRoute: RouteProps = {
path: "/pods"
};
export const deploymentsRoute: RouteProps = {
path: "/deployments"
};
export const daemonSetsRoute: RouteProps = {
path: "/daemonsets"
};
export const statefulSetsRoute: RouteProps = {
path: "/statefulsets"
};
export const replicaSetsRoute: RouteProps = {
path: "/replicasets"
};
export const jobsRoute: RouteProps = {
path: "/jobs"
};
export const cronJobsRoute: RouteProps = {
path: "/cronjobs"
};
export const workloadsRoute: RouteProps = {
path: [
overviewRoute,
podsRoute,
deploymentsRoute,
daemonSetsRoute,
statefulSetsRoute,
replicaSetsRoute,
jobsRoute,
cronJobsRoute
].map(route => route.path.toString())
};
// Route params
export interface IWorkloadsOverviewRouteParams {
}
export interface IPodsRouteParams {
}
export interface IDeploymentsRouteParams {
}
export interface IDaemonSetsRouteParams {
}
export interface IStatefulSetsRouteParams {
}
export interface IReplicaSetsRouteParams {
}
export interface IJobsRouteParams {
}
export interface ICronJobsRouteParams {
}
// URL-builders
export const workloadsURL = (params?: IURLParams) => overviewURL(params);
export const overviewURL = buildURL<IWorkloadsOverviewRouteParams>(overviewRoute.path);
export const podsURL = buildURL<IPodsRouteParams>(podsRoute.path);
export const deploymentsURL = buildURL<IDeploymentsRouteParams>(deploymentsRoute.path);
export const daemonSetsURL = buildURL<IDaemonSetsRouteParams>(daemonSetsRoute.path);
export const statefulSetsURL = buildURL<IStatefulSetsRouteParams>(statefulSetsRoute.path);
export const replicaSetsURL = buildURL<IReplicaSetsRouteParams>(replicaSetsRoute.path);
export const jobsURL = buildURL<IJobsRouteParams>(jobsRoute.path);
export const cronJobsURL = buildURL<ICronJobsRouteParams>(cronJobsRoute.path);
export const workloadURL: Partial<Record<KubeResource, ReturnType<typeof buildURL>>> = {
"pods": podsURL,
"deployments": deploymentsURL,
"daemonsets": daemonSetsURL,
"statefulsets": statefulSetsURL,
"replicasets": replicaSetsURL,
"jobs": jobsURL,
"cronjobs": cronJobsURL,
};
@@ -25,7 +25,6 @@ import React from "react";
import { observer } from "mobx-react";
import { TabLayout, TabLayoutRoute } from "../layout/tab-layout";
import { WorkloadsOverview } from "../+workloads-overview/overview";
import { cronJobsRoute, cronJobsURL, daemonSetsRoute, daemonSetsURL, deploymentsRoute, deploymentsURL, jobsRoute, jobsURL, overviewRoute, overviewURL, podsRoute, podsURL, replicaSetsRoute, replicaSetsURL, statefulSetsRoute, statefulSetsURL } from "./workloads.route";
import { Pods } from "../+workloads-pods";
import { Deployments } from "../+workloads-deployments";
import { DaemonSets } from "../+workloads-daemonsets";
@@ -34,83 +33,84 @@ import { Jobs } from "../+workloads-jobs";
import { CronJobs } from "../+workloads-cronjobs";
import { isAllowedResource } from "../../../common/rbac";
import { ReplicaSets } from "../+workloads-replicasets";
import * as routes from "../../../common/routes";
@observer
export class Workloads extends React.Component {
static get tabRoutes(): TabLayoutRoute[] {
const routes: TabLayoutRoute[] = [
const tabs: TabLayoutRoute[] = [
{
title: "Overview",
component: WorkloadsOverview,
url: overviewURL(),
routePath: overviewRoute.path.toString()
url: routes.overviewURL(),
routePath: routes.overviewRoute.path.toString()
}
];
if (isAllowedResource("pods")) {
routes.push({
tabs.push({
title: "Pods",
component: Pods,
url: podsURL(),
routePath: podsRoute.path.toString()
url: routes.podsURL(),
routePath: routes.podsRoute.path.toString()
});
}
if (isAllowedResource("deployments")) {
routes.push({
tabs.push({
title: "Deployments",
component: Deployments,
url: deploymentsURL(),
routePath: deploymentsRoute.path.toString(),
url: routes.deploymentsURL(),
routePath: routes.deploymentsRoute.path.toString(),
});
}
if (isAllowedResource("daemonsets")) {
routes.push({
tabs.push({
title: "DaemonSets",
component: DaemonSets,
url: daemonSetsURL(),
routePath: daemonSetsRoute.path.toString(),
url: routes.daemonSetsURL(),
routePath: routes.daemonSetsRoute.path.toString(),
});
}
if (isAllowedResource("statefulsets")) {
routes.push({
tabs.push({
title: "StatefulSets",
component: StatefulSets,
url: statefulSetsURL(),
routePath: statefulSetsRoute.path.toString(),
url: routes.statefulSetsURL(),
routePath: routes.statefulSetsRoute.path.toString(),
});
}
if (isAllowedResource("replicasets")) {
routes.push({
tabs.push({
title: "ReplicaSets",
component: ReplicaSets,
url: replicaSetsURL(),
routePath: replicaSetsRoute.path.toString(),
url: routes.replicaSetsURL(),
routePath: routes.replicaSetsRoute.path.toString(),
});
}
if (isAllowedResource("jobs")) {
routes.push({
tabs.push({
title: "Jobs",
component: Jobs,
url: jobsURL(),
routePath: jobsRoute.path.toString(),
url: routes.jobsURL(),
routePath: routes.jobsRoute.path.toString(),
});
}
if (isAllowedResource("cronjobs")) {
routes.push({
tabs.push({
title: "CronJobs",
component: CronJobs,
url: cronJobsURL(),
routePath: cronJobsRoute.path.toString(),
url: routes.cronJobsURL(),
routePath: routes.cronJobsRoute.path.toString(),
});
}
return routes;
return tabs;
}
render() {