Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Display default icon when error (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliy-guliy committed Nov 29, 2019
1 parent 9c01d69 commit 26e75a1
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface ListItemProps {

interface ListItemState {
pluginStatus: PluginStatus;
iconFailed: boolean;
}

export class ChePluginListItem extends React.Component<ListItemProps, ListItemState> {
Expand All @@ -69,7 +70,8 @@ export class ChePluginListItem extends React.Component<ListItemProps, ListItemSt
const status = props.pluginItem.installed ? 'installed' : 'not_installed';

this.state = {
pluginStatus: status
pluginStatus: status,
iconFailed: false
};
}

Expand Down Expand Up @@ -239,11 +241,22 @@ export class ChePluginListItem extends React.Component<ListItemProps, ListItemSt
</select>;
}

protected onIconFailed = async () => {
const plugin = this.props.pluginItem;
const metadata = plugin.versionList[plugin.version];
if (metadata) {
this.setState({
pluginStatus: this.state.pluginStatus,
iconFailed: true
});
}
}

protected renderIcon(metadata: ChePluginMetadata): React.ReactNode {
if (metadata.icon) {
if (!this.state.iconFailed && metadata.icon) {
// return the icon
return <div className='che-plugin-icon'>
<img src={metadata.icon}></img>
<img src={metadata.icon} onError={this.onIconFailed}></img>
</div>;
}

Expand Down Expand Up @@ -277,7 +290,8 @@ export class ChePluginListItem extends React.Component<ListItemProps, ListItemSt

protected setStatus(status: PluginStatus): void {
this.setState({
pluginStatus: status
pluginStatus: status,
iconFailed: this.state.iconFailed
});
}

Expand Down

0 comments on commit 26e75a1

Please sign in to comment.