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:
parent
78ea32eaa3
commit
1f0e79cee8
@ -103,18 +103,20 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
|
||||
}
|
||||
|
||||
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||
context.menuItems.push(
|
||||
{
|
||||
title: "Open",
|
||||
icon: "open_in_full",
|
||||
onClick: () => this.onRun(),
|
||||
},
|
||||
{
|
||||
title: "Open in new window",
|
||||
icon: "launch",
|
||||
onClick: () => requestMain(onNewWindowForClusterHandler, this.getId()),
|
||||
},
|
||||
);
|
||||
if (this.status.phase === "connected" || this.status.phase === "disconnected") {
|
||||
context.menuItems.push(
|
||||
{
|
||||
title: "Open",
|
||||
icon: "open_in_full",
|
||||
onClick: () => this.onRun(),
|
||||
},
|
||||
{
|
||||
title: "Open in new window",
|
||||
icon: "launch",
|
||||
onClick: () => requestMain(onNewWindowForClusterHandler, this.getId()),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.metadata.source || this.metadata.source === "local") {
|
||||
context.menuItems.push(
|
||||
|
||||
@ -19,11 +19,12 @@
|
||||
* 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 logger from "../../../main/logger";
|
||||
import { requestMain } from "../../../common/ipc";
|
||||
import { clusterVisibilityHandler } from "../../../common/cluster-ipc";
|
||||
import { toJS } from "../../utils";
|
||||
|
||||
export interface LensView {
|
||||
isLoaded?: boolean
|
||||
@ -32,6 +33,11 @@ export interface 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 {
|
||||
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}`);
|
||||
const cluster = ClusterStore.getInstance().getById(visibleClusterId);
|
||||
|
||||
visibleCluster.set(visibleClusterId);
|
||||
|
||||
lensViews.forEach(({ clusterId, view, isLoaded }) => {
|
||||
const isCurrent = clusterId === cluster?.id;
|
||||
const isReady = cluster?.available && cluster?.ready;
|
||||
|
||||
@ -31,6 +31,7 @@ import { cssNames, IClassName } from "../../utils";
|
||||
import { Icon } from "../icon";
|
||||
import { HotbarIcon } from "./hotbar-icon";
|
||||
import { HotbarStore } from "../../../common/hotbar-store";
|
||||
import { visibleCluster } from "../cluster-manager/lens-views";
|
||||
|
||||
interface Props extends DOMAttributes<HTMLElement> {
|
||||
entity: CatalogEntity;
|
||||
@ -87,7 +88,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
||||
}
|
||||
|
||||
isActive(item: CatalogEntity) {
|
||||
return catalogEntityRegistry.activeEntity?.metadata?.uid == item.getId();
|
||||
return visibleCluster.get() === item.getId();
|
||||
}
|
||||
|
||||
isPersisted(entity: CatalogEntity) {
|
||||
@ -98,14 +99,14 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
||||
if (!this.contextMenu) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
entity, errorClass, add, remove,
|
||||
index, children, ...elemProps
|
||||
} = this.props;
|
||||
const active = this.isActive(entity);
|
||||
const className = cssNames("HotbarEntityIcon", this.props.className, {
|
||||
interactive: true,
|
||||
active: this.isActive(entity),
|
||||
active,
|
||||
disabled: !entity
|
||||
});
|
||||
|
||||
@ -129,7 +130,6 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
||||
|
||||
await entity.onContextMenuOpen(this.contextMenu);
|
||||
};
|
||||
const isActive = this.isActive(entity);
|
||||
|
||||
return (
|
||||
<HotbarIcon
|
||||
@ -140,7 +140,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
||||
material={entity.spec.icon?.material}
|
||||
background={entity.spec.icon?.background}
|
||||
className={className}
|
||||
active={isActive}
|
||||
active={active}
|
||||
onMenuOpen={onOpen}
|
||||
menuItems={this.contextMenu.menuItems}
|
||||
tooltip={`${entity.metadata.name} (${entity.metadata.source})`}
|
||||
|
||||
@ -28,6 +28,7 @@ import { isMac } from "../../common/vars";
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import { navigate } from "../navigation";
|
||||
import { entitySettingsURL } from "../../common/routes";
|
||||
import { visibleCluster } from "../components/cluster-manager/lens-views";
|
||||
|
||||
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
|
||||
notificationsStore.remove(notificationId);
|
||||
@ -80,6 +81,18 @@ const listNamespacesForbiddenHandlerDisplayedAt = new Map<string, number>();
|
||||
const intervalBetweenNotifications = 1000 * 60; // 60s
|
||||
|
||||
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 wasDisplayed = Boolean(lastDisplayedAt);
|
||||
const now = Date.now();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user