Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions app/javascript/controllers/content_loader_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@ 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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 result-get container (no fulfillment links)
parentElement.remove()
}
Comment thread
jazairi marked this conversation as resolved.
Comment thread
jazairi marked this conversation as resolved.
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function with high complexity (count = 7): load [qlty:function-complexity]

}
Expand Down