/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./helm-chart-details.scss"; import React, { Component } from "react"; import { getChartDetails, HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api"; import { observable, makeObservable, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { Drawer, DrawerItem } from "../drawer"; import { boundMethod, stopPropagation } from "../../utils"; import { MarkdownViewer } from "../markdown-viewer"; import { Spinner } from "../spinner"; import { Button } from "../button"; import { Select, SelectOption } from "../select"; import { Badge } from "../badge"; import { Tooltip, withStyles } from "@material-ui/core"; import { withInjectables } from "@ogre-tools/injectable-react"; import createInstallChartTabInjectable from "../dock/install-chart/create-install-chart-tab.injectable"; interface Props { chart: HelmChart; hideDetails(): void; } const LargeTooltip = withStyles({ tooltip: { fontSize: "var(--font-size-small)", }, })(Tooltip); interface Dependencies { createInstallChartTab: (helmChart: HelmChart) => void } @observer class NonInjectedHelmChartDetails extends Component { @observable chartVersions: HelmChart[]; @observable selectedChart?: HelmChart; @observable readme?: string; @observable error?: string; private abortController?: AbortController; constructor(props: Props & Dependencies) { super(props); makeObservable(this); } componentWillUnmount() { this.abortController?.abort(); } componentDidMount() { disposeOnUnmount(this, [ reaction(() => this.props.chart, async ({ name, repo, version }) => { try { this.selectedChart = undefined; this.chartVersions = undefined; this.readme = undefined; const { readme, versions } = await getChartDetails(repo, name, { version }); this.readme = readme; this.chartVersions = versions; this.selectedChart = versions[0]; } catch (error) { this.error = error; this.selectedChart = null; } }, { fireImmediately: true, }), ]); } @boundMethod async onVersionChange({ value: chart }: SelectOption) { this.selectedChart = chart; this.readme = null; try { this.abortController?.abort(); this.abortController = new AbortController(); const { chart: { name, repo }} = this.props; const { readme } = await getChartDetails(repo, name, { version: chart.version, reqInit: { signal: this.abortController.signal }}); this.readme = readme; } catch (error) { this.error = error; } } @boundMethod install() { this.props.createInstallChartTab(this.selectedChart); this.props.hideDetails(); } renderIntroduction() { const { selectedChart, chartVersions, onVersionChange } = this; const placeholder = require("./helm-placeholder.svg"); return (
event.currentTarget.src = placeholder} />
{selectedChart.getDescription()}