Skip to content

Commit

Permalink
Merge pull request #1313 from hlxsites/fix-overviewtab-hide
Browse files Browse the repository at this point in the history
fix for overview tab hide in products page if no response from api
  • Loading branch information
davenichols-DHLS authored Dec 17, 2024
2 parents f5617fa + 9aaf8bd commit 926283b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions blocks/page-tabs/page-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ function hasSpecifications(productResponse) {
return productResponse?.raw?.numattributes > 0;
}

function hasOverview(productResponse) {
return productResponse?.raw?.richlongdescription;
}

export default async function decorate(block) {
const response = await getProductResponse();
let productResponse;
Expand Down Expand Up @@ -157,11 +161,24 @@ export default async function decorate(block) {
return hasProducts(productResponse);
case 'product-details':
return hasParts(productResponse);
case 'overview':
return hasOverview(productResponse);
default:
return true;
}
});

// Check if 'overview' tab exists
const hasOverviewTab = filteredTabs.some((tab) => tab.id === 'overview');

// Set currentTab to 'overview' if it exists, otherwise 'specifications'
currentTab = hasOverviewTab ? 'overview' : 'specifications';

// If 'overview' tab does not exist, reload the page with '#specifications' in the URL
if (!hasOverviewTab) {
window.location.hash = '#specifications';
}

const navList = createTabList(filteredTabs, currentTab);

// For Mobile View
Expand Down
1 change: 1 addition & 0 deletions tools/importer/transformers/cardList.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const URLS_TO_BLOCK_MAP = [
const createCardList = (main, document) => {
const url = document.querySelector('[property="og:url"]')?.content;
if (url) {
// eslint-disable-next-line max-len
const blockName = URLS_TO_BLOCK_MAP.find((item) => url.endsWith(item.url) || url.includes(item.url))?.blockName;
if (blockName) {
const block = [[blockName], ['']];
Expand Down

0 comments on commit 926283b

Please sign in to comment.