From 6b123dc4c0638ba8596584cb7afae691f8523abc Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Wed, 29 Sep 2021 09:04:54 +0300 Subject: [PATCH] Redirect from /catalog to last catalog page (#3807) * Redirect from /catalog to last catalog page Signed-off-by: Alex Andreev * Cleaning up Signed-off-by: Alex Andreev * Cleaning up more Signed-off-by: Alex Andreev * Splitting url params to pass in catalogURL() Signed-off-by: Alex Andreev --- src/common/routes/catalog.ts | 13 +++++++++++++ src/renderer/components/+catalog/catalog.tsx | 10 +++++----- .../components/cluster-manager/cluster-manager.tsx | 4 +++- .../components/cluster-manager/cluster-view.tsx | 3 +-- src/renderer/components/layout/topbar.tsx | 3 +-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/common/routes/catalog.ts b/src/common/routes/catalog.ts index 1221e931d0..7759d13b62 100644 --- a/src/common/routes/catalog.ts +++ b/src/common/routes/catalog.ts @@ -30,4 +30,17 @@ export const catalogRoute: RouteProps = { path: "/catalog/:group?/:kind?" }; +export const getPreviousTabUrl = (path: string) => { + const [group, kind] = path.split("/"); + + return catalogURL({ + params: { + group: group || browseCatalogTab, + kind + } + }); +}; + export const catalogURL = buildURL(catalogRoute.path); + +export const browseCatalogTab = "browse"; diff --git a/src/renderer/components/+catalog/catalog.tsx b/src/renderer/components/+catalog/catalog.tsx index fae3b0d797..454a825fd2 100644 --- a/src/renderer/components/+catalog/catalog.tsx +++ b/src/renderer/components/+catalog/catalog.tsx @@ -39,12 +39,12 @@ import { MainLayout } from "../layout/main-layout"; import { createAppStorage, cssNames } from "../../utils"; import { makeCss } from "../../../common/utils/makeCss"; import { CatalogEntityDetails } from "./catalog-entity-details"; -import { catalogURL, CatalogViewRouteParam } from "../../../common/routes"; +import { browseCatalogTab, catalogURL, CatalogViewRouteParam } from "../../../common/routes"; import { CatalogMenu } from "./catalog-menu"; import { HotbarIcon } from "../hotbar/hotbar-icon"; import { RenderDelay } from "../render-delay/render-delay"; -export const previousActiveTab = createAppStorage("catalog-previous-active-tab", ""); +export const previousActiveTab = createAppStorage("catalog-previous-active-tab", browseCatalogTab); enum sortBy { name = "name", @@ -75,7 +75,7 @@ export class Catalog extends React.Component { return `${group}/${kind}`; } - return ""; + return browseCatalogTab; } async componentDidMount() { @@ -89,7 +89,7 @@ export class Catalog extends React.Component { previousActiveTab.set(this.routeActiveTab); try { - await when(() => (routeTab === "" || !!catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab)), { timeout: 5_000 }); // we need to wait because extensions might take a while to load + await when(() => (routeTab === browseCatalogTab || !!catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab)), { timeout: 5_000 }); // we need to wait because extensions might take a while to load const item = catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab); runInAction(() => { @@ -157,7 +157,7 @@ export class Catalog extends React.Component { if (activeCategory) { navigate(catalogURL({ params: {group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }})); } else { - navigate(catalogURL()); + navigate(catalogURL({ params: { group: browseCatalogTab }})); } }; diff --git a/src/renderer/components/cluster-manager/cluster-manager.tsx b/src/renderer/components/cluster-manager/cluster-manager.tsx index 8e041ccc7f..2058707b99 100644 --- a/src/renderer/components/cluster-manager/cluster-manager.tsx +++ b/src/renderer/components/cluster-manager/cluster-manager.tsx @@ -25,7 +25,7 @@ import React from "react"; import { Redirect, Route, Switch } from "react-router"; import { disposeOnUnmount, observer } from "mobx-react"; import { BottomBar } from "./bottom-bar"; -import { Catalog } from "../+catalog"; +import { Catalog, previousActiveTab } from "../+catalog"; import { Preferences } from "../+preferences"; import { AddCluster } from "../+add-cluster"; import { ClusterView } from "./cluster-view"; @@ -40,6 +40,7 @@ import { reaction } from "mobx"; import { navigation } from "../../navigation"; import { setEntityOnRouteMatch } from "../../../main/catalog-sources/helpers/general-active-sync"; import { TopBar } from "../layout/topbar"; +import { catalogURL, getPreviousTabUrl } from "../../../common/routes"; @observer export class ClusterManager extends React.Component { @@ -56,6 +57,7 @@ export class ClusterManager extends React.Component {
+ diff --git a/src/renderer/components/cluster-manager/cluster-view.tsx b/src/renderer/components/cluster-manager/cluster-view.tsx index db48e051c8..78626cccb1 100644 --- a/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/src/renderer/components/cluster-manager/cluster-view.tsx @@ -33,7 +33,6 @@ import { clusterActivateHandler } from "../../../common/cluster-ipc"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { navigate } from "../../navigation"; import { catalogURL, ClusterViewRouteParams } from "../../../common/routes"; -import { previousActiveTab } from "../+catalog"; interface Props extends RouteComponentProps { } @@ -85,7 +84,7 @@ export class ClusterView extends React.Component { const disconnected = values[1]; if (hasLoadedView(this.clusterId) && disconnected) { - navigate(`${catalogURL()}/${previousActiveTab.get()}`); // redirect to catalog when active cluster get disconnected/not available + navigate(catalogURL()); // redirect to catalog when active cluster get disconnected/not available } }), ]); diff --git a/src/renderer/components/layout/topbar.tsx b/src/renderer/components/layout/topbar.tsx index 1532fa89d4..9348cfa359 100644 --- a/src/renderer/components/layout/topbar.tsx +++ b/src/renderer/components/layout/topbar.tsx @@ -30,7 +30,6 @@ import { ipcRendererOn } from "../../../common/ipc"; import { watchHistoryState } from "../../remote-helpers/history-updater"; import { isActiveRoute, navigate } from "../../navigation"; import { catalogRoute, catalogURL } from "../../../common/routes"; -import { previousActiveTab } from "../+catalog"; interface Props extends React.HTMLAttributes { } @@ -72,7 +71,7 @@ export const TopBar = observer(({ children, ...rest }: Props) => { }; const goHome = () => { - navigate(`${catalogURL()}/${previousActiveTab.get()}`); + navigate(catalogURL()); }; const goBack = () => {