Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-73613] refresh buildhistory widget in all cases #9624

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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();
});
});
Loading