mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Redirect from /catalog to last catalog page (#3807)
* Redirect from /catalog to last catalog page Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Cleaning up Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Cleaning up more Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Splitting url params to pass in catalogURL() Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
8bca8dd7dc
commit
6b123dc4c0
@ -30,4 +30,17 @@ export const catalogRoute: RouteProps = {
|
|||||||
path: "/catalog/:group?/:kind?"
|
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<CatalogViewRouteParam>(catalogRoute.path);
|
export const catalogURL = buildURL<CatalogViewRouteParam>(catalogRoute.path);
|
||||||
|
|
||||||
|
export const browseCatalogTab = "browse";
|
||||||
|
|||||||
@ -39,12 +39,12 @@ import { MainLayout } from "../layout/main-layout";
|
|||||||
import { createAppStorage, cssNames } from "../../utils";
|
import { createAppStorage, cssNames } from "../../utils";
|
||||||
import { makeCss } from "../../../common/utils/makeCss";
|
import { makeCss } from "../../../common/utils/makeCss";
|
||||||
import { CatalogEntityDetails } from "./catalog-entity-details";
|
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 { CatalogMenu } from "./catalog-menu";
|
||||||
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
||||||
import { RenderDelay } from "../render-delay/render-delay";
|
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 {
|
enum sortBy {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -75,7 +75,7 @@ export class Catalog extends React.Component<Props> {
|
|||||||
return `${group}/${kind}`;
|
return `${group}/${kind}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return browseCatalogTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
@ -89,7 +89,7 @@ export class Catalog extends React.Component<Props> {
|
|||||||
previousActiveTab.set(this.routeActiveTab);
|
previousActiveTab.set(this.routeActiveTab);
|
||||||
|
|
||||||
try {
|
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);
|
const item = catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab);
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
@ -157,7 +157,7 @@ export class Catalog extends React.Component<Props> {
|
|||||||
if (activeCategory) {
|
if (activeCategory) {
|
||||||
navigate(catalogURL({ params: {group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }}));
|
navigate(catalogURL({ params: {group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }}));
|
||||||
} else {
|
} else {
|
||||||
navigate(catalogURL());
|
navigate(catalogURL({ params: { group: browseCatalogTab }}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import React from "react";
|
|||||||
import { Redirect, Route, Switch } from "react-router";
|
import { Redirect, Route, Switch } from "react-router";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { BottomBar } from "./bottom-bar";
|
import { BottomBar } from "./bottom-bar";
|
||||||
import { Catalog } from "../+catalog";
|
import { Catalog, previousActiveTab } from "../+catalog";
|
||||||
import { Preferences } from "../+preferences";
|
import { Preferences } from "../+preferences";
|
||||||
import { AddCluster } from "../+add-cluster";
|
import { AddCluster } from "../+add-cluster";
|
||||||
import { ClusterView } from "./cluster-view";
|
import { ClusterView } from "./cluster-view";
|
||||||
@ -40,6 +40,7 @@ import { reaction } from "mobx";
|
|||||||
import { navigation } from "../../navigation";
|
import { navigation } from "../../navigation";
|
||||||
import { setEntityOnRouteMatch } from "../../../main/catalog-sources/helpers/general-active-sync";
|
import { setEntityOnRouteMatch } from "../../../main/catalog-sources/helpers/general-active-sync";
|
||||||
import { TopBar } from "../layout/topbar";
|
import { TopBar } from "../layout/topbar";
|
||||||
|
import { catalogURL, getPreviousTabUrl } from "../../../common/routes";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterManager extends React.Component {
|
export class ClusterManager extends React.Component {
|
||||||
@ -56,6 +57,7 @@ export class ClusterManager extends React.Component {
|
|||||||
<main>
|
<main>
|
||||||
<div id="lens-views"/>
|
<div id="lens-views"/>
|
||||||
<Switch>
|
<Switch>
|
||||||
|
<Redirect exact from={catalogURL()} to={getPreviousTabUrl(previousActiveTab.get())}/>
|
||||||
<Route component={Welcome} {...routes.welcomeRoute} />
|
<Route component={Welcome} {...routes.welcomeRoute} />
|
||||||
<Route component={Catalog} {...routes.catalogRoute} />
|
<Route component={Catalog} {...routes.catalogRoute} />
|
||||||
<Route component={Preferences} {...routes.preferencesRoute} />
|
<Route component={Preferences} {...routes.preferencesRoute} />
|
||||||
|
|||||||
@ -33,7 +33,6 @@ import { clusterActivateHandler } from "../../../common/cluster-ipc";
|
|||||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
import { catalogURL, ClusterViewRouteParams } from "../../../common/routes";
|
import { catalogURL, ClusterViewRouteParams } from "../../../common/routes";
|
||||||
import { previousActiveTab } from "../+catalog";
|
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
||||||
}
|
}
|
||||||
@ -85,7 +84,7 @@ export class ClusterView extends React.Component<Props> {
|
|||||||
const disconnected = values[1];
|
const disconnected = values[1];
|
||||||
|
|
||||||
if (hasLoadedView(this.clusterId) && disconnected) {
|
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
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -30,7 +30,6 @@ import { ipcRendererOn } from "../../../common/ipc";
|
|||||||
import { watchHistoryState } from "../../remote-helpers/history-updater";
|
import { watchHistoryState } from "../../remote-helpers/history-updater";
|
||||||
import { isActiveRoute, navigate } from "../../navigation";
|
import { isActiveRoute, navigate } from "../../navigation";
|
||||||
import { catalogRoute, catalogURL } from "../../../common/routes";
|
import { catalogRoute, catalogURL } from "../../../common/routes";
|
||||||
import { previousActiveTab } from "../+catalog";
|
|
||||||
|
|
||||||
interface Props extends React.HTMLAttributes<any> {
|
interface Props extends React.HTMLAttributes<any> {
|
||||||
}
|
}
|
||||||
@ -72,7 +71,7 @@ export const TopBar = observer(({ children, ...rest }: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const goHome = () => {
|
const goHome = () => {
|
||||||
navigate(`${catalogURL()}/${previousActiveTab.get()}`);
|
navigate(catalogURL());
|
||||||
};
|
};
|
||||||
|
|
||||||
const goBack = () => {
|
const goBack = () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user