import type { KubeAuthProxyLog } from "../../../main/kube-auth-proxy"; import "./cluster-status.scss"; import React from "react"; import { observer } from "mobx-react"; import { ipcRenderer } from "electron"; import { computed, observable } from "mobx"; import { requestMain, subscribeToBroadcast } from "../../../common/ipc"; import { Icon } from "../icon"; import { Button } from "../button"; import { cssNames, IClassName } from "../../utils"; import { Cluster } from "../../../main/cluster"; import { ClusterId, ClusterStore } from "../../../common/cluster-store"; import { CubeSpinner } from "../spinner"; import { clusterActivateHandler } from "../../../common/cluster-ipc"; interface Props { className?: IClassName; clusterId: ClusterId; } @observer export class ClusterStatus extends React.Component { @observable authOutput: KubeAuthProxyLog[] = []; @observable isReconnecting = false; get cluster(): Cluster { return ClusterStore.getInstance().getById(this.props.clusterId); } @computed get hasErrors(): boolean { return this.authOutput.some(({ error }) => error) || !!this.cluster.failureReason; } async componentDidMount() { subscribeToBroadcast(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => { this.authOutput.push({ data: res.data.trimRight(), error: res.error, }); }); if (this.cluster.disconnected) { await this.activateCluster(); } } componentWillUnmount() { ipcRenderer.removeAllListeners(`kube-auth:${this.props.clusterId}`); } activateCluster = async (force = false) => { await requestMain(clusterActivateHandler, this.props.clusterId, force); }; reconnect = async () => { this.authOutput = []; this.isReconnecting = true; await this.activateCluster(true); this.isReconnecting = false; }; renderContent() { const { authOutput, cluster, hasErrors } = this; const failureReason = cluster.failureReason; if (!hasErrors || this.isReconnecting) { return ( <>
            

{this.isReconnecting ? "Reconnecting..." : "Connecting..."}

{authOutput.map(({ data, error }, index) => { return

{data}

; })}
); } return ( <>

{cluster.preferences.clusterName}

          {authOutput.map(({ data, error }, index) => {
            return 

{data}

; })}
{failureReason && (
{failureReason}
)}