Repository navigation
dev: web: Param, one description of each multiple-choice URL parameter - #2851
Conversation
…r; calc uses it A multiple-choice URL parameter such as calc was described in several places that nothing kept in agreement: its parser, its encoder, its row of links, the options summary's names for it, and its name as a string literal across the handlers (#2798). Now a Param value holds its name, its modes in display order, each mode's URL word, and its labels, and the parser (parseParam, readParam, lookupParam), the row of links (paramLinks), the URL settings (paramSetting, paramSettings) and the options summary's names (paramPhrase) are made from it. The new Hledger.Web.Param module also takes the generic links row renderer (linksRow, linksRowClass, linksRowGroups) from Widget.Common, which now imports it, avoiding an import cycle. calc is the first parameter converted, replacing parseCalc, calcWord and calcLinks. Its labels and translator comments are unchanged, so its translations are too. The journal and register pages now carry only a valid calc value on their links, rather than any value given. Supersedes #2807 and #2821, following the design discussed in #2807. AI usage: Claude Fable 5.1/Opus 5.5, ~51k output tokens
A bad accum value in a url now shows the same message as other bad
parameter values ("The accum parameter has a value this page does not
know"), instead of its own.
accumParam replaces parseAccum, accumWord, accumulationLinks and the
BadAccum error, and the accum literals in the handlers, App.hs's kept
parameters, startupUrlState and the options summary. Its modes keep the
links' order, so the H key still toggles Ending balances.
AI usage: Claude Opus 5.5, ~8k output tokens
listParam and sortParam replace parseListMode, parseSort, listWord, listModeLinks and sortLinks, the journal and register pages' own checks of the sort parameter, and the list and sort literals in the handlers, App.hs's kept parameters, startupUrlState and the options summary. sort, a yes/no choice, is a Param Bool. The accounts list/tree row's class is now its parameter's name, list, and hledger.js's t key finds it by that. AI usage: Claude Opus 5.5, ~9k output tokens
|
One quick note: I think the Web.Param module is a good example of the antipattern of unqualified imports and then trying to resolve conflicts with a naming convention that is not followed by consistently ... you have |
|
I would not mix generic definitions around |
|
Can |
…e generic part Following review: Hledger.Web.Param now holds only the generic definitions (the Param type, its functions, and the links row renderer), and the four parameters, accumParam, calcParam, listParam and sortParam, are in Hledger.Web.ReportPage with the rest of the report pages' parameter handling. optionsSummary and registerKeptParams, which use them, move from Widget.Common to ReportPage too, avoiding an import cycle; the sidebar (balanceReportAsHtml) now takes the parameters its register links keep. AI usage: Claude Opus 5.5, ~15k output tokens
|
Thanks for the review @thielema. I'm ok with the current naming/importing:
I have moved the definitions to ReportPage as you suggest. optionsSummary had to move too. intervalLinks doesn't fit the pattern quite as easily, because of its freeform parse. I prefer to punt on it for now. |
(Personally. When someone wants to work on it, we can try.) |
In hledger-web, each multiple-choice URL parameter (accum, calc, list, sort) was described in several places that nothing kept in agreement (#2798): a parser, a word encoder, a row of links, the options summary's names,
startupUrlState, each handler's own parameter builders and checks, and its name as a string literal in many places.Following the design discussed in #2807, a new
Hledger.Web.Parammodule gives each one a singleParamvalue: its name, its modes in display order, each mode's URL word, and its labels. Everything else is made from that:parseParam/readParam/lookupParam: parsing (strict on report pages, lenient on journal and register)paramLinks: the row of links (whose CSS class is the parameter name)paramSetting/paramSettings: the URL settings carried on linksparamPhrase: the closed options summary's namesThree commits: calc (with the module), accum, list and sort. They remove
parseAccum,parseCalc,parseListMode,parseSort,accumWord,calcWord,listWord,accumulationLinks,calcLinks,listModeLinks,sortLinksandBadAccum, and the four parameter names no longer appear as literals outside Param.hs and the tests. The generic links row renderer moves to the new module too, avoiding an import cycle.Small visible changes:
list; hledger.js's t key follows.Labels and translator comments are unchanged, so translations are unaffected; hledger.pot only loses the old accum error message.
Out of scope, possible follow-ups: value (parameterised), interval (free text), the on/off flags, moving the remaining
*Linksfunctions.Tests: new unit tests that each Param's words are distinct and that parsing handles valid, empty and unknown words; server tests pass. The browser tests (H, S, t keys) are left to CI's web-e2e job.
Supersedes #2807 and #2821.
AI usage: Claude Fable 5.1/Opus 5.5, ~68k output tokens