Skip to content

Commit

Permalink
Fix loading array settings on scheduled product page
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Oct 9, 2024
1 parent d621070 commit 8c39e72
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions assets/javascripts/audit_log.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ function renderScheduledProductSettings(settings) {
const keyTd = document.createElement('td');
const valueTd = document.createElement('td');
keyTd.append(key);
valueTd.style.whiteSpace = 'pre-wrap';
valueTd.append(renderHttpUrlAsLink(value));
tr.append(keyTd, valueTd);
tbody.append(tr);
Expand Down
48 changes: 36 additions & 12 deletions assets/javascripts/openqa.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,43 @@ function renderComments(row) {
}

function renderHttpUrlAsLink(value) {
const span = document.createElement('span');
for (let match; (match = value.match(/https?:\/\/[^\s,]*/)); ) {
const url = match[0];
const link = document.createElement('a');
link.href = url;
link.target = 'blank';
link.appendChild(document.createTextNode(url));
span.appendChild(document.createTextNode(value.substr(0, match.index)));
span.appendChild(link);
value = value.substr(match.index + url.length);
if (!value) {
return document.createTextNode('');
}
span.appendChild(document.createTextNode(value));
return span;
if (Array.isArray(value)) {
const fragment = document.createDocumentFragment();
value.forEach((item, index) => {
fragment.appendChild(renderHttpUrlAsLink(item));
if (index < value.length - 1) {
fragment.appendChild(document.createTextNode(', ')); // rator between items
}
});
return fragment;
}
if (typeof value !== 'string') {
value = String(value);
}
const urlRegex = /https?:\/\/[^\s,]*/g;
let lastIndex = 0;
let match;
const fragment = document.createDocumentFragment();
while ((match = urlRegex.exec(value)) !== null) {
if (match.index > lastIndex) {
fragment.appendChild(document.createTextNode(value.substring(lastIndex, match.index)));
}
const a = document.createElement('a');
a.href = match[0];
a.textContent = match[0];
fragment.appendChild(a);
lastIndex = urlRegex.lastIndex;
}
if (lastIndex < value.length) {
fragment.appendChild(document.createTextNode(value.substring(lastIndex)));
}
if (!fragment.hasChildNodes()) {
return document.createTextNode(value);
}
return fragment;
}

function getXhrError(jqXHR, textStatus, errorThrown) {
Expand Down

0 comments on commit 8c39e72

Please sign in to comment.