Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-148054: Mnemonics list in a text block #2405

Merged
25 changes: 24 additions & 1 deletion libs/blocks/text/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ function decorateLinkFarms(el) {
});
}

export default function init(el) {
export async function loadMnemonicList(foreground) {
try {
const { base } = getConfig();
const stylePromise = new Promise((resolve) => {
loadStyle(`${base}/blocks/mnemonic-list/mnemonic-list.css`, resolve);
});
const loadModule = import('../mnemonic-list/mnemonic-list.js')
.then(({ decorateMnemonicList }) => decorateMnemonicList(foreground));
await Promise.all([stylePromise, loadModule]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we can use loadBlock (link), since it shares a lot of the functionality added here?

} catch (err) {
window.lana?.log(`Failed to load mnemonic list module: ${err}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robert-bogos might have some suggestions on how to categorize this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags are required to LANA logs in order to facilitate filtering them in Splunk. For this particular use case I would go for:

Suggested change
window.lana?.log(`Failed to load mnemonic list module: ${err}`);
window.lana?.log(`Failed to load mnemonic list module: ${err}`, { tags: 'errorType=error,module=text' });

You can see examples and read more about it in here.

}
}

export default async function init(el) {
el.classList.add('text-block', 'con-block');
let rows = el.querySelectorAll(':scope > div');
if (rows.length > 1) {
Expand Down Expand Up @@ -117,4 +131,13 @@ export default function init(el) {
lastActionArea.insertAdjacentElement('afterend', div);
div.append(lastActionArea);
}

const mnemonicList = el.querySelector('.mnemonic-list');
if (mnemonicList) {
const foreground = mnemonicList?.closest('.foreground');
if (foreground) {
mnemonicList.querySelectorAll('p').forEach((product) => product.removeAttribute('class'));
await loadMnemonicList(foreground);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you might be able to avoid some nesting here to make it a bit easier to follow.

Suggested change
const mnemonicList = el.querySelector('.mnemonic-list');
if (mnemonicList) {
const foreground = mnemonicList?.closest('.foreground');
if (foreground) {
mnemonicList.querySelectorAll('p').forEach((product) => product.removeAttribute('class'));
await loadMnemonicList(foreground);
}
}
const mnemonicList = el.querySelector('.mnemonic-list');
const foreground = mnemonicList?.closest('.foreground');
if (!foreground) return;
mnemonicList.querySelectorAll('p').forEach((product) => product.removeAttribute('class'));
await loadMnemonicList(foreground);

}
Loading