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

+12 -16
View File
@@ -20,24 +20,20 @@
*/
import React from "react";
import { addClusterURL } from "../components/+add-cluster";
import { catalogURL } from "../components/+catalog";
import { attemptInstallByInfo, extensionsURL } from "../components/+extensions";
import { preferencesURL } from "../components/+preferences";
import { clusterViewURL } from "../components/cluster-manager/cluster-view.route";
import { attemptInstallByInfo } from "../components/+extensions";
import { LensProtocolRouterRenderer } from "./router";
import { navigate } from "../navigation/helpers";
import { entitySettingsURL } from "../components/+entity-settings";
import { catalogEntityRegistry } from "../api/catalog-entity-registry";
import { ClusterStore } from "../../common/cluster-store";
import { EXTENSION_NAME_MATCH, EXTENSION_PUBLISHER_MATCH, LensProtocolRouter } from "../../common/protocol-handler";
import { Notifications } from "../components/notifications";
import * as routes from "../../common/routes";
export function bindProtocolAddRouteHandlers() {
LensProtocolRouterRenderer
.getInstance()
.addInternalHandler("/preferences", ({ search: { highlight }}) => {
navigate(preferencesURL({ fragment: highlight }));
navigate(routes.preferencesURL({ fragment: highlight }));
})
.addInternalHandler("/", ({ tail }) => {
if (tail) {
@@ -49,26 +45,26 @@ export function bindProtocolAddRouteHandlers() {
);
}
navigate(catalogURL());
navigate(routes.catalogURL());
})
.addInternalHandler("/landing", () => {
navigate(catalogURL());
navigate(routes.catalogURL());
})
.addInternalHandler("/landing/view/:group/:kind", ({ pathname: { group, kind } }) => {
navigate(catalogURL({
navigate(routes.catalogURL({
params: {
group, kind
}
}));
})
.addInternalHandler("/cluster", () => {
navigate(addClusterURL());
navigate(routes.addClusterURL());
})
.addInternalHandler("/entity/:entityId/settings", ({ pathname: { entityId } }) => {
const entity = catalogEntityRegistry.getById(entityId);
if (entity) {
navigate(entitySettingsURL({ params: { entityId } }));
navigate(routes.entitySettingsURL({ params: { entityId } }));
} else {
Notifications.shortInfo(
<p>
@@ -82,7 +78,7 @@ export function bindProtocolAddRouteHandlers() {
const cluster = ClusterStore.getInstance().getById(clusterId);
if (cluster) {
navigate(clusterViewURL({ params: { clusterId } }));
navigate(routes.clusterViewURL({ params: { clusterId } }));
} else {
Notifications.shortInfo(
<p>
@@ -95,7 +91,7 @@ export function bindProtocolAddRouteHandlers() {
const cluster = ClusterStore.getInstance().getById(clusterId);
if (cluster) {
navigate(entitySettingsURL({ params: { entityId: clusterId } }));
navigate(routes.entitySettingsURL({ params: { entityId: clusterId } }));
} else {
Notifications.shortInfo(
<p>
@@ -105,7 +101,7 @@ export function bindProtocolAddRouteHandlers() {
}
})
.addInternalHandler("/extensions", () => {
navigate(extensionsURL());
navigate(routes.extensionsURL());
})
.addInternalHandler(`/extensions/install${LensProtocolRouter.ExtensionUrlSchema}`, ({ pathname, search: { version } }) => {
const name = [
@@ -114,7 +110,7 @@ export function bindProtocolAddRouteHandlers() {
].filter(Boolean)
.join("/");
navigate(extensionsURL());
navigate(routes.extensionsURL());
attemptInstallByInfo({ name, version, requireConfirmation: true });
});
}