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

Use entity name as cluster name in sidebar (#3751)

* Using entity name as cluster name in sidebar

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Use entity name if preferences name is empty

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* simplify

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Alex Andreev 2021-09-08 12:44:23 +03:00 committed by GitHub
parent 9ae84182a1
commit ffdf4a03cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 7 deletions

View File

@ -28,6 +28,7 @@ import type { ClusterId } from "../../common/cluster-types";
import { appEventBus } from "../../common/event-bus"; import { appEventBus } from "../../common/event-bus";
import { dialogShowOpenDialogHandler, ipcMainHandle } from "../../common/ipc"; import { dialogShowOpenDialogHandler, ipcMainHandle } from "../../common/ipc";
import { catalogEntityRegistry } from "../catalog"; import { catalogEntityRegistry } from "../catalog";
import { pushCatalogToRenderer } from "../catalog-pusher";
import { ClusterManager } from "../cluster-manager"; import { ClusterManager } from "../cluster-manager";
import { bundledKubectlPath } from "../kubectl"; import { bundledKubectlPath } from "../kubectl";
import logger from "../logger"; import logger from "../logger";
@ -48,6 +49,8 @@ export function initIpcMainHandlers() {
if (cluster) { if (cluster) {
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId }); clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
cluster.pushState(); cluster.pushState();
pushCatalogToRenderer(catalogEntityRegistry);
} }
}); });

View File

@ -42,7 +42,7 @@ export function GeneralSettings({ entity }: EntitySettingViewProps) {
<section> <section>
<div className="flex"> <div className="flex">
<div className="flex-grow pr-8"> <div className="flex-grow pr-8">
<components.ClusterNameSetting cluster={cluster} /> <components.ClusterNameSetting cluster={cluster} entity={entity as KubernetesCluster} />
</div> </div>
<div> <div>
<components.ClusterIconSetting cluster={cluster} entity={entity as KubernetesCluster} /> <components.ClusterIconSetting cluster={cluster} entity={entity as KubernetesCluster} />

View File

@ -26,9 +26,11 @@ import { observable, autorun, makeObservable } from "mobx";
import { observer, disposeOnUnmount } from "mobx-react"; import { observer, disposeOnUnmount } from "mobx-react";
import { SubTitle } from "../../layout/sub-title"; import { SubTitle } from "../../layout/sub-title";
import { isRequired } from "../../input/input_validators"; import { isRequired } from "../../input/input_validators";
import type { KubernetesCluster } from "../../../../common/catalog-entities";
interface Props { interface Props {
cluster: Cluster; cluster: Cluster;
entity: KubernetesCluster;
} }
@observer @observer
@ -43,7 +45,7 @@ export class ClusterNameSetting extends React.Component<Props> {
componentDidMount() { componentDidMount() {
disposeOnUnmount(this, disposeOnUnmount(this,
autorun(() => { autorun(() => {
this.name = this.props.cluster.preferences.clusterName; this.name = this.props.cluster.preferences.clusterName || this.props.entity.metadata.name;
}) })
); );
} }

View File

@ -40,8 +40,7 @@ import { SidebarItem } from "./sidebar-item";
import { Apps } from "../+apps"; import { Apps } from "../+apps";
import * as routes from "../../../common/routes"; import * as routes from "../../../common/routes";
import { Config } from "../+config"; import { Config } from "../+config";
import { ClusterStore } from "../../../common/cluster-store"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { App } from "../app";
interface Props { interface Props {
className?: string; className?: string;
@ -178,14 +177,20 @@ export class Sidebar extends React.Component<Props> {
}); });
} }
get clusterEntity() {
return catalogEntityRegistry.activeEntity;
}
render() { render() {
const { className } = this.props; const { className } = this.props;
return ( return (
<div className={cssNames(Sidebar.displayName, "flex column", className)}> <div className={cssNames(Sidebar.displayName, "flex column", className)}>
{this.clusterEntity && (
<div className="cluster-name"> <div className="cluster-name">
{ClusterStore.getInstance().getById(App.clusterId)?.name} {this.clusterEntity.metadata.name}
</div> </div>
)}
<div className={cssNames("sidebar-nav flex column box grow-fixed")}> <div className={cssNames("sidebar-nav flex column box grow-fixed")}>
<SidebarItem <SidebarItem
id="cluster" id="cluster"