-
Notifications
You must be signed in to change notification settings - Fork 0
Render fulfillment container only when applicable #402
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,20 +7,43 @@ export default class extends Controller { | |
| this.load() | ||
| } | ||
|
|
||
| stripHtmlComments(input) { | ||
| let previous | ||
| let output = input | ||
|
|
||
| do { | ||
| previous = output | ||
| output = output.replace(/<!--[\s\S]*?-->/g, '') | ||
| } while (output !== previous) | ||
|
|
||
| return output | ||
| } | ||
|
Comment on lines
+10
to
+20
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change Copilot is suggesting is what I originally had. It would override the existing code in this helper method, which was suggested in a prior Copilot review. 🙃 |
||
|
|
||
| load() { | ||
| fetch(this.urlValue) | ||
| .then(response => response.text()) | ||
| .then(html => { | ||
| const parentElement = this.element.parentElement; | ||
| // Replace the entire element with the fetched HTML | ||
| this.element.outerHTML = html; | ||
| // Hide primo links if libkey link is present | ||
| if (parentElement.querySelector('.libkey-link')) { | ||
| const resultGet = parentElement.closest('.result-get'); | ||
| if (resultGet) { | ||
| const primoLinks = resultGet.querySelectorAll('.primo-link'); | ||
| // removing instead of hiding to avoid layout issues when selecting which link to highlight | ||
| primoLinks.forEach(link => link.remove()); | ||
| const parentElement = this.element.parentElement | ||
| // Strip HTML comments and trim whitespace | ||
| const cleanedHtml = this.stripHtmlComments(html).trim() | ||
| // Replace the entire element with the fetched HTML, or remove if empty | ||
| if (cleanedHtml) { | ||
| this.element.outerHTML = cleanedHtml | ||
| // Hide primo links if libkey link is present | ||
| if (parentElement.querySelector('.libkey-link')) { | ||
| const resultGet = parentElement.closest('.result-get') | ||
| if (resultGet) { | ||
| const primoLinks = resultGet.querySelectorAll('.primo-link') | ||
| // removing instead of hiding to avoid layout issues when selecting which link to highlight | ||
| primoLinks.forEach(link => link.remove()) | ||
| } | ||
| } | ||
| } else { | ||
| // Remove only this loader element | ||
| this.element.remove(); | ||
| // Remove result-get container if it's now empty (no fulfillment links and no other content) | ||
| if (!parentElement.textContent.trim()) { | ||
| parentElement.remove(); | ||
| } | ||
| } | ||
|
jazairi marked this conversation as resolved.
jazairi marked this conversation as resolved.
|
||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there actually HTML comments we need to strip? I see whitespace, but that's handled by the trim without this new method.