mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
use a free function instead of subclassing
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2daff2da0b
commit
ffa5cb15e4
@ -82,13 +82,13 @@ export interface ClusterRenderInfo extends ClusterModel {
|
||||
online: boolean;
|
||||
}
|
||||
|
||||
export class LensClusterStoreImpl extends BaseStore<ClusterStoreModel> {
|
||||
export class ClusterStore 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 = LensClusterStoreImpl.getCustomKubeConfigPath(clusterId);
|
||||
const filePath = ClusterStore.getCustomKubeConfigPath(clusterId);
|
||||
const fileContents = typeof kubeConfig == "string" ? kubeConfig : dumpConfigYaml(kubeConfig);
|
||||
saveToAppFiles(filePath, fileContents, { mode: 0o600 });
|
||||
return filePath;
|
||||
@ -200,21 +200,6 @@ export class LensClusterStoreImpl extends BaseStore<ClusterStoreModel> {
|
||||
return this.deadClusters.get(id);
|
||||
}
|
||||
|
||||
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,
|
||||
online: false,
|
||||
...cluster,
|
||||
}));
|
||||
|
||||
|
||||
return _.sortBy([...aliveClusters, ...deadClusters], c => c.preferences?.iconOrder);
|
||||
}
|
||||
|
||||
getByWorkspaceId(workspaceId: string): Cluster[] {
|
||||
const clusters = this.clustersList.filter(c => c.workspace === workspaceId);
|
||||
return _.sortBy(clusters, c => c.preferences?.iconOrder);
|
||||
@ -262,7 +247,7 @@ export class LensClusterStoreImpl extends BaseStore<ClusterStoreModel> {
|
||||
this.setActive(null);
|
||||
}
|
||||
// remove only custom kubeconfigs (pasted as text)
|
||||
if (cluster.kubeConfigPath == LensClusterStoreImpl.getCustomKubeConfigPath(clusterId)) {
|
||||
if (cluster.kubeConfigPath == ClusterStore.getCustomKubeConfigPath(clusterId)) {
|
||||
unlink(cluster.kubeConfigPath).catch(() => null);
|
||||
}
|
||||
}
|
||||
@ -348,20 +333,22 @@ export class LensClusterStoreImpl 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 getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] {
|
||||
const aliveClusters: ClusterRenderInfo[] = clusterStore.clustersList.filter(c => c.workspace === workspaceId);
|
||||
const deadClusters: ClusterRenderInfo[] = clusterStore.deadClustersList
|
||||
.filter(([c]) => c.workspace === workspaceId)
|
||||
.map(([cluster, error]) => ({
|
||||
DeadError: error,
|
||||
name: cluster.contextName,
|
||||
online: false,
|
||||
...cluster,
|
||||
}));
|
||||
|
||||
|
||||
return _.sortBy([...aliveClusters, ...deadClusters], c => c.preferences?.iconOrder);
|
||||
}
|
||||
|
||||
export function getClusterIdFromHost(hostname: string): ClusterId {
|
||||
const subDomains = hostname.split(":")[0].split(".");
|
||||
|
||||
@ -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, lensClusterStore } from "../common/cluster-store";
|
||||
import { ClusterRenderInfo, getRendererInfoByWorkspace } 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, lensClusterStore.getRendererInfoByWorkspace(workspace.id)])
|
||||
.map((workspace): [Workspace, ClusterRenderInfo[]] => [workspace, getRendererInfoByWorkspace(workspace.id)])
|
||||
.filter(([, clusters]) => clusters.length > 0)
|
||||
.map(([workspace, clusters]): MenuItemConstructorOptions => ({
|
||||
label: workspace.name,
|
||||
|
||||
@ -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, lensClusterStore } from "../../../common/cluster-store";
|
||||
import { ClusterId, ClusterRenderInfo, clusterStore, getRendererInfoByWorkspace } 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 = lensClusterStore.getRendererInfoByWorkspace(workspace.id);
|
||||
const clusters = getRendererInfoByWorkspace(workspace.id);
|
||||
const activeClusterId = clusterStore.activeCluster;
|
||||
return (
|
||||
<div className={cssNames("ClustersMenu flex column", className)}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user