Repository navigation
Conversation
34865a7 to
d89d08d
Compare
|
Thanks @thielema. This relates to
It's aiming to solve this problem, which is what #2798 was talking about:
By gathering all the info relating to each parameter into a table. It defines a new Option type inspired by Yesod's Option (used in web forms). My impression is that this draft is adding more new machinery than is needed. Here's a simpler idea (deriving the parser from the encoders) - what do you think of it ?
|
|
I thought I needed two option parsers, because |
|
It might be great to unify all the way to the CLI, but only if it doesn't create more headaches. And it doesn't sound urgent. |
d89d08d to
a20c968
Compare
|
If we have no immediate consensus on the single source of truth we can also first examine the ToDos I added to the draft. |
|
Can you clarify @thielema - do you agree with that "simpler fix" approach above ? |
I looked at your new push to this PR but don't see what you mean - where are those ? |
|
On Mon, 26 Oct 2026, Simon Michael wrote:
[10144?s=20&v=4] simonmichael left a comment (hledgerorg/hledger#2807)
Can you clarify @thielema - do you agree with that "simpler fix" approach above ?
I do not see how it is simpler. You somehow have to do a JOIN between option
parser/generator and link list generator, and this is a source of
potential inconsistency.
|
|
On Mon, 26 Oct 2026, Simon Michael wrote:
[10144?s=20&v=4] simonmichael left a comment (hledgerorg/hledger#2807)
we can also first examine the ToDos I added to the draft.
I looked at your new push to this PR but don't see what you mean - where are those ?
ReportParamError: BadAccum is a custom constructor whereas Calc is handled
by generic BadParamValue. I think that all errors can be handled by a
generic handler. Since wrong options due not happen if you click around,
this only happens to users that manually alter the URL. Thus I think they
know what they are doing and do not need individual error messages.
All link generators, i.e. *Links functions should be in the same module.
Not in Widgets.Common.
The other ToDos were discussed elsewhere.
|
a20c968 to
f942994
Compare
…ort options accumulationOption, calcOption: demonstration of collecting all required information in one place
f942994 to
a1f5ce9
Compare
|
Thanks @thielema. Continuing the discussion from here and #2821: We seem to agree on:
It's about 20 shared lines, versus about 65 in the draft, which looked boilerplatey to me. But your per-mode
I take your point. That earlier sketch kept the URL words consistent, but a links row could still omit a mode, add one, or order them differently. We could prevent that by putting the labels into -- | A multiple-choice URL parameter: its name, its modes in display order,
-- the mode used when it's absent (if any), and each mode's URL word,
-- label and tooltip.
data Param a = Param
{ paramName :: Text
, paramModes :: [a]
, paramDefault :: Maybe a
, paramWord :: a -> Text
, paramLabel :: Translations -> a -> (Text, Text)
}
-- | Read a parameter's value; empty or absent gives the default.
parseParam :: Param a -> Maybe Text -> Either ReportParamError (Maybe a)
-- | A links row choosing one of the parameter's modes.
-- The default mode's link omits the parameter.
paramLinks :: Eq a => Param a -> Translations -> Text -> r -> [(Text, Text)] -> a -> HtmlUrl r
paramLinks p trs heading route kept current =
linksRowClass (paramName p) heading
[ (lbl, tip, (route, kept ++ [paramSetting p a | Just a /= paramDefault p]), a == current)
| a <- paramModes p, let (lbl, tip) = paramLabel p trs a ]With An explicit mode list also gives us more freedom in the UI, to show a subset of the constructors (like calc), or a chosen order, independent of the type declarations. Once the parameter handling is settled, we can clarify the modules. Eg Would you like to try adapting #2807 along these lines ? Or if you prefer, I could try it. |
|
Any other opinions welcome too (@acinader). |
|
🍿 |
|
Sounds all reasonable to me. Since you have a clear idea how to reorganize the code I'd ask you and your LLM to prepare a new pull request. |
|
Will do. I made a start, and it's (of course) more complicated than it seems. If I get time to work it out and do sufficient testing, it might still get done before 1.99.6, scheduled for 11/1; if not I'll pick it up again after that. |
…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
|
Closed in favour of #2851. |
accumulationOption, calcOption: demonstration of collecting all required information in one place
I added several ToDo comments. I have not yet tried to remove duplicate parameter name literals like "calc". I defer that one to the next refactoring iteration.
I moved
Widgets.Common.calcLinkstoReportPageand think all link generators should be moved toReportPage. I also suggest to replace the long import lists inHandler.BalanceRby qualified imports fromReportPage.