mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
don't allow user to delete the active cluster before setting to new active cluster
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
d238d0e8cb
commit
32b2e82871
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
import styles from "./delete-cluster-dialog.module.css";
|
import styles from "./delete-cluster-dialog.module.css";
|
||||||
|
|
||||||
import { makeObservable, observable } from "mobx";
|
import { computed, makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
@ -122,6 +122,10 @@ export class DeleteClusterDialog extends React.Component {
|
|||||||
this.onClose();
|
this.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@computed get disableDelete() {
|
||||||
|
return this.showContextSwitch && (this.newCurrentContext === "");
|
||||||
|
}
|
||||||
|
|
||||||
isCurrentContext() {
|
isCurrentContext() {
|
||||||
return dialogState.config.currentContext == dialogState.cluster.contextName;
|
return dialogState.config.currentContext == dialogState.cluster.contextName;
|
||||||
}
|
}
|
||||||
@ -142,6 +146,7 @@ export class DeleteClusterDialog extends React.Component {
|
|||||||
<div className="mt-4">
|
<div className="mt-4">
|
||||||
<Select
|
<Select
|
||||||
options={options}
|
options={options}
|
||||||
|
value={this.newCurrentContext}
|
||||||
onChange={({ value }) => this.newCurrentContext = value}
|
onChange={({ value }) => this.newCurrentContext = value}
|
||||||
themeName="light"
|
themeName="light"
|
||||||
className="ml-[1px] mr-[1px]"
|
className="ml-[1px] mr-[1px]"
|
||||||
@ -150,6 +155,24 @@ export class DeleteClusterDialog extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderDeleteMessage() {
|
||||||
|
const { cluster } = dialogState;
|
||||||
|
|
||||||
|
if (cluster.isInLocalKubeconfig()) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Delete the <b>{cluster.getMeta().name}</b> context from Lens's internal kubeconfig?
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Delete the <b>{cluster.getMeta().name}</b> context from <b>{cluster.kubeConfigPath}</b>?
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
getWarningMessage() {
|
getWarningMessage() {
|
||||||
const { cluster, config } = dialogState;
|
const { cluster, config } = dialogState;
|
||||||
const contexts = config.contexts.filter(context => context.name !== cluster.contextName);
|
const contexts = config.contexts.filter(context => context.name !== cluster.contextName);
|
||||||
@ -207,9 +230,7 @@ export class DeleteClusterDialog extends React.Component {
|
|||||||
onOpen={this.onOpen}
|
onOpen={this.onOpen}
|
||||||
>
|
>
|
||||||
<div className={styles.dialogContent}>
|
<div className={styles.dialogContent}>
|
||||||
<div>
|
{this.renderDeleteMessage()}
|
||||||
Delete the <b>{cluster.getMeta().name}</b> context from <b>{cluster.kubeConfigPath}</b>?
|
|
||||||
</div>
|
|
||||||
{this.renderWarning()}
|
{this.renderWarning()}
|
||||||
<hr className={styles.hr}/>
|
<hr className={styles.hr}/>
|
||||||
{contexts.length > 0 && (
|
{contexts.length > 0 && (
|
||||||
@ -225,7 +246,7 @@ export class DeleteClusterDialog extends React.Component {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
value={this.showContextSwitch}
|
value={this.showContextSwitch}
|
||||||
onChange={value => this.showContextSwitch = value}
|
onChange={value => this.showContextSwitch = this.isCurrentContext() ? true : value}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{this.renderCurrentContextSwitch()}
|
{this.renderCurrentContextSwitch()}
|
||||||
@ -241,6 +262,7 @@ export class DeleteClusterDialog extends React.Component {
|
|||||||
onClick={this.onDelete}
|
onClick={this.onDelete}
|
||||||
autoFocus accent
|
autoFocus accent
|
||||||
label="Delete Context"
|
label="Delete Context"
|
||||||
|
disabled={this.disableDelete}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user