Commit ed3127bc authored by Nicolas Pouillard's avatar Nicolas Pouillard

Table: minor refactoring

parent 7e558a0b
...@@ -130,20 +130,12 @@ tableCpt = R.hooksComponent "G.C.Table.table" cpt ...@@ -130,20 +130,12 @@ tableCpt = R.hooksComponent "G.C.Table.table" cpt
pageSize@(pageSize' /\ setPageSize) <- R.useState' PS10 pageSize@(pageSize' /\ setPageSize) <- R.useState' PS10
(page /\ setPage) <- R.useState' 1 (page /\ setPage) <- R.useState' 1
(orderBy /\ setOrderBy) <- R.useState' Nothing (orderBy /\ setOrderBy) <- R.useState' Nothing
let state = {pageSize: pageSize', orderBy, page} let
let ps = pageSizes2Int pageSize' state = {pageSize: pageSize', orderBy, page}
let totalPages = (totalRecords / ps) + min 1 (totalRecords `mod` ps) ps = pageSizes2Int pageSize'
R.useEffect1' state $ when (fst params /= stateParams state) $ (snd params) (const $ stateParams state) totalPages = (totalRecords / ps) + min 1 (totalRecords `mod` ps)
pure $ container colHeader :: ColumnName -> R.Element
{ pageSizeControl: sizeDD pageSize colHeader c = H.th {scope: "col"} [ H.b {} cs ]
, pageSizeDescription: textDescription page pageSize' totalRecords
, paginationLinks: pagination setPage totalPages page
, tableHead: H.tr {} (colHeader setOrderBy orderBy <$> colNames)
, tableBody: map (H.tr {} <<< map (\c -> H.td {} [c]) <<< _.row) rows
}
where
colHeader :: (R2.Setter OrderBy) -> OrderBy -> ColumnName -> R.Element
colHeader setOrderBy orderBy c = H.th {scope: "col"} [ H.b {} cs ]
where where
lnk mc = effectLink (setOrderBy (const mc)) lnk mc = effectLink (setOrderBy (const mc))
cs :: Array R.Element cs :: Array R.Element
...@@ -152,6 +144,14 @@ tableCpt = R.hooksComponent "G.C.Table.table" cpt ...@@ -152,6 +144,14 @@ tableCpt = R.hooksComponent "G.C.Table.table" cpt
Just (ASC d) | c == d -> [lnk (Just (DESC c)) "DESC ", lnk Nothing (columnName c)] Just (ASC d) | c == d -> [lnk (Just (DESC c)) "DESC ", lnk Nothing (columnName c)]
Just (DESC d) | c == d -> [lnk (Just (ASC c)) "ASC ", lnk Nothing (columnName c)] Just (DESC d) | c == d -> [lnk (Just (ASC c)) "ASC ", lnk Nothing (columnName c)]
_ -> [lnk (Just (ASC c)) (columnName c)] _ -> [lnk (Just (ASC c)) (columnName c)]
R.useEffect1' state $ when (fst params /= stateParams state) $ (snd params) (const $ stateParams state)
pure $ container
{ pageSizeControl: sizeDD pageSize
, pageSizeDescription: textDescription page pageSize' totalRecords
, paginationLinks: pagination setPage totalPages page
, tableHead: H.tr {} (colHeader <$> colNames)
, tableBody: map (H.tr {} <<< map (\c -> H.td {} [c]) <<< _.row) rows
}
defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element
defaultContainer {title} props = R.fragment defaultContainer {title} props = R.fragment
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment