Skip to content
Open
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
1 change: 0 additions & 1 deletion openwisp_ipam/static/openwisp-ipam/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ section.subnet-visual {
background: rgba(149, 10, 10, 1);
border: 1px solid rgba(0, 0, 0, 0.4);
}

.subnet-visual .page {
display: inline;
}
Expand Down
49 changes: 35 additions & 14 deletions openwisp_ipam/static/openwisp-ipam/js/subnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function initHostsInfiniteScroll(
var id = normalizeIP(addr.address);
if (addr.used) {
var uuid = ip_uuid[addr.address];
var id_attr = 'id="addr_' + id + '"';
//note 1234 was passed as a dummy to be later on replaced in the script
return (
'<a class = "used" href=\"' +
Expand All @@ -64,7 +65,9 @@ function initHostsInfiniteScroll(
addr.address +
"&amp;subnet=" +
current_subnet +
'"onclick="return showAddAnotherPopup(this);">' +
'" ' +
id_attr +
' onclick="return showAddAnotherPopup(this);">' +
addr.address +
"</a>"
);
Expand Down Expand Up @@ -111,20 +114,38 @@ function initHostsInfiniteScroll(
function goTo() {
var input = $("#goto-input").val().toLowerCase().trim();
validateIp(input, function (isValid) {
if (isValid) {
$("#invalid-address").hide();
if (input !== searchQuery) {
searchQuery = input;
nextPageUrl =
"/api/v1/ipam/subnet/" + current_subnet + "/hosts/?start=" + searchQuery;
$("#subnet-visual").empty();
fetchedPages = [];
lastRenderedPage = 0;
busy = false;
onUpdate();
}
} else {
if (!isValid) {
$("#invalid-address").show();
return;
}
$("#invalid-address").hide();
var id = normalizeIP(input);
var target = $("#addr_" + id);
if (target.length) {
// IP is already on the page
$("#subnet-visual").animate(
{
scrollTop:
target.offset().top -
$("#subnet-visual").offset().top +
$("#subnet-visual").scrollTop(),
},
500,
);
target.css("background-color", "yellow");
setTimeout(function () {
target.css("background-color", "");
}, 500);
} else {
// IP not on page, re-fetch
searchQuery = input;
nextPageUrl =
"/api/v1/ipam/subnet/" + current_subnet + "/hosts/?start=" + searchQuery;
$("#subnet-visual").empty();
fetchedPages = [];
lastRenderedPage = 0;
busy = false;
Comment on lines +140 to +147

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Preserve pagination state instead of clearing it in go-to fallback

Line 144 through Line 147 still wipe the rendered list and cached pages. That discards navigation history and reintroduces the “can’t scroll back after go to IP” behavior for addresses not already in DOM. Keep existing rows/state and fetch/scroll until the target becomes visible instead of resetting fetchedPages/lastRenderedPage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openwisp_ipam/static/openwisp-ipam/js/subnet.js` around lines 140 - 147, The
code resets the UI and pagination state (calls $("`#subnet-visual`").empty() and
clears fetchedPages/lastRenderedPage) in the go-to-IP fallback, which loses
navigation history; instead do not clear the existing DOM or pagination caches —
only set searchQuery and nextPageUrl
("/api/v1/ipam/subnet/"+current_subnet+"/hosts/?start="+searchQuery") and then
drive the existing fetch/scroll loop to request additional pages until the
target IP is rendered and visible; remove the $("`#subnet-visual`").empty(), do
not reset fetchedPages or lastRenderedPage, and ensure busy is managed (set true
when starting the fetch loop and false when done) so the current fetch/scroll
machinery will append pages and allow scrolling back.

onUpdate();
}
});
}
Expand Down
Loading