import "./kubeconfig-dialog.scss"; import React from "react"; import { observable } from "mobx"; import { observer } from "mobx-react"; import jsYaml from "js-yaml"; import { Trans } from "@lingui/macro"; import { AceEditor } from "../ace-editor"; import { kubeConfigApi, ServiceAccount } from "../../api/endpoints"; import { copyToClipboard, downloadFile, cssNames } from "../../utils"; import { Button } from "../button"; import { Dialog, DialogProps } from "../dialog"; import { Icon } from "../icon"; import { Notifications } from "../notifications"; import { Wizard, WizardStep } from "../wizard"; import { themeStore } from "../../theme.store"; interface IKubeconfigDialogData { title?: React.ReactNode; loader?: () => Promise; } interface Props extends Partial { } @observer export class KubeConfigDialog extends React.Component { @observable static isOpen = false; @observable static data: IKubeconfigDialogData = null; @observable.ref configTextArea: HTMLTextAreaElement; // required for coping config text @observable config = ""; // parsed kubeconfig in yaml format static open(data: IKubeconfigDialogData) { KubeConfigDialog.isOpen = true; KubeConfigDialog.data = data; } static close() { KubeConfigDialog.isOpen = false; } get data(): IKubeconfigDialogData { return KubeConfigDialog.data; } close = () => { KubeConfigDialog.close(); } onOpen = () => { this.loadConfig(); } async loadConfig() { const config = await this.data.loader().catch(err => { Notifications.error(err) this.close() }) this.config = config ? jsYaml.dump(config) : "" } copyToClipboard = () => { if (this.config && copyToClipboard(this.configTextArea)) { Notifications.ok(Config copied to clipboard) } } download = () => { downloadFile("config", this.config, "text/yaml") } render() { const { isOpen, data = {} } = KubeConfigDialog; const { ...dialogProps } = this.props; const yamlConfig = this.config; const header =
{data.title || Kubeconfig File}
const buttons = (
) return (