Commit 8f1f26d4 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski Committed by Alexandre Delanoë

[ngrams] some refactorings to search

Trying to make input work.
parent 6629d18e
...@@ -22,6 +22,7 @@ import Data.Set as Set ...@@ -22,6 +22,7 @@ import Data.Set as Set
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), fst, snd) import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
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.DOM (a, span, text) import React.DOM (a, span, text)
...@@ -151,6 +152,7 @@ type TableContainerProps = ...@@ -151,6 +152,7 @@ type TableContainerProps =
, ngramsSelection :: Set NgramsTerm , ngramsSelection :: Set NgramsTerm
, ngramsTable :: NgramsTable , ngramsTable :: NgramsTable
, path :: R.State PageParams , path :: R.State PageParams
, search :: R.Element
, tabNgramType :: CTabNgramType , tabNgramType :: CTabNgramType
) )
...@@ -165,10 +167,14 @@ tableContainerCpt { dispatch ...@@ -165,10 +167,14 @@ tableContainerCpt { dispatch
, ngramsSelection , ngramsSelection
, ngramsTable: ngramsTableCache , ngramsTable: ngramsTableCache
, path: {searchQuery, termListFilter, termSizeFilter} /\ setPath , path: {searchQuery, termListFilter, termSizeFilter} /\ setPath
, search
, tabNgramType , tabNgramType
} = R.hooksComponent "G.C.NT.tableContainer" cpt } = R.hooksComponent "G.C.NT.tableContainer" cpt
where where
cpt props _ = do cpt props _ = do
R.useEffect' $ do
log2 "[tableContainer] searchQuery" searchQuery
pure $ H.div {className: "container-fluid"} [ pure $ H.div {className: "container-fluid"} [
H.div {className: "jumbotron1"} H.div {className: "jumbotron1"}
[ R2.row [ R2.row
...@@ -180,12 +186,7 @@ tableContainerCpt { dispatch ...@@ -180,12 +186,7 @@ tableContainerCpt { dispatch
] ]
, R2.row , R2.row
[ H.div {className: "col-md-3", style: {marginTop: "6px"}} [ H.div {className: "col-md-3", style: {marginTop: "6px"}}
[ H.input { className: "form-control" [ search
, defaultValue: searchQuery
, name: "search"
, on: { input: setSearchQuery <<< R2.unsafeEventValue }
, placeholder: "Search"
, type: "value" }
, H.div {} ( , H.div {} (
if A.null props.tableBody && searchQuery /= "" then [ if A.null props.tableBody && searchQuery /= "" then [
H.button { className: "btn btn-primary" H.button { className: "btn btn-primary"
...@@ -251,7 +252,6 @@ tableContainerCpt { dispatch ...@@ -251,7 +252,6 @@ tableContainerCpt { dispatch
] ]
] ]
-- WHY setPath f = origSetPageParams (const $ f path) -- WHY setPath f = origSetPageParams (const $ f path)
setSearchQuery x = setPath $ _ { searchQuery = x }
setTermListFilter x = setPath $ _ { termListFilter = x } setTermListFilter x = setPath $ _ { termListFilter = x }
setTermSizeFilter x = setPath $ _ { termSizeFilter = x } setTermSizeFilter x = setPath $ _ { termSizeFilter = x }
setSelection = dispatch <<< setTermListSetA ngramsTableCache ngramsSelection setSelection = dispatch <<< setTermListSetA ngramsTableCache ngramsSelection
...@@ -270,6 +270,27 @@ tableContainerCpt { dispatch ...@@ -270,6 +270,27 @@ tableContainerCpt { dispatch
} [ H.text "Candidate" ] } [ H.text "Candidate" ]
] ]
type SearchInputProps =
(
key :: String -- to prevent refreshing & losing input
, onSearch :: String -> Effect Unit
, searchQuery :: String
)
searchInput :: Record SearchInputProps -> R.Element
searchInput props = R.createElement searchInputCpt props []
searchInputCpt :: R.Component SearchInputProps
searchInputCpt = R.hooksComponent "G.C.NT.searchInput" cpt
where
cpt { onSearch, searchQuery } _ = do
pure $ H.input { className: "form-control"
, defaultValue: searchQuery
, name: "search"
, on: { input: onSearch <<< R2.unsafeEventValue }
, placeholder: "Search"
, type: "value" }
toggleMaybe :: forall a. a -> Maybe a -> Maybe a toggleMaybe :: forall a. a -> Maybe a -> Maybe a
toggleMaybe _ (Just _) = Nothing toggleMaybe _ (Just _) = Nothing
toggleMaybe b Nothing = Just b toggleMaybe b Nothing = Just b
...@@ -340,6 +361,7 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -340,6 +361,7 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
, ngramsSelection , ngramsSelection
, ngramsTable , ngramsTable
, path , path
, search
, tabNgramType , tabNgramType
} }
, params: params /\ setParams -- TODO-LENS , params: params /\ setParams -- TODO-LENS
...@@ -371,10 +393,8 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -371,10 +393,8 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
setState $ \s@{ ngramsChildren: nc } -> s { ngramsChildren = newNC nc } setState $ \s@{ ngramsChildren: nc } -> s { ngramsChildren = newNC nc }
where where
newNC nc = Map.alter (maybe Nothing $ const (Just b)) c nc newNC nc = Map.alter (maybe Nothing $ const (Just b)) c nc
-- modifyState_ $ _ngramsChildren <<< at c %~ toggleMaybe b
performAction (ToggleSelect c) = performAction (ToggleSelect c) =
setState $ \s@{ ngramsSelection: ns } -> s { ngramsSelection = toggleSet c ns } setState $ \s@{ ngramsSelection: ns } -> s { ngramsSelection = toggleSet c ns }
-- modifyState_ $ _ngramsSelection <<< at c %~ toggleMaybe unit
performAction ToggleSelectAll = performAction ToggleSelectAll =
setState toggler setState toggler
where where
...@@ -390,7 +410,6 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -390,7 +410,6 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
commitPatchR (Versioned {version: ngramsVersion, data: pt}) (state /\ setState) commitPatchR (Versioned {version: ngramsVersion, data: pt}) (state /\ setState)
performAction ResetPatches = performAction ResetPatches =
setState $ \s -> s { ngramsLocalPatch = { ngramsNewElems: mempty, ngramsPatches: mempty } } setState $ \s -> s { ngramsLocalPatch = { ngramsNewElems: mempty, ngramsPatches: mempty } }
-- modifyState_ $ \s -> s { ngramsLocalPatch = { ngramsNewElems: mempty, ngramsPatches: mempty } }
performAction AddTermChildren = performAction AddTermChildren =
case ngramsParent of case ngramsParent of
Nothing -> Nothing ->
...@@ -411,6 +430,7 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -411,6 +430,7 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
addOcc addOcc
<$> Map.toUnfoldable (Map.filter rowsFilter (ngramsTable ^. _NgramsTable)) <$> Map.toUnfoldable (Map.filter rowsFilter (ngramsTable ^. _NgramsTable))
) )
rowsFilter :: NgramsElement -> Boolean
rowsFilter = displayRow state searchQuery versioned termListFilter rowsFilter = displayRow state searchQuery versioned termListFilter
addOcc (Tuple ne ngramsElement) = addOcc (Tuple ne ngramsElement) =
let Additive occurrences = sumOccurrences ngramsTable ngramsElement in let Additive occurrences = sumOccurrences ngramsTable ngramsElement in
...@@ -448,6 +468,13 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -448,6 +468,13 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
wrapColElts _ = identity wrapColElts _ = identity
setParams f = setPath $ \p@{params: ps} -> p {params = f ps} setParams f = setPath $ \p@{params: ps} -> p {params = f ps}
search :: R.Element
search = searchInput { key: "search-input"
, onSearch: setSearchQuery
, searchQuery: searchQuery }
setSearchQuery :: String -> Effect Unit
setSearchQuery x = setPath $ _ { searchQuery = x }
displayRow :: State -> SearchQuery -> VersionedNgramsTable -> Maybe TermList -> NgramsElement -> Boolean displayRow :: State -> SearchQuery -> VersionedNgramsTable -> Maybe TermList -> NgramsElement -> Boolean
displayRow state@{ ngramsChildren displayRow state@{ ngramsChildren
......
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