Skip to content

Commit

Permalink
MWPW-143894 more robust for edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
npeltier committed Mar 20, 2024
1 parent 8f02868 commit bb26726
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions creativecloud/blocks/sidenav/sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,26 @@ function appendResources(rootNav, resourceLink) {
export default async function init(el) {
const libs = getLibs();
const rows = Array.from(el.children);
if (!rows || rows.length === 0) {
return;
}
const mainRow = rows[0];
const categoryRow = rows.length > 1 ? rows[1] : null;

await Promise.all([
import(`${libs}/features/spectrum-web-components/dist/theme.js`),
import(`${libs}/features/spectrum-web-components/dist/sidenav.js`),
import(`${libs}/features/spectrum-web-components/dist/search.js`),
import(`${libs}/features/spectrum-web-components/dist/checkbox.js`),
import(`${libs}/features/spectrum-web-components/dist/dialog.js`),
]);
const mainRow = rows[0];
const title = mainRow?.querySelector('h2')?.textContent.trim();
const rootNav = createTag('merch-sidenav', { title });
const searchText = mainRow?.querySelector('p > strong')?.textContent.trim();
const typeText = mainRow?.querySelector('p > em')?.textContent.trim();
appendSearch(rootNav, searchText);
// eslint-disable-next-line prefer-const
const resourcesLink = mainRow?.querySelector('a');
const categoryRow = rows.length > 1 ? rows[1] : null;
let endpoint = categoryRow?.querySelector('a');
if (endpoint) {
endpoint = localizeLink(endpoint.textContent.trim(), null, true);
Expand Down

0 comments on commit bb26726

Please sign in to comment.