Skip to content

Commit

Permalink
ASSETS-88908 : Remove Console Error in Marketing Dashboard page and C…
Browse files Browse the repository at this point in the history
…ampaign Details when no image is found (#96)

* assets.js : Refactored code to eliminate console.log error
gmo-campaign-list.js : Removed  console.error("No campaign image found:", error);

* Eliminated  JavaScript errors when image is not found

* Display total assets = 0 when the campaign image does not exist
  • Loading branch information
TyroneAEM authored May 29, 2024
1 parent 106e2b2 commit f956a85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 8 additions & 2 deletions blocks/gmo-campaign-details/gmo-campaign-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@ export default async function decorate(block) {
buildProductCard(program);
try {
const imageObject = await searchAsset(program.programName, program.campaignName);
insertImageIntoCampaignImg(block,imageObject);
document.getElementById('totalassets').textContent = imageObject.assetCount;
if (imageObject){
insertImageIntoCampaignImg(block,imageObject);
document.getElementById('totalassets').textContent = imageObject.assetCount;
}
else
{
document.getElementById('totalassets').textContent = 0;
}
} catch (error) {
console.error("Failed to load campaign image:", error);
}
Expand Down
1 change: 0 additions & 1 deletion blocks/gmo-campaign-list/gmo-campaign-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ async function buildCampaignList(campaigns, numPerPage) {
iconImage.src = imageObject.imageUrl;
iconImage.alt = imageObject.imageAltText;
} catch (error) {
console.error("No campaign image found:", error);
}
// Append the image to the campaignIcon div
campaignIcon.appendChild(iconImage);
Expand Down
13 changes: 10 additions & 3 deletions scripts/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ export async function searchAsset(programName, campaignName, imageWidth = 80) {
// Asset retrieved successfully
const responseBody = await response.json();
const assetData = responseBody.results[0].hits[0];
const totalAssets = responseBody.results[0].nbHits;
const thumbnailURL = await getOptimizedDeliveryUrl(assetData.assetId, assetData['repo-name'], imageWidth);
return {imageUrl : thumbnailURL, imageAltText: assetData['repo-name'], assetCount: totalAssets};
if (assetData)
{
const totalAssets = responseBody.results[0].nbHits;
const thumbnailURL = await getOptimizedDeliveryUrl(assetData.assetId, assetData['repo-name'], imageWidth);
return {imageUrl : thumbnailURL, imageAltText: assetData['repo-name'], assetCount: totalAssets};
}
else
{
return null;
}
}
// Handle other response codes
throw new Error(`Failed to search asset: ${response.status} ${response.statusText}`);
Expand Down

0 comments on commit f956a85

Please sign in to comment.