mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
navigation refactoring, move out buildUrl to common/utils so react and react-router not required as package.json dependecies in runtime (main)
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
8097ca5af8
commit
457171dd00
@ -207,7 +207,6 @@
|
|||||||
"openid-client": "^3.15.2",
|
"openid-client": "^3.15.2",
|
||||||
"path-to-regexp": "^6.1.0",
|
"path-to-regexp": "^6.1.0",
|
||||||
"proper-lockfile": "^4.1.1",
|
"proper-lockfile": "^4.1.1",
|
||||||
"react-router": "^5.2.0",
|
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"request-promise-native": "^1.0.8",
|
"request-promise-native": "^1.0.8",
|
||||||
"semver": "^7.3.2",
|
"semver": "^7.3.2",
|
||||||
@ -313,6 +312,7 @@
|
|||||||
"react": "^16.14.0",
|
"react": "^16.14.0",
|
||||||
"react-beautiful-dnd": "^13.0.0",
|
"react-beautiful-dnd": "^13.0.0",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
|
"react-router": "^5.2.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-select": "^3.1.0",
|
"react-select": "^3.1.0",
|
||||||
"react-window": "^1.8.5",
|
"react-window": "^1.8.5",
|
||||||
|
|||||||
14
src/common/utils/buildUrl.ts
Normal file
14
src/common/utils/buildUrl.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { compile } from "path-to-regexp"
|
||||||
|
|
||||||
|
export interface IURLParams<P extends object = {}, Q extends object = {}> {
|
||||||
|
params?: P;
|
||||||
|
query?: Q;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildURL<P extends object = {}, Q extends object = {}>(path: string | any) {
|
||||||
|
const pathBuilder = compile(String(path));
|
||||||
|
return function ({ params, query }: IURLParams<P, Q> = {}) {
|
||||||
|
const queryParams = query ? new URLSearchParams(Object.entries(query)).toString() : ""
|
||||||
|
return pathBuilder(params) + (queryParams ? `?${queryParams}` : "")
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,6 @@
|
|||||||
import { action, computed, observable, toJS } from "mobx";
|
import { action, computed, observable, toJS } from "mobx";
|
||||||
import { BaseStore } from "./base-store";
|
import { BaseStore } from "./base-store";
|
||||||
import { clusterStore } from "./cluster-store"
|
import { clusterStore } from "./cluster-store"
|
||||||
import { landingURL } from "../renderer/components/+landing-page/landing-page.route";
|
|
||||||
import { navigate } from "../renderer/navigation";
|
|
||||||
|
|
||||||
export type WorkspaceId = string;
|
export type WorkspaceId = string;
|
||||||
|
|
||||||
@ -56,18 +54,13 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
setActive(id = WorkspaceStore.defaultId, { redirectToLanding = true, resetActiveCluster = true } = {}) {
|
setActive(id = WorkspaceStore.defaultId, reset = true) {
|
||||||
if (id === this.currentWorkspaceId) return;
|
if (id === this.currentWorkspaceId) return;
|
||||||
if (!this.getById(id)) {
|
if (!this.getById(id)) {
|
||||||
throw new Error(`workspace ${id} doesn't exist`);
|
throw new Error(`workspace ${id} doesn't exist`);
|
||||||
}
|
}
|
||||||
this.currentWorkspaceId = id;
|
this.currentWorkspaceId = id;
|
||||||
if (resetActiveCluster) {
|
clusterStore.activeClusterId = null; // fixme: handle previously selected cluster from current workspace
|
||||||
clusterStore.setActive(null)
|
|
||||||
}
|
|
||||||
if (redirectToLanding) {
|
|
||||||
navigate(landingURL())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const addClusterRoute: RouteProps = {
|
export const addClusterRoute: RouteProps = {
|
||||||
path: "/add-cluster"
|
path: "/add-cluster"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
import { appsRoute } from "../+apps/apps.route";
|
import { appsRoute } from "../+apps/apps.route";
|
||||||
import { buildURL } from "../../navigation";
|
|
||||||
|
|
||||||
export const helmChartsRoute: RouteProps = {
|
export const helmChartsRoute: RouteProps = {
|
||||||
path: appsRoute.path + "/charts/:repo?/:chartName?"
|
path: appsRoute.path + "/charts/:repo?/:chartName?"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
import { appsRoute } from "../+apps/apps.route";
|
import { appsRoute } from "../+apps/apps.route";
|
||||||
import { buildURL } from "../../navigation";
|
|
||||||
|
|
||||||
export const releaseRoute: RouteProps = {
|
export const releaseRoute: RouteProps = {
|
||||||
path: appsRoute.path + "/releases/:namespace?/:name?"
|
path: appsRoute.path + "/releases/:namespace?/:name?"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const appsRoute: RouteProps = {
|
export const appsRoute: RouteProps = {
|
||||||
path: "/apps",
|
path: "/apps",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { IClusterViewRouteParams } from "../cluster-manager/cluster-view.route";
|
import type { IClusterViewRouteParams } from "../cluster-manager/cluster-view.route";
|
||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export interface IClusterSettingsRouteParams extends IClusterViewRouteParams {
|
export interface IClusterSettingsRouteParams extends IClusterViewRouteParams {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const clusterRoute: RouteProps = {
|
export const clusterRoute: RouteProps = {
|
||||||
path: "/cluster"
|
path: "/cluster"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const hpaRoute: RouteProps = {
|
export const hpaRoute: RouteProps = {
|
||||||
path: "/hpa"
|
path: "/hpa"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const configMapsRoute: RouteProps = {
|
export const configMapsRoute: RouteProps = {
|
||||||
path: "/configmaps"
|
path: "/configmaps"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const pdbRoute: RouteProps = {
|
export const pdbRoute: RouteProps = {
|
||||||
path: "/poddisruptionbudgets"
|
path: "/poddisruptionbudgets"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const resourceQuotaRoute: RouteProps = {
|
export const resourceQuotaRoute: RouteProps = {
|
||||||
path: "/resourcequotas"
|
path: "/resourcequotas"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const secretsRoute: RouteProps = {
|
export const secretsRoute: RouteProps = {
|
||||||
path: "/secrets"
|
path: "/secrets"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RouteProps } from "react-router";
|
import { RouteProps } from "react-router";
|
||||||
import { configMapsURL } from "../+config-maps";
|
|
||||||
import { Config } from "./config";
|
import { Config } from "./config";
|
||||||
import { IURLParams } from "../../navigation";
|
import { IURLParams } from "../../../common/utils/buildUrl";
|
||||||
|
import { configMapsURL } from "../+config-maps/config-maps.route";
|
||||||
|
|
||||||
export const configRoute: RouteProps = {
|
export const configRoute: RouteProps = {
|
||||||
get path() {
|
get path() {
|
||||||
|
|||||||
@ -10,8 +10,8 @@ import { resourceQuotaRoute, ResourceQuotas, resourceQuotaURL } from "../+config
|
|||||||
import { PodDisruptionBudgets, pdbRoute, pdbURL } from "../+config-pod-disruption-budgets";
|
import { PodDisruptionBudgets, pdbRoute, pdbURL } from "../+config-pod-disruption-budgets";
|
||||||
import { configURL } from "./config.route";
|
import { configURL } from "./config.route";
|
||||||
import { HorizontalPodAutoscalers, hpaRoute, hpaURL } from "../+config-autoscalers";
|
import { HorizontalPodAutoscalers, hpaRoute, hpaURL } from "../+config-autoscalers";
|
||||||
import { buildURL } from "../../navigation";
|
|
||||||
import { isAllowedResource } from "../../../common/rbac"
|
import { isAllowedResource } from "../../../common/rbac"
|
||||||
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const certificatesURL = buildURL("/certificates");
|
export const certificatesURL = buildURL("/certificates");
|
||||||
export const issuersURL = buildURL("/issuers");
|
export const issuersURL = buildURL("/issuers");
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const crdRoute: RouteProps = {
|
export const crdRoute: RouteProps = {
|
||||||
path: "/crd"
|
path: "/crd"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const eventRoute: RouteProps = {
|
export const eventRoute: RouteProps = {
|
||||||
path: "/events"
|
path: "/events"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const landingRoute: RouteProps = {
|
export const landingRoute: RouteProps = {
|
||||||
path: "/landing"
|
path: "/landing"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const namespacesRoute: RouteProps = {
|
export const namespacesRoute: RouteProps = {
|
||||||
path: "/namespaces"
|
path: "/namespaces"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const endpointRoute: RouteProps = {
|
export const endpointRoute: RouteProps = {
|
||||||
path: "/endpoints"
|
path: "/endpoints"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const ingressRoute: RouteProps = {
|
export const ingressRoute: RouteProps = {
|
||||||
path: "/ingresses"
|
path: "/ingresses"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const networkPoliciesRoute: RouteProps = {
|
export const networkPoliciesRoute: RouteProps = {
|
||||||
path: "/network-policies"
|
path: "/network-policies"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const servicesRoute: RouteProps = {
|
export const servicesRoute: RouteProps = {
|
||||||
path: "/services"
|
path: "/services"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RouteProps } from "react-router"
|
import { RouteProps } from "react-router"
|
||||||
import { Network } from "./network";
|
import { Network } from "./network";
|
||||||
import { servicesURL } from "../+network-services";
|
import { servicesURL } from "../+network-services";
|
||||||
import { IURLParams } from "../../navigation";
|
import { IURLParams } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const networkRoute: RouteProps = {
|
export const networkRoute: RouteProps = {
|
||||||
get path() {
|
get path() {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const nodesRoute: RouteProps = {
|
export const nodesRoute: RouteProps = {
|
||||||
path: "/nodes"
|
path: "/nodes"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const podSecurityPoliciesRoute: RouteProps = {
|
export const podSecurityPoliciesRoute: RouteProps = {
|
||||||
path: "/pod-security-policies"
|
path: "/pod-security-policies"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const preferencesRoute: RouteProps = {
|
export const preferencesRoute: RouteProps = {
|
||||||
path: "/preferences"
|
path: "/preferences"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const storageClassesRoute: RouteProps = {
|
export const storageClassesRoute: RouteProps = {
|
||||||
path: "/storage-classes"
|
path: "/storage-classes"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const volumeClaimsRoute: RouteProps = {
|
export const volumeClaimsRoute: RouteProps = {
|
||||||
path: "/persistent-volume-claims"
|
path: "/persistent-volume-claims"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const volumesRoute: RouteProps = {
|
export const volumesRoute: RouteProps = {
|
||||||
path: "/persistent-volumes"
|
path: "/persistent-volumes"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RouteProps } from "react-router"
|
import { RouteProps } from "react-router"
|
||||||
import { volumeClaimsURL } from "../+storage-volume-claims";
|
import { volumeClaimsURL } from "../+storage-volume-claims";
|
||||||
import { Storage } from "./storage";
|
import { Storage } from "./storage";
|
||||||
import { IURLParams } from "../../navigation";
|
import { IURLParams } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const storageRoute: RouteProps = {
|
export const storageRoute: RouteProps = {
|
||||||
get path() {
|
get path() {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
|
import { buildURL, IURLParams } from "../../../common/utils/buildUrl";
|
||||||
import { UserManagement } from "./user-management"
|
import { UserManagement } from "./user-management"
|
||||||
import { buildURL, IURLParams } from "../../navigation";
|
|
||||||
|
|
||||||
export const usersManagementRoute: RouteProps = {
|
export const usersManagementRoute: RouteProps = {
|
||||||
get path() {
|
get path() {
|
||||||
@ -30,9 +30,7 @@ export interface IRolesRouteParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// URL-builders
|
// URL-builders
|
||||||
|
export const usersManagementURL = (params?: IURLParams) => serviceAccountsURL(params);
|
||||||
export const serviceAccountsURL = buildURL<IServiceAccountsRouteParams>(serviceAccountsRoute.path)
|
export const serviceAccountsURL = buildURL<IServiceAccountsRouteParams>(serviceAccountsRoute.path)
|
||||||
export const roleBindingsURL = buildURL<IRoleBindingsRouteParams>(roleBindingsRoute.path)
|
export const roleBindingsURL = buildURL<IRoleBindingsRouteParams>(roleBindingsRoute.path)
|
||||||
export const rolesURL = buildURL<IRoleBindingsRouteParams>(rolesRoute.path)
|
export const rolesURL = buildURL<IRoleBindingsRouteParams>(rolesRoute.path)
|
||||||
export const usersManagementURL = (params?: IURLParams) => {
|
|
||||||
return serviceAccountsURL(params);
|
|
||||||
};
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const whatsNewRoute: RouteProps = {
|
export const whatsNewRoute: RouteProps = {
|
||||||
path: "/what-s-new"
|
path: "/what-s-new"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RouteProps } from "react-router"
|
import type { RouteProps } from "react-router";
|
||||||
import { Workloads } from "./workloads";
|
import { buildURL, IURLParams } from "../../../common/utils/buildUrl";
|
||||||
import { buildURL, IURLParams } from "../../navigation";
|
|
||||||
import { KubeResource } from "../../../common/rbac";
|
import { KubeResource } from "../../../common/rbac";
|
||||||
|
import { Workloads } from "./workloads";
|
||||||
|
|
||||||
export const workloadsRoute: RouteProps = {
|
export const workloadsRoute: RouteProps = {
|
||||||
get path() {
|
get path() {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../navigation";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
export const workspacesRoute: RouteProps = {
|
export const workspacesRoute: RouteProps = {
|
||||||
path: "/workspaces"
|
path: "/workspaces"
|
||||||
|
|||||||
@ -11,14 +11,16 @@ import { Workspaces, workspacesRoute } from "../+workspaces";
|
|||||||
import { AddCluster, addClusterRoute } from "../+add-cluster";
|
import { AddCluster, addClusterRoute } from "../+add-cluster";
|
||||||
import { ClusterView } from "./cluster-view";
|
import { ClusterView } from "./cluster-view";
|
||||||
import { ClusterSettings, clusterSettingsRoute } from "../+cluster-settings";
|
import { ClusterSettings, clusterSettingsRoute } from "../+cluster-settings";
|
||||||
import { clusterViewRoute, clusterViewURL, getMatchedCluster, getMatchedClusterId } from "./cluster-view.route";
|
import { clusterViewRoute, clusterViewURL } from "./cluster-view.route";
|
||||||
import { clusterStore } from "../../../common/cluster-store";
|
import { clusterStore } from "../../../common/cluster-store";
|
||||||
import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views";
|
import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views";
|
||||||
import { isMac } from "../../../common/vars";
|
import { getMatchedClusterId } from "../../navigation";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterManager extends React.Component {
|
export class ClusterManager extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
const getMatchedCluster = () => clusterStore.getById(getMatchedClusterId());
|
||||||
|
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(getMatchedClusterId, initView, {
|
reaction(getMatchedClusterId, initView, {
|
||||||
fireImmediately: true
|
fireImmediately: true
|
||||||
@ -55,7 +57,7 @@ export class ClusterManager extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div className="ClusterManager">
|
<div className="ClusterManager">
|
||||||
<main>
|
<main>
|
||||||
<div id="lens-views" />
|
<div id="lens-views"/>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route component={LandingPage} {...landingRoute} />
|
<Route component={LandingPage} {...landingRoute} />
|
||||||
<Route component={Preferences} {...preferencesRoute} />
|
<Route component={Preferences} {...preferencesRoute} />
|
||||||
@ -63,11 +65,11 @@ export class ClusterManager extends React.Component {
|
|||||||
<Route component={AddCluster} {...addClusterRoute} />
|
<Route component={AddCluster} {...addClusterRoute} />
|
||||||
<Route component={ClusterView} {...clusterViewRoute} />
|
<Route component={ClusterView} {...clusterViewRoute} />
|
||||||
<Route component={ClusterSettings} {...clusterSettingsRoute} />
|
<Route component={ClusterSettings} {...clusterSettingsRoute} />
|
||||||
<Redirect exact to={this.startUrl} />
|
<Redirect exact to={this.startUrl}/>
|
||||||
</Switch>
|
</Switch>
|
||||||
</main>
|
</main>
|
||||||
<ClustersMenu />
|
<ClustersMenu/>
|
||||||
<BottomBar />
|
<BottomBar/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
import { reaction } from "mobx";
|
import type { RouteProps } from "react-router";
|
||||||
import { ipcRenderer } from "electron";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
import { matchPath, RouteProps } from "react-router";
|
|
||||||
import { buildURL, navigation } from "../../navigation";
|
|
||||||
import { clusterStore } from "../../../common/cluster-store";
|
|
||||||
|
|
||||||
export interface IClusterViewRouteParams {
|
export interface IClusterViewRouteParams {
|
||||||
clusterId: string;
|
clusterId: string;
|
||||||
@ -14,33 +11,3 @@ export const clusterViewRoute: RouteProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const clusterViewURL = buildURL<IClusterViewRouteParams>(clusterViewRoute.path)
|
export const clusterViewURL = buildURL<IClusterViewRouteParams>(clusterViewRoute.path)
|
||||||
|
|
||||||
export function getMatchedClusterId(): string {
|
|
||||||
const matched = matchPath<IClusterViewRouteParams>(navigation.location.pathname, {
|
|
||||||
exact: true,
|
|
||||||
path: clusterViewRoute.path
|
|
||||||
})
|
|
||||||
if (matched) {
|
|
||||||
return matched.params.clusterId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getMatchedCluster() {
|
|
||||||
return clusterStore.getById(getMatchedClusterId())
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ipcRenderer) {
|
|
||||||
if (process.isMainFrame) {
|
|
||||||
// Keep track of active cluster-id for handling IPC/menus/etc.
|
|
||||||
reaction(() => getMatchedClusterId(), clusterId => {
|
|
||||||
ipcRenderer.send("cluster-view:current-id", clusterId);
|
|
||||||
}, {
|
|
||||||
fireImmediately: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reload dashboard
|
|
||||||
ipcRenderer.on("menu:reload", () => {
|
|
||||||
location.reload();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { observable, when } from "mobx";
|
import { observable, when } from "mobx";
|
||||||
import { ClusterId, clusterStore, getClusterFrameUrl } from "../../../common/cluster-store";
|
import { ClusterId, clusterStore, getClusterFrameUrl } from "../../../common/cluster-store";
|
||||||
import { getMatchedCluster } from "./cluster-view.route"
|
import { getMatchedClusterId } from "../../navigation";
|
||||||
import logger from "../../../main/logger";
|
import logger from "../../../main/logger";
|
||||||
|
|
||||||
export interface LensView {
|
export interface LensView {
|
||||||
@ -51,7 +51,7 @@ export async function autoCleanOnRemove(clusterId: ClusterId, iframe: HTMLIFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function refreshViews() {
|
export function refreshViews() {
|
||||||
const cluster = getMatchedCluster();
|
const cluster = clusterStore.getById(getMatchedClusterId());
|
||||||
lensViews.forEach(({ clusterId, view, isLoaded }) => {
|
lensViews.forEach(({ clusterId, view, isLoaded }) => {
|
||||||
const isCurrent = clusterId === cluster?.id;
|
const isCurrent = clusterId === cluster?.id;
|
||||||
const isReady = cluster?.available && cluster?.ready;
|
const isReady = cluster?.available && cluster?.ready;
|
||||||
|
|||||||
@ -1,22 +1,16 @@
|
|||||||
// Navigation helpers
|
// Navigation helpers
|
||||||
|
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
import { compile } from "path-to-regexp"
|
import { matchPath } from "react-router";
|
||||||
import { createBrowserHistory, createMemoryHistory, LocationDescriptor } from "history";
|
import { reaction } from "mobx";
|
||||||
import { createObservableHistory } from "mobx-observable-history";
|
import { createObservableHistory } from "mobx-observable-history";
|
||||||
|
import { createBrowserHistory, createMemoryHistory, LocationDescriptor } from "history";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
|
import { clusterViewRoute, IClusterViewRouteParams } from "./components/cluster-manager/cluster-view.route";
|
||||||
|
|
||||||
export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory();
|
export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory();
|
||||||
export const navigation = createObservableHistory(history);
|
export const navigation = createObservableHistory(history);
|
||||||
|
|
||||||
// handle navigation from other process (e.g. system menus in main, common->cluster view interactions)
|
|
||||||
if (ipcRenderer) {
|
|
||||||
ipcRenderer.on("menu:navigate", (event, location: LocationDescriptor) => {
|
|
||||||
logger.info(`[IPC]: ${event.type} ${JSON.stringify(location)}`, event);
|
|
||||||
navigate(location);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function navigate(location: LocationDescriptor) {
|
export function navigate(location: LocationDescriptor) {
|
||||||
const currentLocation = navigation.getPath();
|
const currentLocation = navigation.getPath();
|
||||||
navigation.push(location);
|
navigation.push(location);
|
||||||
@ -25,20 +19,6 @@ export function navigate(location: LocationDescriptor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IURLParams<P = {}, Q = {}> {
|
|
||||||
params?: P;
|
|
||||||
query?: IQueryParams & Q;
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: extract building urls to commons (also used in menu.ts)
|
|
||||||
// fixme: missing types validation for params & query
|
|
||||||
export function buildURL<P extends object, Q = object>(path: string | string[]) {
|
|
||||||
const pathBuilder = compile(path.toString());
|
|
||||||
return function ({ params, query }: IURLParams<P, Q> = {}) {
|
|
||||||
return pathBuilder(params) + (query ? getQueryString(query, false) : "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// common params for all pages
|
// common params for all pages
|
||||||
export interface IQueryParams {
|
export interface IQueryParams {
|
||||||
namespaces?: string[]; // selected context namespaces
|
namespaces?: string[]; // selected context namespaces
|
||||||
@ -100,3 +80,33 @@ export function setSearch(text: string) {
|
|||||||
export function getSearch() {
|
export function getSearch() {
|
||||||
return navigation.searchParams.get("search") || "";
|
return navigation.searchParams.get("search") || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getMatchedClusterId(): string {
|
||||||
|
const matched = matchPath<IClusterViewRouteParams>(navigation.location.pathname, {
|
||||||
|
exact: true,
|
||||||
|
path: clusterViewRoute.path
|
||||||
|
});
|
||||||
|
return matched?.params.clusterId;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-- EVENTS
|
||||||
|
|
||||||
|
if (process.isMainFrame) {
|
||||||
|
// Keep track of active cluster-id for handling IPC/menus/etc.
|
||||||
|
reaction(() => getMatchedClusterId(), clusterId => {
|
||||||
|
ipcRenderer.send("cluster-view:current-id", clusterId);
|
||||||
|
}, {
|
||||||
|
fireImmediately: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle navigation via IPC (e.g. from top menu)
|
||||||
|
ipcRenderer.on("menu:navigate", (event, location: LocationDescriptor) => {
|
||||||
|
logger.info(`[IPC]: ${event.type} ${JSON.stringify(location)}`, event);
|
||||||
|
navigate(location);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reload dashboard window
|
||||||
|
ipcRenderer.on("menu:reload", () => {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user