/** * Copyright (c) 2021 OpenLens Authors * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import "./install-chart.scss"; import React, { Component } from "react"; import { computed, makeObservable, observable } from "mobx"; import { observer } from "mobx-react"; import { dockStore, TabKind } from "./dock.store"; import { InfoPanel, InfoPanelProps } from "./info-panel"; import { Badge } from "../badge"; import { NamespaceSelect } from "../+namespaces/namespace-select"; import { prevDefault } from "../../utils"; import { IChartInstallData, installChartStore } from "./install-chart.store"; import { Spinner } from "../spinner"; import { Icon } from "../icon"; import { Button } from "../button"; import { releaseStore } from "../+apps-releases/release.store"; import { LogsDialog } from "../dialog/logs-dialog"; import { Select, SelectOption } from "../select"; import { Input } from "../input"; import { navigate } from "../../navigation"; import { releaseURL } from "../../../common/routes"; import { dockViewsManager } from "./dock.views-manager"; interface Props extends InfoPanelProps { } @observer export class InstallChartInfoPanel extends Component { @observable showNotes = false; constructor(props: Props) { super(props); makeObservable(this); } get tabId() { return this.props.tabId; } get chartData(): IChartInstallData | undefined { return installChartStore.getData(this.tabId); } get versions() { return installChartStore.versions.get(this.tabId); } get releaseDetails() { return installChartStore.details.get(this.tabId); } @computed get isReady() { return [installChartStore.dataReady, this.versions].every(Boolean); } viewRelease = () => { const { release } = this.releaseDetails; navigate(releaseURL({ params: { name: release.name, namespace: release.namespace } })); dockStore.closeTab(this.tabId); }; save = (data: Partial) => { const chart = { ...this.chartData, ...data }; installChartStore.setData(this.tabId, chart); }; onVersionChange = (option: SelectOption) => { const version = option.value; this.save({ version, values: "" }); installChartStore.loadValues(this.tabId); }; onNamespaceChange = (opt: SelectOption) => { this.save({ namespace: opt.value }); }; onReleaseNameChange = (name: string) => { this.save({ releaseName: name }); }; install = async () => { const { repo, name, version, namespace, values, releaseName } = this.chartData; const details = await releaseStore.create({ name: releaseName || undefined, chart: name, repo, namespace, version, values, }); installChartStore.details.set(this.tabId, details); return (

Chart Release {details.release.name} successfully created.

); }; renderReleaseDetails(): React.ReactNode { return (

Installation complete!

this.showNotes = false} logs={this.releaseDetails.log} />
); } render() { if (!this.isReady) { return ; } if (this.releaseDetails) { return this.renderReleaseDetails(); } const { chartData, install, versions } = this; const { repo, name, version, namespace, releaseName } = chartData; const panelControls = (
Chart Version
); return ( ); } } dockViewsManager.register(TabKind.INSTALL_CHART, { InfoPanel: InstallChartInfoPanel, editor: { getValue(tabId) { return installChartStore.getData(tabId).values; }, setValue(tabId, value) { installChartStore.getData(tabId).values = value; }, } });