Commit 91224ece authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski Committed by Alexandre Delanoë

[ngrams] some more refactoring

parent 8d2095b3
...@@ -34,8 +34,8 @@ import Gargantext.Utils (queryMatchesLabel) ...@@ -34,8 +34,8 @@ import Gargantext.Utils (queryMatchesLabel)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, otherwise, pure, show, unit, (#), ($), (&&), (+), (/=), (<$>), (<<<), (<>), (=<<), (==), (||)) import Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, otherwise, pure, show, unit, (#), ($), (&&), (+), (/=), (<$>), (<<<), (<>), (=<<), (==), (||))
import React (ReactClass, Children) import React (ReactClass, Children)
import React.DOM (a, input, span, text) import React.DOM (a, span, text)
import React.DOM.Props (_type, checked, className, onChange, onClick, style) import React.DOM.Props (onClick, style)
import React.DOM.Props as DOM import React.DOM.Props as DOM
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -170,7 +170,9 @@ tableContainerCpt { dispatch ...@@ -170,7 +170,9 @@ tableContainerCpt { dispatch
} }
} }
[ H.text ("Add " <> searchQuery) ] [ H.text ("Add " <> searchQuery) ]
] else [])] ] else []
)
]
, H.div {className: "col-md-2", style: {marginTop : "6px"}} , H.div {className: "col-md-2", style: {marginTop : "6px"}}
[ H.li {className: " list-group-item"} [ H.li {className: " list-group-item"}
[ R2.select { id: "picklistmenu" [ R2.select { id: "picklistmenu"
...@@ -191,7 +193,8 @@ tableContainerCpt { dispatch ...@@ -191,7 +193,8 @@ tableContainerCpt { dispatch
, props.pageSizeControl , props.pageSizeControl
, H.text " items / " , H.text " items / "
, props.paginationLinks]] , props.paginationLinks]]
]] ]
]
, H.div {} , H.div {}
(maybe [] (\ngrams -> (maybe [] (\ngrams ->
let let
...@@ -337,35 +340,40 @@ loadedNgramsTableSpec = Thermite.simpleSpec performAction render ...@@ -337,35 +340,40 @@ loadedNgramsTableSpec = Thermite.simpleSpec performAction render
state@{ ngramsParent, ngramsChildren, ngramsLocalPatch state@{ ngramsParent, ngramsChildren, ngramsLocalPatch
, ngramsSelection, ngramsSelectAll } , ngramsSelection, ngramsSelectAll }
_reactChildren = _reactChildren =
(autoUpdate <> resetSaveButtons <> [ R2.scuff <$> (
R2.scuff $ T.table { colNames autoUpdate <> resetSaveButtons <> [
T.table { colNames
, container , container
, params: params /\ setParams -- TODO-LENS , params: params /\ setParams -- TODO-LENS
, rows: filteredRows , rows: filteredRows
, totalRecords , totalRecords
, wrapColElts , wrapColElts
} }
]) ]
)
where where
autoUpdate = if withAutoUpdate then [ autoUpdateElt { duration: 5000, effect: dispatch Synchronize } ] else [] autoUpdate :: Array R.Element
autoUpdate = if withAutoUpdate then [ R2.buff $ autoUpdateElt { duration: 5000, effect: dispatch Synchronize } ] else []
resetButton :: R.Element
resetButton = H.button { className: "btn btn-primary" resetButton = H.button { className: "btn btn-primary"
, on: { click: \_ -> dispatch ResetPatches } } [ H.text "Reset" ] , on: { click: \_ -> dispatch ResetPatches } } [ H.text "Reset" ]
saveButton :: R.Element
saveButton = H.button { className: "btn btn-primary" saveButton = H.button { className: "btn btn-primary"
, on: { click: \_ -> dispatch Synchronize }} [ H.text "Save" ] , on: { click: \_ -> dispatch Synchronize }} [ H.text "Save" ]
resetSaveButtons :: Array R.Element
resetSaveButtons = if ngramsLocalPatch == mempty then [] else resetSaveButtons = if ngramsLocalPatch == mempty then [] else
[ R2.scuff $ H.div {} [ resetButton, saveButton ] ] [ H.div {} [ resetButton, saveButton ] ]
totalRecords = A.length rows totalRecords = A.length rows
filteredRows = T.filterRows { params } rows filteredRows = T.filterRows { params } rows
colNames = T.ColumnName <$> ["Select", "Map", "Stop", "Terms", "Score"] -- see convOrderBy colNames = T.ColumnName <$> ["Select", "Map", "Stop", "Terms", "Score"] -- see convOrderBy
selected = selected =
input H.input { checked: ngramsSelectAll
[ _type "checkbox" , className: "checkbox"
, className "checkbox" , on: { change: const $ dispatch $ ToggleSelectAll }
, checked ngramsSelectAll , type: "checkbox" }
, onChange $ const $ dispatch $ ToggleSelectAll
]
-- This is used to *decorate* the Select header with the checkbox. -- This is used to *decorate* the Select header with the checkbox.
wrapColElts (T.ColumnName "Select") = const [R2.buff selected] wrapColElts (T.ColumnName "Select") = const [selected]
wrapColElts (T.ColumnName "Score") = (_ <> [H.text ("(" <> show scoreType <> ")")]) wrapColElts (T.ColumnName "Score") = (_ <> [H.text ("(" <> show scoreType <> ")")])
wrapColElts _ = identity wrapColElts _ = identity
container = tableContainer { dispatch container = tableContainer { dispatch
...@@ -454,8 +462,8 @@ mainNgramsTableCpt = R.hooksComponent "MainNgramsTable" cpt ...@@ -454,8 +462,8 @@ mainNgramsTableCpt = R.hooksComponent "MainNgramsTable" cpt
cpt {nodeId, defaultListId, tabType, session, tabNgramType, withAutoUpdate} _ = do cpt {nodeId, defaultListId, tabType, session, tabNgramType, withAutoUpdate} _ = do
path /\ setPath <- R.useState' $ initialPageParams session nodeId [defaultListId] tabType path /\ setPath <- R.useState' $ initialPageParams session nodeId [defaultListId] tabType
let paint versioned = loadedNgramsTable' { let paint versioned = loadedNgramsTable' {
tabNgramType path: path /\ setPath
, path: path /\ setPath , tabNgramType
, versioned , versioned
, withAutoUpdate , withAutoUpdate
} }
......
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