Skip to content

Commit 49faa83

Browse files
committed
Table module : rowAttrs customization is unused
1 parent c978eaf commit 49faa83

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

src/Rudder/Table.elm

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,20 @@ type alias CsvExportData =
197197
The defaults should be fine, but customizations can be added and defined depending on each case.
198198
-}
199199
type alias Customizations row msg =
200-
{ tableContainerAttrs : List (Attribute (Msg msg))
201-
, tableAttrs : List (Attribute (Msg msg))
202-
, optionsHeaderAttrs : List (Attribute (Msg msg))
200+
{ tableContainerAttrs : List (Attribute msg)
201+
, tableAttrs : List (Attribute msg)
202+
, optionsHeaderAttrs : List (Attribute msg)
203203

204204
-- , caption : Maybe (HtmlDetails msg)
205-
, theadAttrs : List (Attribute (Msg msg))
205+
, theadAttrs : List (Attribute msg)
206206

207207
-- , tfoot : Maybe (HtmlDetails msg)
208-
, tbodyAttrs : List (Attribute (Msg msg))
209-
, rowAttrs : row -> List (Attribute (Msg msg))
208+
, tbodyAttrs : List (Attribute msg)
209+
, rowAttrs : row -> List (Attribute msg)
210+
211+
-- column-specific attributes
212+
, thAttrs : ColumnName -> List (Attribute msg)
213+
, tdAttrs : ColumnName -> List (Attribute msg)
210214
}
211215

212216

@@ -396,6 +400,10 @@ defaultCustomizations =
396400
-- , tfoot = Nothing
397401
, tbodyAttrs = []
398402
, rowAttrs = \_ -> []
403+
404+
-- column-specific attributes
405+
, thAttrs = \_ -> []
406+
, tdAttrs = \_ -> []
399407
}
400408

401409

@@ -774,24 +782,29 @@ encodeStorageEffect key filter =
774782
{- VIEW -}
775783

776784

785+
mapAttributes : List (Attribute msg) -> List (Attribute (Msg msg))
786+
mapAttributes =
787+
List.map (Html.Attributes.map ParentMsg)
788+
789+
777790
{-| The main view function for the table
778791
-}
779792
view : Model row msg -> Html (Msg msg)
780793
view (Model ({ columns, data, options } as model)) =
781794
let
782795
theadAttrs =
783-
options.customizations.theadAttrs
796+
options.customizations.theadAttrs |> mapAttributes
784797

785798
tbodyAttrs =
786-
options.customizations.tbodyAttrs
799+
options.customizations.tbodyAttrs |> mapAttributes
787800

788801
tableContainerAttrs =
789-
options.customizations.tableContainerAttrs
802+
options.customizations.tableContainerAttrs |> mapAttributes
790803

791804
tableView =
792-
table options.customizations.tableAttrs
793-
[ thead theadAttrs [ tableHeader columns model ]
794-
, tbody tbodyAttrs (tableBody columns data)
805+
table (options.customizations.tableAttrs |> mapAttributes)
806+
[ thead theadAttrs [ tableHeader columns model options.customizations.thAttrs ]
807+
, tbody tbodyAttrs (tableBody columns data options.customizations.rowAttrs options.customizations.tdAttrs)
795808
]
796809

797810
content =
@@ -800,7 +813,7 @@ view (Model ({ columns, data, options } as model)) =
800813
[ tableView ]
801814

802815
elems ->
803-
[ div options.customizations.optionsHeaderAttrs elems
816+
[ div (options.customizations.optionsHeaderAttrs |> mapAttributes) elems
804817
, tableView
805818
]
806819
in
@@ -902,20 +915,26 @@ viewCsvExportButton (Model model) =
902915
viewCsvExportButtonOption model.options.csvExport
903916

904917

905-
tableHeader : NonEmptyList.Nonempty (Column row msg) -> Sort a -> Html (Msg msg)
906-
tableHeader columns sort =
918+
tableHeader : NonEmptyList.Nonempty (Column row msg) -> Sort a -> (ColumnName -> List (Attribute msg)) -> Html (Msg msg)
919+
tableHeader columns sort thAttrsFun =
907920
tr [ class "head" ]
908921
(columns
909922
|> NonEmptyList.toList
910923
|> List.map (\column -> ( column.name, thClass sort column.name ))
911924
|> List.map
912925
(\( ColumnName name, thClassValue ) ->
926+
let
927+
thAttrs =
928+
thAttrsFun (ColumnName name)
929+
in
913930
th
914-
[ class thClassValue
915-
, rowspan 1
916-
, colspan 1
917-
, onClick (SortColumn (ColumnName name))
918-
]
931+
([ class thClassValue
932+
, rowspan 1
933+
, colspan 1
934+
, onClick (SortColumn (ColumnName name))
935+
]
936+
++ mapAttributes thAttrs
937+
)
919938
[ text name ]
920939
)
921940
)
@@ -935,15 +954,19 @@ thClass { sortBy, sortOrder } columnName =
935954
"sorting"
936955

937956

938-
tableBody : NonEmptyList.Nonempty (Column row msg) -> List row -> List (Html (Msg msg))
939-
tableBody columns data =
957+
tableBody : NonEmptyList.Nonempty (Column row msg) -> List row -> (row -> List (Attribute msg)) -> (ColumnName -> List (Attribute msg)) -> List (Html (Msg msg))
958+
tableBody columns data rowAttrs tdAttrs =
940959
let
941960
rowTable n =
942-
tr []
961+
tr (mapAttributes (rowAttrs n))
943962
(columns
944963
|> NonEmptyList.toList
945-
|> List.map (\{ renderHtml } -> Html.map ParentMsg (n |> renderHtml))
946-
|> List.map (\s -> td [] [ s ])
964+
|> List.map
965+
(\{ name, renderHtml } ->
966+
td
967+
(mapAttributes (tdAttrs name))
968+
[ Html.map ParentMsg (n |> renderHtml) ]
969+
)
947970
)
948971
in
949972
if List.length data > 0 then

0 commit comments

Comments
 (0)