/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import styles from "./kubeconfig-dialog.module.scss"; import React from "react"; import type { IObservableValue } from "mobx"; import { observer } from "mobx-react"; import { cssNames, saveFileDialog } from "../../utils"; import { Button } from "../button"; import type { DialogProps } from "../dialog"; import { Dialog } from "../dialog"; import { Icon } from "../icon"; import type { ShowNotification } from "../notifications"; import { Wizard, WizardStep } from "../wizard"; import { MonacoEditor } from "../monaco-editor"; import { clipboard } from "electron"; import { withInjectables } from "@ogre-tools/injectable-react"; import showSuccessNotificationInjectable from "../notifications/show-success-notification.injectable"; import kubeconfigDialogStateInjectable from "./state.injectable"; export interface KubeconfigDialogData { title?: React.ReactNode; config: string; } export interface KubeConfigDialogProps extends Partial { } interface Dependencies { state: IObservableValue; showSuccessNotification: ShowNotification; } @observer class NonInjectedKubeConfigDialog extends React.Component { constructor(props: KubeConfigDialogProps & Dependencies) { super(props); } close = () => { this.props.state.set(undefined); }; copyToClipboard = (config: string) => { clipboard.writeText(config); this.props.showSuccessNotification("Config copied to clipboard"); }; download = (config: string) => { saveFileDialog("config", config, "text/yaml"); }; renderContents = (data: KubeconfigDialogData) => ( { data.title || "Kubeconfig File" }}> ) } prev={this.close} > ); render() { const { className, state, ...dialogProps } = this.props; const data = state.get(); return ( {data && this.renderContents(data)} ); } } export const KubeConfigDialog = withInjectables(NonInjectedKubeConfigDialog, { getProps: (di, props) => ({ ...props, showSuccessNotification: di.inject(showSuccessNotificationInjectable), state: di.inject(kubeconfigDialogStateInjectable), }), });