Improve DHCP static leases interface (alternative)#3766
Conversation
…xtarea below Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
…t any possibility for code injection) Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
…hemes Signed-off-by: RD WebDesign <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
Signed-off-by: DL6ER <[email protected]>
…ew feedback Resolve merge conflict in style/pi-hole.css (keep both StaticDHCPTable styles and DNSSEC query log styles). Address outstanding reviewer feedback: - Change save button icon from floppy-disk to checkmark to clarify it confirms the row edit, not a final save - Update hint text to mention "Save & Apply" is still needed - Add hostname validation on the hostname cell (rejects spaces, commas, and other characters invalid in DNS names) Signed-off-by: Dominik <[email protected]>
When using the `v` flag, hyphens need to be escaped inside a character class. Signed-off-by: RD WebDesign <[email protected]>
Signed-off-by: RD WebDesign <[email protected]>
Signed-off-by: RD WebDesign <[email protected]>
Signed-off-by: RD WebDesign <[email protected]>
Fix regex adding `v` flag and fix line breaks to respect maximum lenght Note: these issues were not previously reported because there was a previous merge conflict. The prettier test was executed only after the merge conflict was resolved. Signed-off-by: RD WebDesign <[email protected]>
Signed-off-by: RD WebDesign <[email protected]>
- only show save button when needed - use fixed size and right aligned text for button column - highlight cells only on error and remove the highlight when is fixed - replace a few inline CSS styles with proper HTML tags - adjust CSS on specific themes Signed-off-by: RD WebDesign <[email protected]>
- replace DOMContentLoaded listener with a function and call it when needed - use javascript to update the CSS variable `--num-lines` - use CSS to calculate the elements height Signed-off-by: RD WebDesign <[email protected]>
bf69448 to
8ba9c79
Compare
- move and group some CSS selectors in the file, to make editing easier - use semi-transparent background color for .table-danger - reduce specificity for StaticDHCPTable cells and .line-numbers - remove unused and duplicated selectors Signed-off-by: RD WebDesign <[email protected]>
…data If enabled, the textarea can be edited, which triggers a table rewrite, resulting in the loss of all unsaved changes made to the table rows. This commit keeps the textarea disabled until all edited rows are saved. Signed-off-by: RD WebDesign <[email protected]>
aa89702 to
cec2e30
Compare
Dinamically created buttons were not showing bootstrap tooltips because
the event listener was created too early, before the buttons were
created (only previuosly existing buttons would show a tooltip).
Now, tooptip() function is called once, on the body element.
This attaches an event listener to the body. Every dynamically created
button will display the tooltip, without the need to call tooltip()
function. We need to manually call .tooltip("hide"), to remove tooltips
when buttons are clicked.
Signed-off-by: RD WebDesign <[email protected]>
Only accept valid hostnames: Previously, invalid hostnames were trigerring the cell highlighting, but invalid entries were still accepted when using the green "save" button. Now, hostnames are saved only if they pass the validation, like other values. Only allow IPv6 enclosed in square brackets: The previous validation function used to validate IPv6 didn't accept brackets, resulting in errors when an IPv6 was typed directly on the table cell. A new function was created to validate IPv6 enclosed in brackets. Signed-off-by: RD WebDesign <[email protected]>
…eens Also fix LCARS theme styles for the new interface Signed-off-by: RD WebDesign <[email protected]>
0d919cf to
ceddab9
Compare
When editing a row, two new buttons will be visible: Confirm and Cancel Signed-off-by: RD WebDesign <[email protected]>
The intention here is to improve readability Signed-off-by: RD WebDesign <[email protected]>
ceddab9 to
8c6bf7b
Compare
Signed-off-by: RD WebDesign <[email protected]>
|
This looks really nice now. |
|
Hmmmm... What did you type in your test? I'm not sure if we can validate that in every case. The issue here is: we don't have a fixed number of items to make sure the second one is always an IP. On the table, we can always say the second column should be an IP, but when the text is typed on the textarea, the second item can be a hostname... or an invalid IP, or many other options. |
|
You are correct - we can't know that the second item in from the textarea is an invalid IP when it could also be something different (id, tag). Scratch my idea. |
There was a problem hiding this comment.
Pull request overview
This PR provides an alternative UX for managing static DHCP leases by introducing an editable table view that stays in sync with the underlying dhcp.hosts textarea, while improving validation, tooltips, and styling across themes.
Changes:
- Added a dedicated “Static DHCP” table UI with per-row confirm/cancel behavior and synchronized textarea + line numbers.
- Expanded client-side validators (IPv4/IPv6 helpers, bracketed IPv6, stricter hostname checks) and applied them to table editing.
- Updated core/theme CSS to support the new layout, hint messaging, and validation highlighting.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
style/themes/lcars.css |
Theme-specific tweaks for button sizing and the new static DHCP hint/disabled-textarea tooltip styles. |
style/themes/high-contrast.css |
Adds StaticDHCPTable-specific styling hooks for danger/success highlighting. |
style/themes/high-contrast-dark.css |
Adds StaticDHCPTable-specific styling hooks for danger/success highlighting. |
style/pi-hole.css |
Adds layout/UX CSS for the StaticDHCPTable, hint message, textarea wrapper, and line numbers. |
settings-dhcp.lp |
Reworks the static DHCP section layout: introduces the table UI, advanced notes, examples cards, and textarea wrapper with line numbers. |
scripts/js/utils.js |
Adds IPv4/IPv6 convenience validators, bracketed IPv6 validation, stricter hostname validation, and updates MAC/hostname trimming behavior. |
scripts/js/settings-dhcp.js |
Implements the static DHCP table rendering/editing workflow, per-row save/cancel, validation highlighting, tooltips, and textarea line numbering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c877479 to
c574020
Compare
This function tries to use a simplified version of the dnsmasq code used to parse dhcp-host options. Also, use the parse function when we cancel edit operation on a line Signed-off-by: RD WebDesign <[email protected]>
c574020 to
62132c8
Compare
Also fix 2 issues on validation functions: - better regex for validateMAC() - make sure validateIPv6Brackets() correctly trims the value before validation Signed-off-by: RD WebDesign <[email protected]>
09a7fcc to
e6fe47c
Compare
|
I think the new parse function will solve some issues, like when "infinite" was considered as hostname (Example: Also, now the position of the items are not really important. The function will parse them and, if valid, will show them on the table, in the correct columns. |
…ping Signed-off-by: RD WebDesign <[email protected]>
Now we allow invalid values on the table and highlight them. This will allow users to find errors in data already saved on pihole.toml. New parsing rules added - The line is also considered as "advanced" if: - the line contains an asterisk; - more than one IP is found; - more than one Mac Address is found; - more than one hostname is found. The table also highlights invalid data onload, before a row is clicked. Signed-off-by: RD WebDesign <[email protected]>
74af516 to
a88b579
Compare
What does this PR aim to accomplish?
This is an alternative attempt to create a better user interface to edit Static DHCP leases.
This version is based on #3565 and all previous commits were kept, to avoid losing authorship credits.
Main differences found on this version:
By submitting this pull request, I confirm the following:
git rebase)