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

Refactor warning messages

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-09-06 09:53:43 +03:00
parent 8faa108c86
commit 661d6f080b
2 changed files with 31 additions and 14 deletions

View File

@ -741,6 +741,6 @@ export class Cluster implements ClusterModel, ClusterState {
} }
isInLocalKubeconfig() { isInLocalKubeconfig() {
return this.kubeConfigPath.includes(storedKubeConfigFolder()); return this.kubeConfigPath.startsWith(storedKubeConfigFolder());
} }
} }

View File

@ -151,27 +151,44 @@ export class DeleteClusterDialog extends React.Component {
); );
} }
renderWarning() { getWarningMessage() {
const { cluster } = dialogState; const { cluster, config } = dialogState;
const isInternalKubeconfig = cluster.isInLocalKubeconfig(); const contexts = config.contexts.filter(context => context.name !== cluster.contextName);
let warning: JSX.Element = null;
if (this.isCurrentContext()) { if (!contexts.length) {
warning = <p data-testid="context-warning"> return (
This will remove active context in kubeconfig. Use drop down below to&nbsp;select a&nbsp;different one. <p data-testid="no-more-contexts-warning">
</p>; This will remove the last context in kubeconfig. There will be no active context.
} else if (!isInternalKubeconfig) { </p>
warning = <p>The contents of kubeconfig file will be changed!</p>; );
} }
if (!warning) { if (this.isCurrentContext()) {
return null; return (
<p data-testid="current-context-warning">
This will remove active context in kubeconfig. Use drop down below to&nbsp;select a&nbsp;different one.
</p>
);
}
if (cluster.isInLocalKubeconfig()) {
return (
<p data-testid="internal-kubeconfig-warning">
Are you sure you want to delete it? It can be re-added through the copy/paste mechanism.
</p>
);
} }
return (
<p data-testid="kubeconfig-change-warning">The contents of kubeconfig file will be changed!</p>
);
}
renderWarning() {
return ( return (
<div className={styles.warning}> <div className={styles.warning}>
<Icon material="warning_amber" className={styles.warningIcon}/> <Icon material="warning_amber" className={styles.warningIcon}/>
{warning} {this.getWarningMessage()}
</div> </div>
); );
} }