allow to remove cluster from icon's context-menu, random fixes

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-07-17 13:08:21 +03:00
1 parent 33d3181113
commit e11d8582f1
10 files changed
+88 -299

No files matched your search

@@ -16,16 +16,17 @@ import { tracker } from "../../../common/tracker";
import { clusterStore } from "../../../common/cluster-store";
import { workspaceStore } from "../../../common/workspace-store";
import { v4 as uuid } from "uuid"
import { navigate } from "../../navigation";
@observer
export class AddCluster extends React.Component {
readonly custom: any = "custom"
@observable.ref clusterConfig: KubeConfig;
@observable.ref kubeConfig: KubeConfig; // local ~/.kube/config (if available)
@observable.ref error: React.ReactNode;
@observable isWaiting = false
@observable showSettings = false
@observable error = ""
@observable proxyServer = ""
@observable customConfig = ""
@@ -49,13 +50,15 @@ export class AddCluster extends React.Component {
@computed get clusterOptions() {
const options: SelectOption<KubeConfig>[] = [];
if (this.kubeConfig) {
splitConfig(this.kubeConfig).forEach(kubeConfig => {
const contextName = kubeConfig.getCurrentContext();
const contexts = splitConfig(this.kubeConfig)
.filter(kc => !clusterStore.hasContext(kc.currentContext));
contexts.forEach(kubeConfig => {
const isNew = false; // fixme: detect new context since last visit
options.push({
value: kubeConfig,
label: <>
{contextName}
{kubeConfig.currentContext}
{isNew && <span className="new"> <Trans>(new)</Trans></span>}
</>,
})
@@ -72,16 +75,16 @@ export class AddCluster extends React.Component {
tracker.event("cluster", "add");
const { clusterConfig, customConfig, proxyServer } = this;
const clusterId = uuid();
this.isWaiting = true
this.error = ""
try {
const config = this.isCustom ? loadConfig(customConfig) : clusterConfig;
if (!config) {
this.error = "Please select kubeconfig"
this.error = <Trans>Please select kubeconfig</Trans>
return;
}
this.error = ""
this.isWaiting = true
validateConfig(config);
clusterStore.addCluster({
await clusterStore.addCluster({
id: clusterId,
kubeConfigPath: saveConfigToAppFiles(clusterId, config),
workspace: workspaceStore.currentWorkspaceId,
@@ -90,7 +93,8 @@ export class AddCluster extends React.Component {
clusterName: config.currentContext,
httpsProxy: proxyServer || undefined,
},
})
});
navigate("/");
} catch (err) {
this.error = String(err);
} finally {
@@ -33,7 +33,7 @@
}
> .clusters {
@include hidden-scrollbar;
//@include hidden-scrollbar; // fixme: uncomment after refactoring tooltip.tsx
--flex-gap: #{$padding * 2};
padding: $padding;
@@ -18,6 +18,7 @@ import { addClusterURL } from "../+add-cluster";
import { clusterSettingsURL } from "../+cluster-settings";
import { landingURL } from "../+landing-page";
import { Tooltip, TooltipContent } from "../tooltip";
import { ConfirmDialog } from "../confirm-dialog";
// fixme: allow to rearrange clusters with drag&drop
// fixme: disconnect cluster from context-menu
@@ -50,7 +51,6 @@ export class ClustersMenu extends React.Component<Props> {
label: _i18n._(t`Settings`),
click: () => navigate(clusterSettingsURL())
}));
if (cluster.initialized) {
menu.append(new MenuItem({
label: _i18n._(t`Disconnect`),
@@ -59,6 +59,16 @@ export class ClustersMenu extends React.Component<Props> {
}
}))
}
menu.append(new MenuItem({
label: _i18n._(t`Remove`),
click: () => {
ConfirmDialog.open({
ok: () => clusterStore.removeById(cluster.id),
labelOk: _i18n._(t`Remove`),
message: <p>Are you sure want to remove cluster <b title={cluster.id}>{cluster.contextName}</b>?</p>,
})
}
}));
menu.popup({
window: remote.getCurrentWindow()
})