Skip to content

Commit

Permalink
[JENKINS-73613] refresh buildhistory widget in all cases (#9624)
Browse files Browse the repository at this point in the history
* [JENKINS-73592] refresh buildhistory widget when page gets focus

* [JENKINS-73613] refresh buildhistory in all cases

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 authored Aug 24, 2024
1 parent de5cd41 commit 83541cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 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
30 changes: 21 additions & 9 deletions war/src/main/js/pages/project/builds-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +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) {
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 @@ -92,23 +107,16 @@ 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;
}

paginationPrevious.addEventListener("click", () => {
load({ "newer-than": buildHistoryPage.dataset.pageEntryNewest });
});

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

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

load();

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

0 comments on commit 83541cf

Please sign in to comment.