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

make getRenderInfoByWorkspace private to Lens only, not extensions

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2020-11-26 10:13:09 -05:00
parent 76f0bdcaca
commit 2daff2da0b
5 changed files with 24 additions and 15 deletions

View File

@ -13,7 +13,7 @@ binaries/client:
yarn download-bins
node_modules:
yarn install --frozen-lockfile --verbose
yarn install --frozen-lockfile
yarn check --verify-tree --integrity
static/build/LensDev.html:

View File

@ -1,5 +1,5 @@
{
"name": "extension-example",
"name": "example-extension",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,

View File

@ -78,19 +78,17 @@ export interface ClusterPrometheusPreferences {
export interface ClusterRenderInfo extends ClusterModel {
DeadError?: LoadKubeError; // this != undefined => dead
isAdmin: boolean;
name: string;
eventCount: number;
online: boolean;
}
export class ClusterStore extends BaseStore<ClusterStoreModel> {
export class LensClusterStoreImpl extends BaseStore<ClusterStoreModel> {
static getCustomKubeConfigPath(clusterId: ClusterId): string {
return path.resolve((app || remote.app).getPath("userData"), "kubeconfigs", clusterId);
}
static embedCustomKubeConfig(clusterId: ClusterId, kubeConfig: KubeConfig | string): string {
const filePath = ClusterStore.getCustomKubeConfigPath(clusterId);
const filePath = LensClusterStoreImpl.getCustomKubeConfigPath(clusterId);
const fileContents = typeof kubeConfig == "string" ? kubeConfig : dumpConfigYaml(kubeConfig);
saveToAppFiles(filePath, fileContents, { mode: 0o600 });
return filePath;
@ -101,7 +99,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
@observable clusters = observable.map<ClusterId, Cluster>();
@observable deadClusters = observable.map<ClusterId, [ClusterModel, LoadKubeError]>();
private constructor() {
protected constructor() {
super({
configName: "lens-cluster-store",
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
@ -202,15 +200,13 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
return this.deadClusters.get(id);
}
getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] {
protected getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] {
const aliveClusters: ClusterRenderInfo[] = this.clustersList.filter(c => c.workspace === workspaceId);
const deadClusters: ClusterRenderInfo[] = this.deadClustersList
.filter(([c]) => c.workspace === workspaceId)
.map(([cluster, error]) => ({
DeadError: error,
name: cluster.contextName,
isAdmin: false,
eventCount: 0,
online: false,
...cluster,
}));
@ -266,7 +262,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
this.setActive(null);
}
// remove only custom kubeconfigs (pasted as text)
if (cluster.kubeConfigPath == ClusterStore.getCustomKubeConfigPath(clusterId)) {
if (cluster.kubeConfigPath == LensClusterStoreImpl.getCustomKubeConfigPath(clusterId)) {
unlink(cluster.kubeConfigPath).catch(() => null);
}
}
@ -352,7 +348,20 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
}
}
export class LensClusterStore extends LensClusterStoreImpl {
public getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] {
return super.getRendererInfoByWorkspace(workspaceId);
}
}
export class ClusterStore extends LensClusterStoreImpl {
private constructor() {
super();
}
}
export const clusterStore = ClusterStore.getInstance<ClusterStore>();
export const lensClusterStore = clusterStore as LensClusterStore;
export function getClusterIdFromHost(hostname: string): ClusterId {
const subDomains = hostname.split(":")[0].split(".");

View File

@ -5,7 +5,7 @@ import { autorun } from "mobx";
import { showAbout } from "./menu";
import { AppUpdater } from "./app-updater";
import { WindowManager } from "./window-manager";
import { ClusterRenderInfo, clusterStore } from "../common/cluster-store";
import { ClusterRenderInfo, clusterStore, lensClusterStore } from "../common/cluster-store";
import { Workspace, workspaceStore } from "../common/workspace-store";
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route";
@ -82,7 +82,7 @@ export function createTrayMenu(windowManager: WindowManager): Menu {
{
label: "Clusters",
submenu: workspaceStore.enabledWorkspacesList
.map((workspace): [Workspace, ClusterRenderInfo[]] => [workspace, clusterStore.getRendererInfoByWorkspace(workspace.id)])
.map((workspace): [Workspace, ClusterRenderInfo[]] => [workspace, lensClusterStore.getRendererInfoByWorkspace(workspace.id)])
.filter(([, clusters]) => clusters.length > 0)
.map(([workspace, clusters]): MenuItemConstructorOptions => ({
label: workspace.name,

View File

@ -8,7 +8,7 @@ import { observer } from "mobx-react";
import { _i18n } from "../../i18n";
import { t, Trans } from "@lingui/macro";
import { userStore } from "../../../common/user-store";
import { ClusterId, ClusterRenderInfo, clusterStore } from "../../../common/cluster-store";
import { ClusterId, ClusterRenderInfo, clusterStore, lensClusterStore } from "../../../common/cluster-store";
import { workspaceStore } from "../../../common/workspace-store";
import { ClusterIcon } from "../cluster-icon";
import { Icon } from "../icon";
@ -105,7 +105,7 @@ export class ClusterMenu extends React.Component<Props> {
const { className } = this.props;
const { newContexts } = userStore;
const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId);
const clusters = clusterStore.getRendererInfoByWorkspace(workspace.id);
const clusters = lensClusterStore.getRendererInfoByWorkspace(workspace.id);
const activeClusterId = clusterStore.activeCluster;
return (
<div className={cssNames("ClustersMenu flex column", className)}>