fix(reports): export what is on screen instead of the last saved report - #59
Merged
Conversation
Both export handlers built a query AST and layout from the live editor state,
then discarded them whenever a saved report was selected and called
GET /reports/{id}/export/... instead, which re-runs the stored report.
The on-screen preview meanwhile posts the live state to /reports/preview, so
the two disagreed: changing columns, sorting or grouping updated the preview
but produced a byte-identical export, and the configuration had to be saved
before it could be exported at all.
Exports now always post the live state to the preview endpoints, so the file
matches the preview it was requested from. The client keeps the report name
for the downloaded filename, since those endpoints answer with a generic one.
The query AST and layout are now built once and shared by the preview, the
save payload and both exports, so they cannot drift apart again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes defect (b) from manual QA, and with it the "two exports come out identical" symptom.
The bug
handleExportCsvandhandleExportPdfeach built a query AST and a layout from the live editor state — and then threw them away whenever a saved report was selected, callingGET /reports/{id}/export/csv|pdf, which re-runs the stored report.The on-screen preview does the opposite: it posts the live state to
/reports/preview. So the two disagreed:The change
Exports now always post the live state to the preview endpoints, so a downloaded file matches the preview it was requested from. The client keeps the report name for the filename, since those endpoints answer with a generic
rapport_apercu.*.The query AST and layout are now built once and shared by the preview, the save payload and both exports — they were duplicated in four places, which is how they drifted apart.
Verification
Driven against the running stack. With a saved report selected whose stored
selectis["Nom Complet"], andPrénomticked on screen without saving:GET /reports/{id}/export/csv"Nom Complet"POST /reports/preview/csv"Nom Complet",PrénomThe network log confirms the click now issues
POST /api/v1/reports/preview/csvwhile a report is selected.Also: 65/65 client tests (2 new, asserting both exports POST the live configuration with a saved report selected),
tsc -b, ESLint, Prettier.Note
ReportBuilderPageis now exported so it can be rendered in tests; the route itself is unchanged.