Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/KymaModules/KymaModulesAddModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export default function KymaModulesAddModule({
],
docsUrl:
module.metadata.annotations['operator.kyma-project.io/doc-url'],
icon: {
link: module.spec?.info?.icons[0]?.link,
name: module.spec?.info?.icons[0]?.name,
},
});
} else if (existingModule) {
existingModule.channels?.push({
Expand All @@ -128,6 +132,10 @@ export default function KymaModulesAddModule({
],
docsUrl:
module.metadata.annotations['operator.kyma-project.io/doc-url'],
icon: {
link: module.spec?.info?.icons[0]?.link,
name: module.spec?.info?.icons[0]?.name,
},
});
} else {
acc
Expand Down
37 changes: 36 additions & 1 deletion src/components/KymaModules/ModulesCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ import '@ui5/webcomponents/dist/features/InputElementsFormSupport.js';
import { ExternalLink } from 'shared/components/ExternalLink/ExternalLink';
import { useTranslation } from 'react-i18next';
import { spacing } from '@ui5/webcomponents-react-base';
import { useEffect, useState } from 'react';

async function isImageAvailable(url) {
try {
const response = await fetch(url, { method: 'HEAD' });
return response.ok;
} catch (error) {
return false;
}
}
async function getImageSrc(module) {
const defaultImage = '/assets/sap-logo.svg';
const iconLink = module.icon.link;

if (iconLink && (await isImageAvailable(iconLink))) {
return iconLink;
} else {
return defaultImage;
}
}

export default function ModulesCard({
module,
Expand All @@ -26,6 +46,15 @@ export default function ModulesCard({
checkIfStatusModuleIsBeta,
}) {
const { t } = useTranslation();
const [imageSrc, setImageSrc] = useState('');

useEffect(() => {
async function checkImage() {
const src = await getImageSrc(module);
setImageSrc(src);
}
checkImage();
}, [module]);

return (
<Card key={module.name} className="addModuleCard">
Expand All @@ -52,7 +81,13 @@ export default function ModulesCard({
: t('kyma-modules.no-version')}
</Text>
</div>
<img className="avatar" alt="SAP" src="\assets\sap-logo.svg" />
{imageSrc !== '' && (
<img
className="avatar"
alt={module.icon.name ? module.icon.name : 'SAP'}
src={imageSrc}
/>
)}
</StandardListItem>
<div className="content">
{module.docsUrl && (
Expand Down