Skip to content

Commit 92d8b43

Browse files
committed
rowAttrs customization is unused
1 parent c978eaf commit 92d8b43

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

src/Rudder/Table.elm

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ type alias Column row msg =
118118
{ name : ColumnName
119119
, renderHtml : row -> Html msg
120120
, ordering : Ordering row
121+
, columnAttrs : List (Attribute msg)
122+
, entryAttrs : List (Attribute msg)
121123
}
122124

123125

@@ -197,16 +199,16 @@ type alias CsvExportData =
197199
The defaults should be fine, but customizations can be added and defined depending on each case.
198200
-}
199201
type alias Customizations row msg =
200-
{ tableContainerAttrs : List (Attribute (Msg msg))
201-
, tableAttrs : List (Attribute (Msg msg))
202-
, optionsHeaderAttrs : List (Attribute (Msg msg))
202+
{ tableContainerAttrs : List (Attribute msg)
203+
, tableAttrs : List (Attribute msg)
204+
, optionsHeaderAttrs : List (Attribute msg)
203205

204206
-- , caption : Maybe (HtmlDetails msg)
205-
, theadAttrs : List (Attribute (Msg msg))
207+
, theadAttrs : List (Attribute msg)
206208

207209
-- , tfoot : Maybe (HtmlDetails msg)
208-
, tbodyAttrs : List (Attribute (Msg msg))
209-
, rowAttrs : row -> List (Attribute (Msg msg))
210+
, tbodyAttrs : List (Attribute msg)
211+
, rowAttrs : row -> List (Attribute msg)
210212
}
211213

212214

@@ -779,19 +781,22 @@ encodeStorageEffect key filter =
779781
view : Model row msg -> Html (Msg msg)
780782
view (Model ({ columns, data, options } as model)) =
781783
let
784+
mapAttribute =
785+
Html.Attributes.map ParentMsg
786+
782787
theadAttrs =
783-
options.customizations.theadAttrs
788+
options.customizations.theadAttrs |> List.map mapAttribute
784789

785790
tbodyAttrs =
786-
options.customizations.tbodyAttrs
791+
options.customizations.tbodyAttrs |> List.map mapAttribute
787792

788793
tableContainerAttrs =
789-
options.customizations.tableContainerAttrs
794+
options.customizations.tableContainerAttrs |> List.map mapAttribute
790795

791796
tableView =
792-
table options.customizations.tableAttrs
797+
table (options.customizations.tableAttrs |> List.map mapAttribute)
793798
[ thead theadAttrs [ tableHeader columns model ]
794-
, tbody tbodyAttrs (tableBody columns data)
799+
, tbody tbodyAttrs (tableBody columns data options.customizations.rowAttrs)
795800
]
796801

797802
content =
@@ -800,7 +805,7 @@ view (Model ({ columns, data, options } as model)) =
800805
[ tableView ]
801806

802807
elems ->
803-
[ div options.customizations.optionsHeaderAttrs elems
808+
[ div (options.customizations.optionsHeaderAttrs |> List.map mapAttribute) elems
804809
, tableView
805810
]
806811
in
@@ -907,15 +912,17 @@ tableHeader columns sort =
907912
tr [ class "head" ]
908913
(columns
909914
|> NonEmptyList.toList
910-
|> List.map (\column -> ( column.name, thClass sort column.name ))
915+
|> List.map (\column -> ( column.name, thClass sort column.name, column.columnAttrs ))
911916
|> List.map
912-
(\( ColumnName name, thClassValue ) ->
917+
(\( ColumnName name, thClassValue, columnAttrs ) ->
913918
th
914-
[ class thClassValue
915-
, rowspan 1
916-
, colspan 1
917-
, onClick (SortColumn (ColumnName name))
918-
]
919+
([ class thClassValue
920+
, rowspan 1
921+
, colspan 1
922+
, onClick (SortColumn (ColumnName name))
923+
]
924+
++ List.map (Html.Attributes.map ParentMsg) columnAttrs
925+
)
919926
[ text name ]
920927
)
921928
)
@@ -935,15 +942,19 @@ thClass { sortBy, sortOrder } columnName =
935942
"sorting"
936943

937944

938-
tableBody : NonEmptyList.Nonempty (Column row msg) -> List row -> List (Html (Msg msg))
939-
tableBody columns data =
945+
tableBody : NonEmptyList.Nonempty (Column row msg) -> List row -> (row -> List (Attribute msg)) -> List (Html (Msg msg))
946+
tableBody columns data rowAttrs =
940947
let
941948
rowTable n =
942-
tr []
949+
tr (List.map (Html.Attributes.map ParentMsg) (rowAttrs n))
943950
(columns
944951
|> NonEmptyList.toList
945-
|> List.map (\{ renderHtml } -> Html.map ParentMsg (n |> renderHtml))
946-
|> List.map (\s -> td [] [ s ])
952+
|> List.map
953+
(\{ renderHtml, entryAttrs } ->
954+
td
955+
(List.map (Html.Attributes.map ParentMsg) entryAttrs)
956+
[ Html.map ParentMsg (n |> renderHtml) ]
957+
)
947958
)
948959
in
949960
if List.length data > 0 then

tests/ProgramTestTable.elm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ testConfig columnNames ordering renderHtml options =
7676
{ name = ColumnName columnName
7777
, renderHtml = renderHtml
7878
, ordering = ordering
79+
, entryAttrs = []
80+
, columnAttrs = []
7981
}
8082
in
8183
{ columns = columnNames |> NonEmpty.map toColumn
@@ -146,8 +148,8 @@ mockFilterConfigWithData =
146148
columns : NonEmpty.Nonempty (Column { a : String, b : Int } msg)
147149
columns =
148150
NonEmpty.Nonempty
149-
{ name = ColumnName "Name", renderHtml = .a >> Html.text, ordering = Ordering.byField .a }
150-
[ { name = ColumnName "Age", renderHtml = .b >> String.fromInt >> Html.text, ordering = Ordering.byField .b } ]
151+
{ name = ColumnName "Name", renderHtml = .a >> Html.text, ordering = Ordering.byField .a, entryAttrs = [], columnAttrs = [] }
152+
[ { name = ColumnName "Age", renderHtml = .b >> String.fromInt >> Html.text, ordering = Ordering.byField .b, entryAttrs = [], columnAttrs = [] } ]
151153

152154
options =
153155
buildOptions.newOptions

tests/TestTable.elm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ columnFuzz =
4141
|> andMap columnNameFuzz
4242
|> andMap (constant (\_ -> Html.text ""))
4343
|> andMap (constant Ordering.natural)
44+
|> andMap (constant [])
45+
|> andMap (constant [])
4446

4547

4648
nonEmptyListFuzzer : Fuzzer a -> Fuzzer (NonEmptyList.Nonempty a)
@@ -80,7 +82,7 @@ sortModelFuzz sortBy sortOrder =
8082
let
8183
config =
8284
constant Config
83-
|> andMap (constant (NonEmptyList.singleton { name = sortBy, renderHtml = \_ -> Html.text "", ordering = Ordering.natural }))
85+
|> andMap (constant (NonEmptyList.singleton { name = sortBy, renderHtml = \_ -> Html.text "", ordering = Ordering.natural, entryAttrs = [], columnAttrs = [] }))
8486
|> andMap (constant sortBy)
8587
|> andMap (constant sortOrder)
8688
|> andMap (optionsFuzz Filters.empty)
@@ -97,6 +99,8 @@ csvColumnFuzz (NonEmptyList.Nonempty head tail) =
9799
|> andMap (constant (ColumnName colName))
98100
|> andMap (constant (\_ -> Html.text ""))
99101
|> andMap (constant (\_ _ -> LT))
102+
|> andMap (constant [])
103+
|> andMap (constant [])
100104
in
101105
map2 NonEmptyList.Nonempty
102106
(head |> colNameToColumnFuzz)

0 commit comments

Comments
 (0)