Skip to content

Add customizations for th, tr, and td tags in Table module#14

Merged
clarktsiory merged 1 commit intoNormation:masterfrom
skaerg:rowAttrs_customization_unused
Jan 14, 2026
Merged

Add customizations for th, tr, and td tags in Table module#14
clarktsiory merged 1 commit intoNormation:masterfrom
skaerg:rowAttrs_customization_unused

Conversation

@skaerg
Copy link
Contributor

@skaerg skaerg commented Jan 13, 2026

This PR aims to

  • use the rowAttrs customization since it was present in the code but actually unused until now.
  • rename rowAttrs to trAttrs
  • change the type of the customizations so that all instances of Attribute (Msg msg) are replaced with Attribute msg so that it is easier for the parent component to create attributes that depend on parent msgs
  • add the option to add column-specific html attributes on entries (tdAttrs) and on columns themselves (thAttrs)

@skaerg skaerg requested a review from clarktsiory January 13, 2026 10:12
@skaerg skaerg marked this pull request as draft January 13, 2026 10:46
@skaerg skaerg force-pushed the rowAttrs_customization_unused branch from 72d838d to f5ae733 Compare January 13, 2026 10:57
@skaerg skaerg marked this pull request as ready for review January 13, 2026 10:57
@skaerg skaerg force-pushed the rowAttrs_customization_unused branch 2 times, most recently from 6664a4c to 92d8b43 Compare January 13, 2026 12:53
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ! Since it's always a list, and repeats across functions, it could even be factored out

Could you also update the title, so that we have Table in it ? (the library contains something else than table, it makes it easier to trace)

Comment on lines +784 to +785
mapAttribute =
Html.Attributes.map ParentMsg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be extracted outside of the view

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could even be

mapAttributes =
    List.map Html.Attributes.map ParentMsg

let
rowTable n =
tr []
tr (List.map (Html.Attributes.map ParentMsg) (rowAttrs n))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be

Suggested change
tr (List.map (Html.Attributes.map ParentMsg) (rowAttrs n))
tr (mapAttributes (rowAttrs n))

|> List.map
(\{ renderHtml, entryAttrs } ->
td
(List.map (Html.Attributes.map ParentMsg) entryAttrs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(List.map (Html.Attributes.map ParentMsg) entryAttrs)
(mapAttributes entryAttrs)

, colspan 1
, onClick (SortColumn (ColumnName name))
]
++ List.map (Html.Attributes.map ParentMsg) columnAttrs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
++ List.map (Html.Attributes.map ParentMsg) columnAttrs
++ mapAttributes columnAttrs

Comment on lines +788 to +808
@@ -800,7 +805,7 @@ view (Model ({ columns, data, options } as model)) =
[ tableView ]

elems ->
[ div options.customizations.optionsHeaderAttrs elems
[ div (options.customizations.optionsHeaderAttrs |> List.map mapAttribute) elems
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all could be |> mapAttributes since they are are lists

@skaerg skaerg changed the title rowAttrs customization is unused Table module : rowAttrs customization is unused Jan 13, 2026
@skaerg skaerg force-pushed the rowAttrs_customization_unused branch from 92d8b43 to 335db4d Compare January 13, 2026 15:47
@skaerg skaerg requested a review from clarktsiory January 13, 2026 15:48
Comment on lines +121 to +122
, columnAttrs : List (Attribute msg)
, entryAttrs : List (Attribute msg)
Copy link
Contributor

@clarktsiory clarktsiory Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this changes the API of Column significantly : we will need to provide explicit "customizations" on the column every time we instantiate it.
If we are ready to have them within Column, we may need to provide a "column builder" for convenience, as it would more often be empty...

But this primarily raises some inconsistency in the API, these clearly belong to Customizations.
Moreover, the naming of customizations are based on the HTML element that is being customized, respectively th and td here.

And it's true that they are "cell"/"header"-specific, so, is it not possible to have :

type alias Customizations row msg =
   ...
   , thAttrs : Column row msg -> List (Attribute msg)
   , tdAttrs : Column row msg -> List (Attribute msg)

?

@skaerg skaerg force-pushed the rowAttrs_customization_unused branch from 335db4d to 49faa83 Compare January 14, 2026 09:05
@skaerg skaerg requested a review from clarktsiory January 14, 2026 09:20
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great !
Edit : but see the comment below

Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the title of the PR is being divergent with the change that is made, and it indicates there is something still wrong : rowAttrs should be trAttrs 😅

And the real thing this PR is doing is : adding customizations for tr, td, th

@skaerg skaerg changed the title Table module : rowAttrs customization is unused Add customizations for th, tr, and td tags in Table module Jan 14, 2026
@skaerg skaerg force-pushed the rowAttrs_customization_unused branch from 49faa83 to d05ca9d Compare January 14, 2026 11:07
@skaerg skaerg requested a review from clarktsiory January 14, 2026 11:08
@clarktsiory clarktsiory enabled auto-merge January 14, 2026 14:45
@clarktsiory clarktsiory merged commit 7ec66cd into Normation:master Jan 14, 2026
4 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.

2 participants