1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

update catalog url params on category change (#3102)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-06-18 14:09:04 +03:00 committed by GitHub
parent e9a89f396f
commit d812e28639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ import { MainLayout } from "../layout/main-layout";
import { cssNames } from "../../utils"; import { 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 type { 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";
@ -83,22 +83,17 @@ export class Catalog extends React.Component<Props> {
this.catalogEntityStore = new CatalogEntityStore(); this.catalogEntityStore = new CatalogEntityStore();
disposeOnUnmount(this, [ disposeOnUnmount(this, [
this.catalogEntityStore.watch(), this.catalogEntityStore.watch(),
when(() => catalogCategoryRegistry.items.length > 0, () => { reaction(() => this.routeActiveTab, async (routeTab) => {
const item = catalogCategoryRegistry.items.find(i => i.getId() === this.routeActiveTab); await when(() => catalogCategoryRegistry.items.length > 0);
const item = catalogCategoryRegistry.items.find(i => i.getId() === routeTab);
if (item || this.routeActiveTab === undefined) { if (item || routeTab === undefined) {
this.activeTab = this.routeActiveTab; this.activeTab = routeTab;
this.catalogEntityStore.activeCategory = item; this.catalogEntityStore.activeCategory = item;
} else { } else {
Notifications.error(<p>Unknown category: {this.routeActiveTab}</p>); Notifications.error(<p>Unknown category: {routeTab}</p>);
} }
}), }, {fireImmediately: true}),
reaction(() => catalogCategoryRegistry.items, (items) => {
if (!this.activeTab && items.length > 0) {
this.activeTab = items[0].getId();
this.catalogEntityStore.activeCategory = items[0];
}
}),
]); ]);
} }
@ -135,8 +130,11 @@ export class Catalog extends React.Component<Props> {
onTabChange = (tabId: string | null) => { onTabChange = (tabId: string | null) => {
const activeCategory = this.categories.find(category => category.getId() === tabId); const activeCategory = this.categories.find(category => category.getId() === tabId);
this.catalogEntityStore.activeCategory = activeCategory; if (activeCategory) {
this.activeTab = activeCategory?.getId(); navigate(catalogURL({ params: {group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }}));
} else {
navigate(catalogURL());
}
}; };
renderNavigation() { renderNavigation() {