[fix] Highlighting IP in go to IP instead of deleting previous rows #73#194
[fix] Highlighting IP in go to IP instead of deleting previous rows #73#194pranshustuff wants to merge 8 commits into
Conversation
…penwisp#73 Instead of deleting previous rows when fetching IP in search, it now scrolls to the IP till it is visible on screen and highlights it. Fixes openwisp#73
Same as above. Fixes openwisp#73.
To pass QA checks Fixes openwisp#73.
Same as above. Fixes openwisp#73.
Fixing Prettier style, again. Fixes openwisp#73.
|
I've passed the QA checks for subnet.js. It was showing format differences for jstree ad plotly but those files I haven't changed. |
nemesifier
left a comment
There was a problem hiding this comment.
Thanks @pranshustuff, this is a sensible UX fix for #73: when the target IP is already rendered, scroll to and highlight it rather than clearing and refetching the visualization.
A few notes:
- Highlight vs scroll timing. The scroll animation is 500ms and the highlight is cleared after 500ms, so on a long scroll the yellow flash may fade before the user's eye lands on it. Consider clearing the highlight after the scroll completes (animation callback) or using a slightly longer highlight.
- Only used IPs get an id. The
id="addr_<id>"is added only insideif (addr.used), so "go to" an unused-but-rendered IP will not find a target and falls through to the refetch path. That may be acceptable, just confirm it is intentional. - ID sanitization. Ensure
normalizeIPproduces an id safe for a DOM id/selector for IPv6 too (no colons), otherwise `` will break for v6 addresses. - Prefer toggling a CSS class (e.g.
.highlight) over inlinecss("background-color", "yellow"), so the color respects the admin theme (including dark mode).
Minor stuff; the core behavior is a good improvement. A small QUnit/JS test or at least manual confirmation for both an on-page hit and an off-page (refetch) case would be nice.
nemesifier
left a comment
There was a problem hiding this comment.
Thanks @pranshustuff, this is a sensible UX fix for #73: when the target IP is already rendered, scroll to and highlight it rather than clearing and refetching the visualization.
A few notes:
- Highlight vs scroll timing. The scroll animation is 500ms and the highlight is cleared after 500ms, so on a long scroll the yellow flash may fade before the user's eye lands on it. Consider clearing the highlight after the scroll completes (animation callback) or using a slightly longer highlight.
- Only used IPs get an id. The
id="addr_<id>"is added only insideif (addr.used), so "go to" an unused-but-rendered IP will not find a target and falls through to the refetch path. That may be acceptable, just confirm it is intentional. - ID sanitization. Ensure
normalizeIPproduces an id safe for a DOM id/selector for IPv6 too (no colons), otherwise$("#addr_" + id)will break for v6 addresses. - Prefer toggling a CSS class (e.g.
.highlight) over inlinecss("background-color", "yellow"), so the color respects the admin theme (including dark mode).
Minor stuff; the core behavior is a good improvement. A small QUnit/JS test or at least manual confirmation for both an on-page hit and an off-page (refetch) case would be nice.
📝 WalkthroughWalkthroughThe pull request enhances the subnet IP lookup feature by adding stable DOM IDs to used address elements and redesigning the "Go To IP" navigation flow. Used IP addresses now receive an Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with 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.
Inline comments:
In `@openwisp_ipam/static/openwisp-ipam/js/subnet.js`:
- Around line 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.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 73766b1a-f84a-484b-9368-c91d576bc09c
📒 Files selected for processing (2)
openwisp_ipam/static/openwisp-ipam/css/admin.cssopenwisp_ipam/static/openwisp-ipam/js/subnet.js
💤 Files with no reviewable changes (1)
- openwisp_ipam/static/openwisp-ipam/css/admin.css
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Python==3.13 | django~=5.2.0
- GitHub Check: Python==3.13 | django~=5.1.0
- GitHub Check: Python==3.12 | django~=5.2.0
- GitHub Check: Python==3.11 | django~=4.2.0
- GitHub Check: Python==3.12 | django~=4.2.0
- GitHub Check: Python==3.10 | django~=5.1.0
- GitHub Check: Python==3.12 | django~=5.1.0
- GitHub Check: Python==3.11 | django~=5.2.0
- GitHub Check: Python==3.11 | django~=5.1.0
- GitHub Check: Python==3.10 | django~=4.2.0
- GitHub Check: Python==3.10 | django~=5.2.0
🔇 Additional comments (1)
openwisp_ipam/static/openwisp-ipam/js/subnet.js (1)
59-70: LGTM!
| // 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; |
There was a problem hiding this comment.
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.
Checklist
Reference to Existing Issue
Fixes #73
Please describe these changes.
Instead of deleting previous rows when fetching IP in search, it now scrolls to the IP till it is visible on screen and highlights it.
Screenshot
simplescreenrecorder-2025-10-02_12.24.33.mp4