mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Factor out HelmChartIcon for better reusability
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
b8862a39ad
commit
15ba895cde
@ -20,12 +20,12 @@ import { Tooltip, withStyles } from "@material-ui/core";
|
|||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import createInstallChartTabInjectable from "../dock/install-chart/create-install-chart-tab.injectable";
|
import createInstallChartTabInjectable from "../dock/install-chart/create-install-chart-tab.injectable";
|
||||||
import type { ShowCheckedErrorNotification } from "../notifications";
|
import type { ShowCheckedErrorNotification } from "../notifications";
|
||||||
import HelmLogoPlaceholder from "./helm-placeholder.svg";
|
|
||||||
import type { SingleValue } from "react-select";
|
import type { SingleValue } from "react-select";
|
||||||
import AbortController from "abort-controller";
|
import AbortController from "abort-controller";
|
||||||
import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable";
|
import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable";
|
||||||
import type { GetChartDetails } from "./get-char-details.injectable";
|
import type { GetChartDetails } from "./get-char-details.injectable";
|
||||||
import getChartDetailsInjectable from "./get-char-details.injectable";
|
import getChartDetailsInjectable from "./get-char-details.injectable";
|
||||||
|
import { HelmChartIcon } from "./icon";
|
||||||
|
|
||||||
export interface HelmChartDetailsProps {
|
export interface HelmChartDetailsProps {
|
||||||
chart: HelmChart;
|
chart: HelmChart;
|
||||||
@ -46,7 +46,6 @@ interface Dependencies {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedHelmChartDetails extends Component<HelmChartDetailsProps & Dependencies> {
|
class NonInjectedHelmChartDetails extends Component<HelmChartDetailsProps & Dependencies> {
|
||||||
private readonly imgLoadingFailed = observable.set<string>(); // The IDs of the HelmChart instances
|
|
||||||
readonly chartVersions = observable.array<HelmChart>();
|
readonly chartVersions = observable.array<HelmChart>();
|
||||||
readonly selectedChart = observable.box<HelmChart | undefined>();
|
readonly selectedChart = observable.box<HelmChart | undefined>();
|
||||||
readonly readme = observable.box<string | undefined>(undefined);
|
readonly readme = observable.box<string | undefined>(undefined);
|
||||||
@ -119,32 +118,13 @@ class NonInjectedHelmChartDetails extends Component<HelmChartDetailsProps & Depe
|
|||||||
this.props.hideDetails();
|
this.props.hideDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderIcon(chart: HelmChart) {
|
|
||||||
const icon = chart.getIcon();
|
|
||||||
|
|
||||||
if (!icon || this.imgLoadingFailed.has(chart.getId())) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="intro-logo"
|
|
||||||
dangerouslySetInnerHTML={{ __html: HelmLogoPlaceholder }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<img
|
|
||||||
className="intro-logo"
|
|
||||||
src={icon}
|
|
||||||
onLoad={evt => evt.currentTarget.classList.add("visible")}
|
|
||||||
onError={() => this.imgLoadingFailed.add(chart.getId())}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderIntroduction(selectedChart: HelmChart) {
|
renderIntroduction(selectedChart: HelmChart) {
|
||||||
return (
|
return (
|
||||||
<div className="introduction flex align-flex-start">
|
<div className="introduction flex align-flex-start">
|
||||||
{this.renderIcon(selectedChart)}
|
<HelmChartIcon
|
||||||
|
chart={selectedChart}
|
||||||
|
className="intro-logo"
|
||||||
|
/>
|
||||||
<div className="intro-contents box grow">
|
<div className="intro-contents box grow">
|
||||||
<div className="description flex align-center justify-space-between" data-testid="selected-chart-description">
|
<div className="description flex align-center justify-space-between" data-testid="selected-chart-description">
|
||||||
{selectedChart.getDescription()}
|
{selectedChart.getDescription()}
|
||||||
|
|||||||
@ -12,13 +12,12 @@ import type { HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.ap
|
|||||||
import { HelmChartDetails } from "./helm-chart-details";
|
import { HelmChartDetails } from "./helm-chart-details";
|
||||||
import { ItemListLayout } from "../item-object-list/list-layout";
|
import { ItemListLayout } from "../item-object-list/list-layout";
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
import { observable } from "mobx";
|
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
||||||
import helmChartsRouteParametersInjectable from "./helm-charts-route-parameters.injectable";
|
import helmChartsRouteParametersInjectable from "./helm-charts-route-parameters.injectable";
|
||||||
import type { NavigateToHelmCharts } from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable";
|
import type { NavigateToHelmCharts } from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable";
|
||||||
import navigateToHelmChartsInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable";
|
import navigateToHelmChartsInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable";
|
||||||
import HelmLogoPlaceholder from "./helm-placeholder.svg";
|
import { HelmChartIcon } from "./icon";
|
||||||
|
|
||||||
enum columnId {
|
enum columnId {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -39,8 +38,6 @@ interface Dependencies {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedHelmCharts extends Component<Dependencies> {
|
class NonInjectedHelmCharts extends Component<Dependencies> {
|
||||||
private readonly imgLoadingFailed = observable.set<string>(); // The IDs of the HelmChart instances
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
helmChartStore.loadAll();
|
helmChartStore.loadAll();
|
||||||
}
|
}
|
||||||
@ -80,22 +77,6 @@ class NonInjectedHelmCharts extends Component<Dependencies> {
|
|||||||
this.showDetails(null);
|
this.showDetails(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
private renderIcon(chart: HelmChart) {
|
|
||||||
const icon = chart.getIcon();
|
|
||||||
|
|
||||||
if (!icon || this.imgLoadingFailed.has(chart.getId())) {
|
|
||||||
return <div dangerouslySetInnerHTML={{ __html: HelmLogoPlaceholder }} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<img
|
|
||||||
src={icon}
|
|
||||||
onLoad={evt => evt.currentTarget.classList.add("visible")}
|
|
||||||
onError={() => this.imgLoadingFailed.add(chart.getId())}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<SiblingsInTabLayout>
|
<SiblingsInTabLayout>
|
||||||
@ -134,7 +115,7 @@ class NonInjectedHelmCharts extends Component<Dependencies> {
|
|||||||
]}
|
]}
|
||||||
renderTableContents={chart => [
|
renderTableContents={chart => [
|
||||||
<figure key="image">
|
<figure key="image">
|
||||||
{this.renderIcon(chart)}
|
<HelmChartIcon chart={chart} />
|
||||||
</figure>,
|
</figure>,
|
||||||
chart.getName(),
|
chart.getName(),
|
||||||
chart.getDescription(),
|
chart.getDescription(),
|
||||||
|
|||||||
41
src/renderer/components/+helm-charts/icon.tsx
Normal file
41
src/renderer/components/+helm-charts/icon.tsx
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import type { HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
||||||
|
import HelmLogoPlaceholder from "./helm-placeholder.svg";
|
||||||
|
|
||||||
|
export interface HelmChartIconProps {
|
||||||
|
className?: string;
|
||||||
|
chart: HelmChart;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const HelmChartIcon = ({
|
||||||
|
chart,
|
||||||
|
className,
|
||||||
|
}: HelmChartIconProps) => {
|
||||||
|
const [failedToLoad, setFailedToLoad] = useState(false);
|
||||||
|
const icon = chart.getIcon();
|
||||||
|
|
||||||
|
if (!icon || failedToLoad) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={className}
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: HelmLogoPlaceholder,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
className={className}
|
||||||
|
src={icon}
|
||||||
|
onLoad={evt => evt.currentTarget.classList.add("visible")}
|
||||||
|
onError={() => setFailedToLoad(true)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user