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

Fix hotbar active check and accessible namespaces

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-07-28 10:42:23 -04:00
parent 78ea32eaa3
commit 1f0e79cee8
4 changed files with 41 additions and 18 deletions

View File

@ -103,18 +103,20 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
} }
async onContextMenuOpen(context: CatalogEntityContextMenuContext) { async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
context.menuItems.push( if (this.status.phase === "connected" || this.status.phase === "disconnected") {
{ context.menuItems.push(
title: "Open", {
icon: "open_in_full", title: "Open",
onClick: () => this.onRun(), icon: "open_in_full",
}, onClick: () => this.onRun(),
{ },
title: "Open in new window", {
icon: "launch", title: "Open in new window",
onClick: () => requestMain(onNewWindowForClusterHandler, this.getId()), icon: "launch",
}, onClick: () => requestMain(onNewWindowForClusterHandler, this.getId()),
); },
);
}
if (!this.metadata.source || this.metadata.source === "local") { if (!this.metadata.source || this.metadata.source === "local") {
context.menuItems.push( context.menuItems.push(

View File

@ -19,11 +19,12 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import { observable, when } from "mobx"; import { observable, observe, when } from "mobx";
import { ClusterId, ClusterStore, getClusterFrameUrl } from "../../../common/cluster-store"; import { ClusterId, ClusterStore, getClusterFrameUrl } from "../../../common/cluster-store";
import logger from "../../../main/logger"; import logger from "../../../main/logger";
import { requestMain } from "../../../common/ipc"; import { requestMain } from "../../../common/ipc";
import { clusterVisibilityHandler } from "../../../common/cluster-ipc"; import { clusterVisibilityHandler } from "../../../common/cluster-ipc";
import { toJS } from "../../utils";
export interface LensView { export interface LensView {
isLoaded?: boolean isLoaded?: boolean
@ -32,6 +33,11 @@ export interface LensView {
} }
export const lensViews = observable.map<ClusterId, LensView>(); export const lensViews = observable.map<ClusterId, LensView>();
export const visibleCluster = observable.box<ClusterId | undefined>();
observe(lensViews, change => {
console.info(`lensViews change: type=${change.type} name=${change.name}`, toJS((change as any).newValue));
});
export function hasLoadedView(clusterId: ClusterId): boolean { export function hasLoadedView(clusterId: ClusterId): boolean {
return !!lensViews.get(clusterId)?.isLoaded; return !!lensViews.get(clusterId)?.isLoaded;
@ -89,6 +95,8 @@ export function refreshViews(visibleClusterId?: string) {
console.info(`[LENS-VIEW]: refreshing iframe views, visible cluster id=${visibleClusterId}`); console.info(`[LENS-VIEW]: refreshing iframe views, visible cluster id=${visibleClusterId}`);
const cluster = ClusterStore.getInstance().getById(visibleClusterId); const cluster = ClusterStore.getInstance().getById(visibleClusterId);
visibleCluster.set(visibleClusterId);
lensViews.forEach(({ clusterId, view, isLoaded }) => { lensViews.forEach(({ clusterId, view, isLoaded }) => {
const isCurrent = clusterId === cluster?.id; const isCurrent = clusterId === cluster?.id;
const isReady = cluster?.available && cluster?.ready; const isReady = cluster?.available && cluster?.ready;

View File

@ -31,6 +31,7 @@ import { cssNames, IClassName } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { HotbarIcon } from "./hotbar-icon"; import { HotbarIcon } from "./hotbar-icon";
import { HotbarStore } from "../../../common/hotbar-store"; import { HotbarStore } from "../../../common/hotbar-store";
import { visibleCluster } from "../cluster-manager/lens-views";
interface Props extends DOMAttributes<HTMLElement> { interface Props extends DOMAttributes<HTMLElement> {
entity: CatalogEntity; entity: CatalogEntity;
@ -87,7 +88,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
} }
isActive(item: CatalogEntity) { isActive(item: CatalogEntity) {
return catalogEntityRegistry.activeEntity?.metadata?.uid == item.getId(); return visibleCluster.get() === item.getId();
} }
isPersisted(entity: CatalogEntity) { isPersisted(entity: CatalogEntity) {
@ -98,14 +99,14 @@ export class HotbarEntityIcon extends React.Component<Props> {
if (!this.contextMenu) { if (!this.contextMenu) {
return null; return null;
} }
const { const {
entity, errorClass, add, remove, entity, errorClass, add, remove,
index, children, ...elemProps index, children, ...elemProps
} = this.props; } = this.props;
const active = this.isActive(entity);
const className = cssNames("HotbarEntityIcon", this.props.className, { const className = cssNames("HotbarEntityIcon", this.props.className, {
interactive: true, interactive: true,
active: this.isActive(entity), active,
disabled: !entity disabled: !entity
}); });
@ -129,7 +130,6 @@ export class HotbarEntityIcon extends React.Component<Props> {
await entity.onContextMenuOpen(this.contextMenu); await entity.onContextMenuOpen(this.contextMenu);
}; };
const isActive = this.isActive(entity);
return ( return (
<HotbarIcon <HotbarIcon
@ -140,7 +140,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
material={entity.spec.icon?.material} material={entity.spec.icon?.material}
background={entity.spec.icon?.background} background={entity.spec.icon?.background}
className={className} className={className}
active={isActive} active={active}
onMenuOpen={onOpen} onMenuOpen={onOpen}
menuItems={this.contextMenu.menuItems} menuItems={this.contextMenu.menuItems}
tooltip={`${entity.metadata.name} (${entity.metadata.source})`} tooltip={`${entity.metadata.name} (${entity.metadata.source})`}

View File

@ -28,6 +28,7 @@ import { isMac } from "../../common/vars";
import { ClusterStore } from "../../common/cluster-store"; import { ClusterStore } from "../../common/cluster-store";
import { navigate } from "../navigation"; import { navigate } from "../navigation";
import { entitySettingsURL } from "../../common/routes"; import { entitySettingsURL } from "../../common/routes";
import { visibleCluster } from "../components/cluster-manager/lens-views";
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void { function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
notificationsStore.remove(notificationId); notificationsStore.remove(notificationId);
@ -80,6 +81,18 @@ const listNamespacesForbiddenHandlerDisplayedAt = new Map<string, number>();
const intervalBetweenNotifications = 1000 * 60; // 60s const intervalBetweenNotifications = 1000 * 60; // 60s
function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]: ListNamespaceForbiddenArgs): void { function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]: ListNamespaceForbiddenArgs): void {
const cluster = ClusterStore.getInstance().getById(clusterId);
if (!cluster) {
return void console.warn("[IPC]: ListNamespacesForbiddenHandler was called with unknown clusterId", { clusterId });
}
const visibileClusterId = visibleCluster.get();
if (visibileClusterId && visibileClusterId !== clusterId) {
return void console.debug("[IPC]: ListNamespacesForbiddenHandler not displaying notification that is not about the currently active cluster");
}
const lastDisplayedAt = listNamespacesForbiddenHandlerDisplayedAt.get(clusterId); const lastDisplayedAt = listNamespacesForbiddenHandlerDisplayedAt.get(clusterId);
const wasDisplayed = Boolean(lastDisplayedAt); const wasDisplayed = Boolean(lastDisplayedAt);
const now = Date.now(); const now = Date.now();