Skip to content

fix(reports): persist layout settings and de-duplicate CSV group column - #57

Merged
Morialkar merged 1 commit into
mainfrom
fix/reports-backend-exports
Aug 1, 2026
Merged

fix(reports): persist layout settings and de-duplicate CSV group column#57
Morialkar merged 1 commit into
mainfrom
fix/reports-backend-exports

Conversation

@Morialkar

Copy link
Copy Markdown
Owner

Two of the reports defects from manual QA, both with regression tests. A third one (PDF pagination) turned out not to be what I first thought — see below.

(c) + (e) — the selected view never persisted

These two symptoms are one backend bug. ReportController::store and update declared validation rules for layout.fields and layout.group_order only. Laravel's validate() returns just the keys that carry a rule, so view_id, show_headers_only and per_page were stripped before the report was written:

{"layout":{"fields":[{"name":"Nom","visible":true,"order":1}]}}

So the chosen view never came back (e), and a saved report's PDF fell back to the default table because its stored layout had no view_id (c). show_headers_only and per_page were silently lost the same way — not reported yet, same cause.

The three keys are now declared explicitly.

(a) — group column duplicated in CSV

generateCsvResponse prepended the group-by field and then looped over every selected column. Since the grouped field is normally displayed as well, its header and its value appeared twice on every row. It is emitted once now.

(d) — PDF pagination: diagnosed, not fixed here

My first reading blamed page-break-inside: avoid on .group-section. Measured against the running stack, that is wrong — Dompdf ignores the rule on block containers; page counts were identical with and without it (7 → 7 on 20 small groups, 7 → 6 on 3 large ones). I reverted that speculative change rather than ship it.

What the numbers actually show, using the real dev report (247 records):

Mode Result
Table 15 pages, ~16 rows/page — normal, long titles wrap
Card view, 40 records 40 pages — one card per page
Card view, 247 records out of memory (256 MB exhausted in Dompdf)

The card in that view stacks 12 of its 16 fields in one column, making it ~370–420pt tall; two cards do not fit in an A4 text block, so each takes a page and wastes the rest. Removing page-break-inside from .report-card, dropping the 80px column min-height and tightening field margins each left it at one card per page — the height is arithmetic, not a break-rule artefact.

This matters more now, not less: fixing (c)/(e) above means saved reports will actually start rendering in card mode, so both the density problem and the OOM become reachable in normal use. Worth deciding on its own — most naturally alongside the print/PDF unification, where this layout gets consolidated anyway.

Verification

  • 183 API tests pass (1 pre-existing skip), Pint clean
  • new: layout keys survive create and update; CSV header emits the group field exactly once
  • pagination figures above measured by rendering the real saved report through ReportQueryService + Dompdf in the API container

…e CSV group column

Report save silently dropped part of the layout. Laravel's validate() only
returns keys that carry a rule, and store/update declared rules for
layout.fields and layout.group_order only, so view_id, show_headers_only and
per_page never reached the database. The consequences reported by manual QA:
the selected view never persisted, and a saved report's PDF fell back to the
default table because its layout carried no view_id.

Declare the three keys explicitly.

The CSV export also prepended the group-by field and then looped over every
selected column. Since the grouped field is normally displayed too, its
header and value appeared twice on every row. Emit it once.

Both are covered by regression tests.
@Morialkar
Morialkar merged commit 14ff1f9 into main Aug 1, 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.

1 participant