mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Navigate back to last viewed catalog catagory (#3163)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
e49576ee8c
commit
7058193295
@ -36,13 +36,15 @@ import { CatalogAddButton } from "./catalog-add-button";
|
|||||||
import type { RouteComponentProps } from "react-router";
|
import type { RouteComponentProps } from "react-router";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import { MainLayout } from "../layout/main-layout";
|
import { MainLayout } from "../layout/main-layout";
|
||||||
import { 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 { 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";
|
||||||
|
|
||||||
|
export const previousActiveTab = createAppStorage("catalog-previous-active-tab", "");
|
||||||
|
|
||||||
enum sortBy {
|
enum sortBy {
|
||||||
name = "name",
|
name = "name",
|
||||||
kind = "kind",
|
kind = "kind",
|
||||||
@ -83,6 +85,8 @@ export class Catalog extends React.Component<Props> {
|
|||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
this.catalogEntityStore.watch(),
|
this.catalogEntityStore.watch(),
|
||||||
reaction(() => this.routeActiveTab, async (routeTab) => {
|
reaction(() => this.routeActiveTab, async (routeTab) => {
|
||||||
|
previousActiveTab.set(this.routeActiveTab);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await when(() => (routeTab === "" || !!catalogCategoryRegistry.items.find(i => i.getId() === routeTab)), { timeout: 5_000 }); // we need to wait because extensions might take a while to load
|
await when(() => (routeTab === "" || !!catalogCategoryRegistry.items.find(i => i.getId() === routeTab)), { timeout: 5_000 }); // we need to wait because extensions might take a while to load
|
||||||
const item = catalogCategoryRegistry.items.find(i => i.getId() === routeTab);
|
const item = catalogCategoryRegistry.items.find(i => i.getId() === routeTab);
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
|||||||
import type { Cluster } from "../../../main/cluster";
|
import type { Cluster } from "../../../main/cluster";
|
||||||
import { ClusterStore } from "../../../common/cluster-store";
|
import { ClusterStore } from "../../../common/cluster-store";
|
||||||
import type { ClusterViewRouteParams } from "../../../common/routes";
|
import type { ClusterViewRouteParams } from "../../../common/routes";
|
||||||
|
import { previousActiveTab } from "../+catalog";
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
||||||
}
|
}
|
||||||
@ -43,7 +44,9 @@ export const ClusterTopbar = observer((props: Props) => {
|
|||||||
<TopBar label={getCluster()?.name}>
|
<TopBar label={getCluster()?.name}>
|
||||||
<div>
|
<div>
|
||||||
<MaterialTooltip title="Back to Catalog" placement="left">
|
<MaterialTooltip title="Back to Catalog" placement="left">
|
||||||
<Icon style={{ cursor: "default" }} material="close" onClick={() => navigate(catalogURL())}/>
|
<Icon style={{ cursor: "default" }} material="close" onClick={() => {
|
||||||
|
navigate(`${catalogURL()}/${previousActiveTab.get()}`);
|
||||||
|
}}/>
|
||||||
</MaterialTooltip>
|
</MaterialTooltip>
|
||||||
</div>
|
</div>
|
||||||
</TopBar>
|
</TopBar>
|
||||||
|
|||||||
@ -33,6 +33,7 @@ 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> {
|
||||||
}
|
}
|
||||||
@ -84,7 +85,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()); // redirect to catalog when active cluster get disconnected/not available
|
navigate(`${catalogURL()}/${previousActiveTab.get()}`); // redirect to catalog when active cluster get disconnected/not available
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -41,8 +41,11 @@ const storage = observable({
|
|||||||
* @param defaultValue
|
* @param defaultValue
|
||||||
*/
|
*/
|
||||||
export function createStorage<T>(key: string, defaultValue: T) {
|
export function createStorage<T>(key: string, defaultValue: T) {
|
||||||
|
return createAppStorage(key, defaultValue, getHostedClusterId());
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createAppStorage<T>(key: string, defaultValue: T, clusterId?: string | undefined) {
|
||||||
const { logPrefix } = StorageHelper;
|
const { logPrefix } = StorageHelper;
|
||||||
const clusterId = getHostedClusterId();
|
|
||||||
const folder = path.resolve((app || remote.app).getPath("userData"), "lens-local-storage");
|
const folder = path.resolve((app || remote.app).getPath("userData"), "lens-local-storage");
|
||||||
const fileName = `${clusterId ?? "app"}.json`;
|
const fileName = `${clusterId ?? "app"}.json`;
|
||||||
const filePath = path.resolve(folder, fileName);
|
const filePath = path.resolve(folder, fileName);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user