mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
introduce PageMenuTarget
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
d3979c2883
commit
d07e199976
9 files changed
+30
-40
No files matched your search
@@ -74,27 +74,8 @@ export class App extends React.Component {
|
||||
}
|
||||
|
||||
renderExtensionRoutes() {
|
||||
return clusterPageRegistry.getItems().map(({ components: { Page }, exact, routePath, subPages }) => {
|
||||
return clusterPageRegistry.getItems().map(({ components: { Page }, exact, routePath }) => {
|
||||
const Component = () => {
|
||||
if (subPages) {
|
||||
const tabs: TabLayoutRoute[] = subPages.map(({ exact, routePath, components: { Page } }) => {
|
||||
const menuItem = clusterPageMenuRegistry.getByRoutePath(routePath);
|
||||
if (!menuItem) return;
|
||||
return {
|
||||
routePath, exact,
|
||||
component: Page,
|
||||
url: menuItem.url,
|
||||
title: menuItem.title,
|
||||
}
|
||||
}).filter(Boolean);
|
||||
if (tabs.length > 0) {
|
||||
return (
|
||||
<Page>
|
||||
<TabLayout tabs={tabs}/>
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
}
|
||||
return <Page/>
|
||||
};
|
||||
return <Route key={routePath} path={routePath} exact={exact} component={Component}/>
|
||||
|
||||
@@ -23,6 +23,7 @@ import { ConfirmDialog } from "../confirm-dialog";
|
||||
import { clusterIpc } from "../../../common/cluster-ipc";
|
||||
import { clusterViewURL } from "./cluster-view.route";
|
||||
import { globalPageMenuRegistry, globalPageRegistry } from "../../../extensions/registries";
|
||||
import { compile } from "path-to-regexp";
|
||||
|
||||
interface Props {
|
||||
className?: IClassName;
|
||||
@@ -148,8 +149,8 @@ export class ClustersMenu extends React.Component<Props> {
|
||||
)}
|
||||
</div>
|
||||
<div className="extensions">
|
||||
{globalPageMenuRegistry.getItems().map(({ title, url, components: { Icon } }) => {
|
||||
const registeredPage = globalPageRegistry.getByUrl(url);
|
||||
{globalPageMenuRegistry.getItems().map(({ title, target, components: { Icon } }) => {
|
||||
const registeredPage = globalPageRegistry.getByPageMenuTarget(target);
|
||||
if (!registeredPage) return;
|
||||
const { routePath, exact } = registeredPage;
|
||||
return (
|
||||
@@ -157,7 +158,7 @@ export class ClustersMenu extends React.Component<Props> {
|
||||
key={routePath}
|
||||
tooltip={title}
|
||||
active={isActiveRoute({ path: routePath, exact })}
|
||||
onClick={() => navigate(url)}
|
||||
onClick={() => navigate(compile(routePath)(target.params))}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -30,6 +30,7 @@ import { isActiveRoute } from "../../navigation";
|
||||
import { isAllowedResource } from "../../../common/rbac"
|
||||
import { Spinner } from "../spinner";
|
||||
import { clusterPageMenuRegistry, clusterPageRegistry } from "../../../extensions/registries";
|
||||
import { compile } from "path-to-regexp";
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextValue>({ pinned: false });
|
||||
type SidebarContextValue = {
|
||||
@@ -191,10 +192,11 @@ export class Sidebar extends React.Component<Props> {
|
||||
>
|
||||
{this.renderCustomResources()}
|
||||
</SidebarNavItem>
|
||||
{clusterPageMenuRegistry.getItems().map(({ title, url, components: { Icon } }) => {
|
||||
const registeredPage = clusterPageRegistry.getByUrl(url);
|
||||
{clusterPageMenuRegistry.getItems().map(({ title, target, components: { Icon } }) => {
|
||||
const registeredPage = clusterPageRegistry.getByPageMenuTarget(target);
|
||||
if (!registeredPage) return;
|
||||
const { routePath, exact } = registeredPage;
|
||||
const url = compile(routePath)(target.params)
|
||||
return (
|
||||
<SidebarNavItem
|
||||
key={url}
|
||||
|
||||
Reference in new issue
Block a user