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

adding cluster fix (reverted changes from master)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-10-12 14:05:28 +03:00
parent 2b37fe3cc1
commit 52b447948d

View File

@ -2,7 +2,7 @@ import "./add-cluster.scss"
import os from "os"; import os from "os";
import React, { Fragment } from "react"; import React, { Fragment } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { action, observable } from "mobx"; import { action, observable, runInAction } from "mobx";
import { remote } from "electron"; import { remote } from "electron";
import { KubeConfig } from "@kubernetes/client-node"; import { KubeConfig } from "@kubernetes/client-node";
import { _i18n } from "../../i18n"; import { _i18n } from "../../i18n";
@ -121,9 +121,7 @@ export class AddCluster extends React.Component {
@action @action
addClusters = () => { addClusters = () => {
const configValidationErrors:string[] = [];
let newClusters: ClusterModel[] = []; let newClusters: ClusterModel[] = [];
try { try {
if (!this.selectedContexts.length) { if (!this.selectedContexts.length) {
this.error = <Trans>Please select at least one cluster context</Trans> this.error = <Trans>Please select at least one cluster context</Trans>
@ -132,7 +130,7 @@ export class AddCluster extends React.Component {
this.error = "" this.error = ""
this.isWaiting = true this.isWaiting = true
newClusters = this.selectedContexts.filter(context => { newClusters = this.selectedContexts.filter(context => {
try { try {
const kubeConfig = this.kubeContexts.get(context); const kubeConfig = this.kubeContexts.get(context);
validateKubeConfig(kubeConfig); validateKubeConfig(kubeConfig);
@ -164,17 +162,21 @@ export class AddCluster extends React.Component {
} }
}) })
runInAction(() => {
clusterStore.addCluster(...newClusters); clusterStore.addCluster(...newClusters);
if (newClusters.length === 1) {
if (newClusters.length === 1) { const clusterId = newClusters[0].id;
const clusterId = newClusters[0].id; clusterStore.setActive(clusterId);
navigate(clusterViewURL({ params: { clusterId } })); navigate(clusterViewURL({ params: { clusterId } }));
} else { } else {
if (newClusters.length > 1) {Notifications.ok( if (newClusters.length > 1) {
<Trans>Successfully imported <b>{newClusters.length}</b> cluster(s)</Trans>); Notifications.ok(
<Trans>Successfully imported <b>{newClusters.length}</b> cluster(s)</Trans>
);
}
} }
} })
this.refreshContexts();
} catch (err) { } catch (err) {
this.error = String(err); this.error = String(err);
Notifications.error(<Trans>Error while adding cluster(s): {this.error}</Trans>); Notifications.error(<Trans>Error while adding cluster(s): {this.error}</Trans>);
@ -226,7 +228,7 @@ export class AddCluster extends React.Component {
<Tab <Tab
value={KubeConfigSourceTab.FILE} value={KubeConfigSourceTab.FILE}
label={<Trans>Select kubeconfig file</Trans>} label={<Trans>Select kubeconfig file</Trans>}
active={this.sourceTab == KubeConfigSourceTab.FILE}/> active={this.sourceTab == KubeConfigSourceTab.FILE} />
<Tab <Tab
value={KubeConfigSourceTab.TEXT} value={KubeConfigSourceTab.TEXT}
label={<Trans>Paste as text</Trans>} label={<Trans>Paste as text</Trans>}
@ -340,8 +342,8 @@ export class AddCluster extends React.Component {
return ( return (
<div className={cssNames("kube-context flex gaps align-center", context)}> <div className={cssNames("kube-context flex gaps align-center", context)}>
<span>{context}</span> <span>{context}</span>
{isNew && <Icon small material="fiber_new"/>} {isNew && <Icon small material="fiber_new" />}
{isSelected && <Icon small material="check" className="box right"/>} {isSelected && <Icon small material="check" className="box right" />}
</div> </div>
) )
}; };