Skip to content

Commit

Permalink
Fix loading array settings on scheduled product page
Browse files Browse the repository at this point in the history
This commit fixes the scheduled product page loading issues,
which occur when job settings contain arrays.
Related ticket: https://progress.opensuse.org/issues/166154
  • Loading branch information
r-richardson committed Oct 10, 2024
1 parent d621070 commit 527e933
Show file tree
Hide file tree
Showing 2 changed files with 33 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
44 changes: 32 additions & 12 deletions assets/javascripts/openqa.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,39 @@ 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(', ')); // seperator 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 = a.textContent = match[0];
fragment.appendChild(a);
lastIndex = urlRegex.lastIndex;
}
if (lastIndex < value.length) {
fragment.appendChild(document.createTextNode(value.substring(lastIndex)));
}
return fragment.hasChildNodes() ? fragment : document.createTextNode(value);
}

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

0 comments on commit 527e933

Please sign in to comment.