mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
PageRegistration / PageMenuRegistration fixes & more simplification (#1386)
* PageRegistration & PageMenuRegistration fixes & more simplification, fix #1383 Signed-off-by: Roman <ixrock@gmail.com> * clean up test, deprecate page.routePath Signed-off-by: Roman <ixrock@gmail.com> * fix: proper `isActive` state matching for page-menu-target to page considering current document location Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
596e60a6f3
commit
13dbdac2f2
12 files changed
+147
-93
No files matched your search
@@ -29,7 +29,6 @@ import { CustomResources } from "./+custom-resources/custom-resources";
|
||||
import { crdRoute } from "./+custom-resources";
|
||||
import { isAllowedResource } from "../../common/rbac";
|
||||
import { MainLayout } from "./layout/main-layout";
|
||||
import { TabLayout, TabLayoutRoute } from "./layout/tab-layout";
|
||||
import { ErrorBoundary } from "./error-boundary";
|
||||
import { Terminal } from "./dock/terminal";
|
||||
import { getHostedCluster, getHostedClusterId } from "../../common/cluster-store";
|
||||
@@ -37,7 +36,6 @@ import logger from "../../main/logger";
|
||||
import { clusterIpc } from "../../common/cluster-ipc";
|
||||
import { webFrame } from "electron";
|
||||
import { clusterPageRegistry } from "../../extensions/registries/page-registry";
|
||||
import { clusterPageMenuRegistry } from "../../extensions/registries";
|
||||
import { extensionLoader } from "../../extensions/extension-loader";
|
||||
import { appEventBus } from "../../common/event-bus";
|
||||
import whatInput from 'what-input';
|
||||
@@ -75,10 +73,7 @@ export class App extends React.Component {
|
||||
|
||||
renderExtensionRoutes() {
|
||||
return clusterPageRegistry.getItems().map(({ components: { Page }, exact, routePath }) => {
|
||||
const Component = () => {
|
||||
return <Page/>
|
||||
};
|
||||
return <Route key={routePath} path={routePath} exact={exact} component={Component}/>
|
||||
return <Route key={routePath} path={routePath} exact={exact} component={Page}/>
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { ClusterIcon } from "../cluster-icon";
|
||||
import { Icon } from "../icon";
|
||||
import { autobind, cssNames, IClassName } from "../../utils";
|
||||
import { Badge } from "../badge";
|
||||
import { isActiveRoute, navigate } from "../../navigation";
|
||||
import { navigate, navigation } from "../../navigation";
|
||||
import { addClusterURL } from "../+add-cluster";
|
||||
import { clusterSettingsURL } from "../+cluster-settings";
|
||||
import { landingURL } from "../+landing-page";
|
||||
@@ -22,8 +22,7 @@ import { Tooltip } from "../tooltip";
|
||||
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";
|
||||
import { getExtensionPageUrl, globalPageMenuRegistry, globalPageRegistry } from "../../../extensions/registries";
|
||||
|
||||
interface Props {
|
||||
className?: IClassName;
|
||||
@@ -152,13 +151,15 @@ export class ClustersMenu extends React.Component<Props> {
|
||||
{globalPageMenuRegistry.getItems().map(({ title, target, components: { Icon } }) => {
|
||||
const registeredPage = globalPageRegistry.getByPageMenuTarget(target);
|
||||
if (!registeredPage) return;
|
||||
const { routePath, exact } = registeredPage;
|
||||
const { extensionId, id: pageId } = registeredPage;
|
||||
const pageUrl = getExtensionPageUrl({ extensionId, pageId, params: target.params });
|
||||
const isActive = pageUrl === navigation.location.pathname;
|
||||
return (
|
||||
<Icon
|
||||
key={routePath}
|
||||
key={pageUrl}
|
||||
tooltip={title}
|
||||
active={isActiveRoute({ path: routePath, exact })}
|
||||
onClick={() => navigate(compile(routePath)(target.params))}
|
||||
active={isActive}
|
||||
onClick={() => navigate(pageUrl)}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -26,11 +26,10 @@ import { Network } from "../+network";
|
||||
import { crdStore } from "../+custom-resources/crd.store";
|
||||
import { CrdList, crdResourcesRoute, crdRoute, crdURL } from "../+custom-resources";
|
||||
import { CustomResources } from "../+custom-resources/custom-resources";
|
||||
import { isActiveRoute } from "../../navigation";
|
||||
import { isActiveRoute, navigation } from "../../navigation";
|
||||
import { isAllowedResource } from "../../../common/rbac"
|
||||
import { Spinner } from "../spinner";
|
||||
import { clusterPageMenuRegistry, clusterPageRegistry } from "../../../extensions/registries";
|
||||
import { compile } from "path-to-regexp";
|
||||
import { clusterPageMenuRegistry, clusterPageRegistry, getExtensionPageUrl } from "../../../extensions/registries";
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextValue>({ pinned: false });
|
||||
type SidebarContextValue = {
|
||||
@@ -195,15 +194,14 @@ export class Sidebar extends React.Component<Props> {
|
||||
{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)
|
||||
const { extensionId, id: pageId } = registeredPage;
|
||||
const pageUrl = getExtensionPageUrl({ extensionId, pageId, params: target.params });
|
||||
const isActive = pageUrl === navigation.location.pathname;
|
||||
return (
|
||||
<SidebarNavItem
|
||||
key={url}
|
||||
url={url}
|
||||
text={title}
|
||||
icon={<Icon/>}
|
||||
isActive={isActiveRoute({ path: routePath, exact })}
|
||||
key={pageUrl} url={pageUrl}
|
||||
text={title} icon={<Icon/>}
|
||||
isActive={isActive}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
Reference in new issue
Block a user