Skip to content

Commit

Permalink
[JENKINS-73613] refresh buildhistory in all cases
Browse files Browse the repository at this point in the history
refresh the buildHistory widget instantly when the window gets focus,
e.g. after switching browser tabs but also when one was in another
application and clicks in the browser window.
When the window is visible it will update even when it has no focus,
when the window is hidden no calls to the controller will be done.

Additionally the buildHistory will be updated when it is not on the
first page. So e.g. when someone deletes a build, changes the display
name or the description or when a build is still running the page gets
updated.
  • Loading branch information
mawinter69 committed Aug 16, 2024
1 parent 539f905 commit a2386a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ THE SOFTWARE.
<div id="jenkins-build-history" class="app-builds-container__items">
</div>

<div class="app-builds-container__controls" id="controls">
<div class="app-builds-container__controls jenkins-hidden" id="controls">
<button class="jenkins-button jenkins-button--tertiary jenkins-card__unveil" id="up">
<l:icon src="symbol-arrow-left" />
<span class="jenkins-visually-hidden">${%Newer builds}</span>
Expand Down
32 changes: 20 additions & 12 deletions war/src/main/js/pages/project/builds-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,28 @@ const updateBuildsRefreshInterval = 5000;
*/
function load(options = {}) {
/** @type {QueryParameters} */
cancelRefreshTimeout();
const params = Object.assign({}, options, { search: pageSearchInput.value });
const paginationOrFirst =
buildHistoryPage.dataset.pageHasUp === "false" ||
"older-than" in params ||
"newer-than" in params;

// Avoid fetching if the page isn't active
// Avoid fetching if the page isn't visible
if (document.hidden) {
if (buildHistoryPage.dataset.pageHasUp === "false") {
createRefreshTimeout();
}
return;
}

createRefreshTimeout();

// When we're not on the first page and this is not a load due to pagination
// we need to set the correct value for older-than so we fetch the same set of runs
if (!paginationOrFirst) {
params["older-than"] = (
BigInt(buildHistoryPage.dataset.pageEntryNewest) + 1n
).toString();
}

fetch(ajaxUrl + toQueryString(params)).then((rsp) => {
if (rsp.ok) {
rsp.text().then((responseText) => {
Expand Down Expand Up @@ -95,13 +107,6 @@ function updateCardControls(parameters) {
!parameters.pageHasDown,
);

// We only want the list to refresh if the user is on the first page of results
if (!parameters.pageHasUp) {
createRefreshTimeout();
} else {
cancelRefreshTimeout();
}

buildHistoryPage.dataset.pageEntryNewest = parameters.pageEntryNewest;
buildHistoryPage.dataset.pageEntryOldest = parameters.pageEntryOldest;
buildHistoryPage.dataset.pageHasUp = parameters.pageHasUp;
Expand All @@ -112,7 +117,6 @@ paginationPrevious.addEventListener("click", () => {
});

paginationNext.addEventListener("click", () => {
cancelRefreshTimeout();
load({ "older-than": buildHistoryPage.dataset.pageEntryOldest });
});

Expand Down Expand Up @@ -143,4 +147,8 @@ document.addEventListener("DOMContentLoaded", function () {
});

load();

window.addEventListener("focus", function () {
load();
});
});

0 comments on commit a2386a8

Please sign in to comment.