Skip to content

dev: web: Param, one description of each multiple-choice URL parameter - #2851

Merged
simonmichael merged 4 commits into
mainfrom
web-params
Nov 15, 2026
Merged

simonmichael merged 4 commits into
mainfrom
web-params

Conversation

@simonmichael

Copy link
Copy Markdown
Member

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.Param module gives each one a single Param value: 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 links
  • paramPhrase: the closed options summary's names
data Param a = Param
  { paramName     :: Text
  , paramModes    :: [a]
  , paramWord     :: a -> Text
  , paramRowLabel :: Translations -> Text
  , paramLabel    :: Translations -> a -> (Text, Text)
  }

Three commits: calc (with the module), accum, list and sort. They remove parseAccum, parseCalc, parseListMode, parseSort, accumWord, calcWord, listWord, accumulationLinks, calcLinks, listModeLinks, sortLinks and BadAccum, 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:

  • A bad accum value shows the generic bad-parameter message, like the others.
  • The journal and register pages carry only a valid calc value on their links.
  • The list/tree row's class is now 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 *Links functions.

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

…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
@simonmichael

Copy link
Copy Markdown
Member Author

@thielema, @acinader: see what you think

@simonmichael simonmichael added the web The hledger-web tool. label Nov 13, 2026
@thielema

Copy link
Copy Markdown
Contributor

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 paramPhrase but accumParam etc.
I would call the module Web.Parameter, people can abbreviate to Param at the import site. Then module could be imported with qualification and functions called like Param.calc instead of calcParam.

@thielema

Copy link
Copy Markdown
Contributor

I would not mix generic definitions around Parameter and instances of parameters in one module. I would keep Web.Parameter for basic definitions and define instances of parameters in another module, I think ReportPage is already the right module for that purpose.

@thielema

Copy link
Copy Markdown
Contributor

Can ReportPage.intervalLinks also be written using Web.Parameter?

…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
@simonmichael

simonmichael commented Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for the review @thielema.

I'm ok with the current naming/importing:

  • verbs (functions) that work on any parameter are called paramACTION; nouns (parameters) are NAMEParam. We use similar conventions elsewhere.
  • Param is a reasonable abbreviation, and I prefer not to see multiple ways of naming things in code.

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.

@simonmichael

Copy link
Copy Markdown
Member Author

I prefer to punt on it for now

(Personally. When someone wants to work on it, we can try.)

@simonmichael
simonmichael merged commit 63cdf4f into main Nov 15, 2026
2 checks passed
@simonmichael
simonmichael deleted the web-params branch November 15, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

web The hledger-web tool.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants