mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Enable deep navigation/routing to catalog (#2818)
* Enable route-based navigation to catalog items Signed-off-by: Alex Culliere <alozhkin@mirantis.com> Co-authored-by: Sebastian Malton <sebastian@malton.name> * Enable custom protocol handle to process routing in catalog Signed-off-by: Alex Culliere <alozhkin@mirantis.com> Co-authored-by: Sebastian Malton <sebastian@malton.name> * Fix type imports Signed-off-by: Alex Culliere <alozhkin@mirantis.com> Co-authored-by: Alex Culliere <alozhkin@mirantis.com>
This commit is contained in:
parent
1664b393ee
commit
27d230d12b
@ -22,8 +22,12 @@
|
|||||||
import type { RouteProps } from "react-router";
|
import type { RouteProps } from "react-router";
|
||||||
import { buildURL } from "../../../common/utils/buildUrl";
|
import { buildURL } from "../../../common/utils/buildUrl";
|
||||||
|
|
||||||
|
export interface ICatalogViewRouteParam {
|
||||||
|
group?: string;
|
||||||
|
kind?: string;
|
||||||
|
}
|
||||||
export const catalogRoute: RouteProps = {
|
export const catalogRoute: RouteProps = {
|
||||||
path: "/catalog"
|
path: "/catalog/:group?/:kind?"
|
||||||
};
|
};
|
||||||
|
|
||||||
export const catalogURL = buildURL(catalogRoute.path);
|
export const catalogURL = buildURL<ICatalogViewRouteParam>(catalogRoute.path);
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import "./catalog.scss";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { ItemListLayout } from "../item-object-list";
|
import { ItemListLayout } from "../item-object-list";
|
||||||
import { action, observable, reaction } from "mobx";
|
import { action, observable, reaction, when } from "mobx";
|
||||||
import { CatalogEntityItem, CatalogEntityStore } from "./catalog-entity.store";
|
import { CatalogEntityItem, CatalogEntityStore } from "./catalog-entity.store";
|
||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
import { kebabCase } from "lodash";
|
import { kebabCase } from "lodash";
|
||||||
@ -37,18 +37,33 @@ import { ConfirmDialog } from "../confirm-dialog";
|
|||||||
import { Tab, Tabs } from "../tabs";
|
import { Tab, Tabs } from "../tabs";
|
||||||
import { catalogCategoryRegistry } from "../../../common/catalog";
|
import { catalogCategoryRegistry } from "../../../common/catalog";
|
||||||
import { CatalogAddButton } from "./catalog-add-button";
|
import { CatalogAddButton } from "./catalog-add-button";
|
||||||
|
import type { RouteComponentProps } from "react-router";
|
||||||
|
import type { ICatalogViewRouteParam } from "./catalog.route";
|
||||||
|
import { Notifications } from "../notifications";
|
||||||
|
|
||||||
enum sortBy {
|
enum sortBy {
|
||||||
name = "name",
|
name = "name",
|
||||||
source = "source",
|
source = "source",
|
||||||
status = "status"
|
status = "status"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Props extends RouteComponentProps<ICatalogViewRouteParam> {}
|
||||||
@observer
|
@observer
|
||||||
export class Catalog extends React.Component {
|
export class Catalog extends React.Component<Props> {
|
||||||
@observable private catalogEntityStore?: CatalogEntityStore;
|
@observable private catalogEntityStore?: CatalogEntityStore;
|
||||||
@observable.deep private contextMenu: CatalogEntityContextMenuContext;
|
@observable.deep private contextMenu: CatalogEntityContextMenuContext;
|
||||||
@observable activeTab?: string;
|
@observable activeTab?: string;
|
||||||
|
|
||||||
|
get routeActiveTab(): string | undefined {
|
||||||
|
const { group, kind } = this.props.match.params ?? {};
|
||||||
|
|
||||||
|
if (group && kind) {
|
||||||
|
return `${group}/${kind}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
this.contextMenu = {
|
this.contextMenu = {
|
||||||
menuItems: [],
|
menuItems: [],
|
||||||
@ -57,12 +72,22 @@ export class Catalog extends React.Component {
|
|||||||
this.catalogEntityStore = new CatalogEntityStore();
|
this.catalogEntityStore = new CatalogEntityStore();
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
this.catalogEntityStore.watch(),
|
this.catalogEntityStore.watch(),
|
||||||
|
when(() => catalogCategoryRegistry.items.length > 0, () => {
|
||||||
|
const item = catalogCategoryRegistry.items.find(i => i.getId() === this.routeActiveTab);
|
||||||
|
|
||||||
|
if (item || this.routeActiveTab === undefined) {
|
||||||
|
this.activeTab = this.routeActiveTab;
|
||||||
|
this.catalogEntityStore.activeCategory = item;
|
||||||
|
} else {
|
||||||
|
Notifications.error(<p>Unknown category: {this.routeActiveTab}</p>);
|
||||||
|
}
|
||||||
|
}),
|
||||||
reaction(() => catalogCategoryRegistry.items, (items) => {
|
reaction(() => catalogCategoryRegistry.items, (items) => {
|
||||||
if (!this.activeTab && items.length > 0) {
|
if (!this.activeTab && items.length > 0) {
|
||||||
this.activeTab = items[0].getId();
|
this.activeTab = items[0].getId();
|
||||||
this.catalogEntityStore.activeCategory = items[0];
|
this.catalogEntityStore.activeCategory = items[0];
|
||||||
}
|
}
|
||||||
}, { fireImmediately: true })
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,13 @@ export function bindProtocolAddRouteHandlers() {
|
|||||||
.addInternalHandler("/landing", () => {
|
.addInternalHandler("/landing", () => {
|
||||||
navigate(catalogURL());
|
navigate(catalogURL());
|
||||||
})
|
})
|
||||||
|
.addInternalHandler("/landing/view/:group/:kind", ({ pathname: { group, kind } }) => {
|
||||||
|
navigate(catalogURL({
|
||||||
|
params: {
|
||||||
|
group, kind
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
})
|
||||||
.addInternalHandler("/cluster", () => {
|
.addInternalHandler("/cluster", () => {
|
||||||
navigate(addClusterURL());
|
navigate(addClusterURL());
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user