Skip to content

issue: Show a saved FlowView Filter as it is saved - #300

Merged
TheWitness merged 2 commits into
developfrom
fix/filter-save-and-edit
Oct 23, 2026
Merged

TheWitness merged 2 commits into
developfrom
fix/filter-save-and-edit

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Fixes several problems with saving a FlowView Filter and showing it on the FlowView tab.

Saved settings never shown (Sort Field, Listener, …)

flowview_request_vars() only seeded the page from the saved Filter when $_SESSION['sess_fv_<id>'] was missing. Cacti's validate_store_request_vars() never writes that key; it stores sess_fv_<id>_<name>. So the check was always true, but the seeded columns were only the chart ones, and the panel seeding was broken (strpos($c, 'panel') is 0 for panel_*). validate_store_request_vars() then filled everything else from the session or its defaults, and load_session_for_filter() skipped saved columns that were already set. The result: after a save, the tab kept showing the old Sort Field, Listener, Stream, cutoffs and timespan. A report could also keep running for the old Listener, which made it look as if the cached shards for listener A still applied after the Filter was switched to All.

  • Add flowview_filter_session_exists(), flowview_reset_filter_session() and flowview_seed_filter_request_vars().
  • Seed the page from the saved Filter whenever the session holds nothing for it.
  • save_filter() forgets the Filter's page settings and cached results, so the next view shows it as saved.

Selecting a Filter kept the previous Filter's Listener

changeQuery() sent the current page's device_id, ex_addr and usenat along with the newly selected filter, which overrode the selected Filter's own values. The time window and Domains toggle are still carried over.

Fields that were not saved

  • FlowView tab Save (save_filter_form()) now stores the Stream (ex_addr, with "no stream" stored as All) and the custom timespan dates. The Stream also counts toward the re-materialize check.
  • Save As keeps the Stream.
  • The Filter editor's timespan field is named predefined_timespan, but the save read timespan, so it was always stored as Custom (0).

Edit button

I couldn't reproduce Edit → "Filter: [new]" on Cacti 1.2.32. As a defensive fix, Edit/New now build urlPath + 'plugins/...' (previously '/plugins/...', which gives //plugins/... and is protocol-relative when Cacti is at /). Edit also falls back to the Filter id the page was rendered for.

Testing

  • New and updated Pest tests in tests/Unit/FilterEditAndSaveTest.php (14 new cases). Security and Unit suites: 373 passed. The 4 materialize tests that fail locally fail the same way on unmodified develop (Windows shell quoting only).
  • End to end on a scratch Cacti 1.2.32 + this branch:
    • Editor save of Sort Field and Listener shows the new values on the FlowView tab (before: stale flows).
    • Switching filters shows each Filter's own Listener (before: carried over).
    • FlowView tab Save persists the Sort Field.
    • Editor timespan persists (before: always Custom).
    • Leaving and returning via the top tab, then Edit, opens the selected Filter.

The FlowView tab only took a Filter's saved settings when the session held
none for it, but it checked for a 'sess_fv_<id>' entry that Cacti never
writes (validate_store_request_vars() stores 'sess_fv_<id>_<name>'), so the
page fell back to stale session values or its defaults.  A saved Sort Field,
Listener, Stream, cutoffs, timespan or chart panel did not appear after a
save, and a report could keep running for the old Listener.

- Seed the page from the saved Filter whenever the session holds nothing for
  it, and forget the Filter's page settings when it is saved from its editor
- Selecting a Filter takes its own Listener, Stream and NAT setting instead of
  carrying over the ones of the Filter shown before
- Save the Stream and custom timespan dates from the FlowView tab Save, keep
  the Stream with Save As, and save the timespan picked in the editor
- Build the Edit/New links without a doubled slash, and have Edit fall back
  to the Filter the page was drawn for

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 12:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Date-session handling can restore an outdated custom range or freeze a relative report window on later visits.

2 open issues
What changed in this PR

Updates FlowView’s saved-filter handling so the report page reflects saved settings and filter selection no longer carries over the previous filter’s Listener, Stream, or NAT setting.

Changes:

  • Adds helpers to detect, reset, and initialize filter page settings.
  • Persists Stream and custom dates, corrects editor timespan saving, and adjusts Edit/New links.
  • Adds regression tests and changelog entries.
File Description
tests/​Unit/​FilterEditAndSaveTest.php Adds coverage for saved settings, session handling, and navigation.
includes/​functions.php Updates saving, session helpers, and report-page controls.
flowview.php Initializes saved settings and preserves Stream in Save As.
CHANGELOG.md Documents the saved-filter fixes.

Review effort: Balanced

Comment thread includes/functions.php Resolved
Comment thread includes/functions.php Resolved
…ep preset windows moving

- save_filter_form() now forgets the Filter's page settings and cached
  results, so dates saved without pressing Go are shown on the next visit
- flowview_seed_filter_request_vars() no longer seeds the dates of a preset
  timespan; they stay empty in the session and load_data_for_filter() works
  them out on every visit, so the window moves with the preset
- Cover the helper edge cases for the 100% patch coverage gate

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit dfef994 into develop Oct 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants