diff --git a/src/renderer/components/+apps-helm-charts/helm-chart-details.scss b/src/renderer/components/+apps-helm-charts/helm-chart-details.scss index 212e9d723a..c436dfa50f 100644 --- a/src/renderer/components/+apps-helm-charts/helm-chart-details.scss +++ b/src/renderer/components/+apps-helm-charts/helm-chart-details.scss @@ -49,4 +49,4 @@ .chart-description { margin-top: $margin * 2; } -} \ No newline at end of file +} diff --git a/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx b/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx index 32c6cd6a3e..4ae8995f11 100644 --- a/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx +++ b/src/renderer/components/+apps-helm-charts/helm-chart-details.tsx @@ -3,8 +3,8 @@ import "./helm-chart-details.scss"; import React, { Component } from "react"; import { HelmChart, helmChartsApi } from "../../api/endpoints/helm-charts.api"; import { t, Trans } from "@lingui/macro"; -import { autorun, observable } from "mobx"; -import { disposeOnUnmount, observer } from "mobx-react"; +import { observable, toJS } from "mobx"; +import { observer } from "mobx-react"; import { Drawer, DrawerItem } from "../drawer"; import { autobind, stopPropagation } from "../../utils"; import { MarkdownViewer } from "../markdown-viewer"; @@ -25,39 +25,41 @@ interface Props { export class HelmChartDetails extends Component { @observable chartVersions: HelmChart[]; @observable selectedChart: HelmChart; - @observable description: string = null; + @observable readme: string = null; + @observable error: string = null; private chartPromise: CancelablePromise<{ readme: string; versions: HelmChart[] }>; - @disposeOnUnmount - chartSelector = autorun(async () => { - if (!this.props.chart) return; - this.chartVersions = null; - this.selectedChart = null; - this.description = null; - this.loadChartData(); - this.chartPromise.then(data => { - this.description = data.readme; - this.chartVersions = data.versions; - this.selectedChart = data.versions[0]; - }); - }); + async componentDidMount() { + const { chart: { name, repo, version } } = this.props - loadChartData(version?: string) { - const { chart: { name, repo } } = this.props; - if (this.chartPromise) this.chartPromise.cancel(); - this.chartPromise = helmChartsApi.get(repo, name, version); + try { + const { readme, versions } = await (this.chartPromise = helmChartsApi.get(repo, name, version)) + this.readme = readme + this.chartVersions = versions + this.selectedChart = versions[0] + } catch (error) { + this.error = error + } + } + + componentWillUnmount() { + this.chartPromise?.cancel(); } @autobind() - onVersionChange(opt: SelectOption) { - const version = opt.value; + async onVersionChange({ value: version }: SelectOption) { this.selectedChart = this.chartVersions.find(chart => chart.version === version); - this.description = null; - this.loadChartData(version); - this.chartPromise.then(data => { - this.description = data.readme - }); + this.readme = null; + + try { + this.chartPromise?.cancel(); + const { chart: { name, repo } } = this.props; + const { readme } = await (this.chartPromise = helmChartsApi.get(repo, name, version)) + this.readme = readme; + } catch (error) { + this.error = error; + } } @autobind() @@ -79,7 +81,7 @@ export class HelmChartDetails extends Component {
{selectedChart.getDescription()} -
{
); } -} \ No newline at end of file +} diff --git a/src/renderer/components/notifications/notifications.store.ts b/src/renderer/components/notifications/notifications.store.ts index 786a65d603..1873ae91a4 100644 --- a/src/renderer/components/notifications/notifications.store.ts +++ b/src/renderer/components/notifications/notifications.store.ts @@ -8,10 +8,16 @@ import { JsonApiErrorParsed } from "../../api/json-api"; export type IMessageId = string | number; export type IMessage = React.ReactNode | React.ReactNode[] | JsonApiErrorParsed; +export enum NotificationStatus { + OK = "ok", + ERROR = "error", + INFO = "info", +} + export interface INotification { id?: IMessageId; message: IMessage; - status?: "ok" | "error" | "info"; + status?: NotificationStatus; timeout?: number; // auto-hiding timeout in milliseconds, 0 = no hide } diff --git a/src/renderer/components/notifications/notifications.tsx b/src/renderer/components/notifications/notifications.tsx index 6f59a068d9..35c741505c 100644 --- a/src/renderer/components/notifications/notifications.tsx +++ b/src/renderer/components/notifications/notifications.tsx @@ -5,7 +5,7 @@ import { reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react" import { JsonApiErrorParsed } from "../../api/json-api"; import { cssNames, prevDefault } from "../../utils"; -import { IMessage, INotification, notificationsStore } from "./notifications.store"; +import { IMessage, INotification, notificationsStore, NotificationStatus } from "./notifications.store"; import { Animate } from "../animate"; import { Icon } from "../icon" @@ -17,7 +17,7 @@ export class Notifications extends React.Component { notificationsStore.add({ message: message, timeout: 2500, - status: "ok" + status: NotificationStatus.OK }) } @@ -25,13 +25,13 @@ export class Notifications extends React.Component { notificationsStore.add({ message: message, timeout: 10000, - status: "error" + status: NotificationStatus.ERROR }); } static info(message: IMessage, customOpts: Partial = {}) { return notificationsStore.add({ - status: "info", + status: NotificationStatus.INFO, timeout: 0, message: message, ...customOpts, @@ -78,7 +78,7 @@ export class Notifications extends React.Component { onMouseLeave={() => addAutoHideTimer(notification)} onMouseEnter={() => removeAutoHideTimer(notification)}>
- +
{msgText}