Commit 796e8e18 authored by Karen Konou's avatar Karen Konou

[Ngrams table] reset to first page when searching

parent 4eb82bba
Pipeline #3217 failed with stage
in 0 seconds
......@@ -43,6 +43,7 @@ import Gargantext.Components.NgramsTable.Tree (renderNgramsItem, renderNgramsTre
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table (changePage)
import Gargantext.Components.Table as TT
import Gargantext.Components.Table.Types (Params)
import Gargantext.Components.Table.Types as TT
import Gargantext.Config.REST (AffRESTError, RESTError, logRESTError)
import Gargantext.Core.NgramsTable.Functions (addNewNgramA, applyNgramsPatches, chartsAfterSync, commitPatch, convOrderBy, coreDispatch, filterTermSize, ngramsRepoElementToNgramsElement, normNgram, patchSetFromMap, singletonNgramsTablePatch, tablePatchHasNgrams, toVersioned)
......@@ -406,13 +407,13 @@ type Props =
| PropsNoReload )
type LoadedNgramsTableHeaderProps =
( searchQuery :: T.Box SearchQuery )
( searchQuery :: T.Box SearchQuery, params :: T.Box Params )
loadedNgramsTableHeader :: R2.Leaf LoadedNgramsTableHeaderProps
loadedNgramsTableHeader = R2.leaf loadedNgramsTableHeaderCpt
loadedNgramsTableHeaderCpt :: R.Component LoadedNgramsTableHeaderProps
loadedNgramsTableHeaderCpt = here.component "loadedNgramsTableHeader" cpt where
cpt { searchQuery } _ = pure $
cpt { searchQuery, params } _ = pure $
R.fragment
[
......@@ -434,6 +435,7 @@ loadedNgramsTableHeaderCpt = here.component "loadedNgramsTableHeader" cpt where
NTS.searchInput
{ key: "search-input"
, searchQuery
, params
}
]
......@@ -540,6 +542,7 @@ loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
performAction
$ CoreAction
$ Synchronize { afterSync: afterSync' }
changePage 1 params
-- autoUpdate :: Array R.Element
......@@ -752,6 +755,7 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
where
cpt props@{ cacheState, path, treeEdit } _ = do
searchQuery <- T.useFocused (_.searchQuery) (\a b -> b { searchQuery = a }) path
params <- T.useFocused (_.params) (\a b -> b { params = a }) path
cacheState' <- T.useLive T.unequal cacheState
-- onCancelRef <- R.useRef Nothing
-- onNgramsClickRef <- R.useRef Nothing
......@@ -773,12 +777,12 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
case cacheState' of
NT.CacheOn -> pure $ R.fragment
[ loadedNgramsTableHeader { searchQuery }
[ loadedNgramsTableHeader { searchQuery, params }
, ngramsTreeEdit (treeEdit)
, mainNgramsTableCacheOn (Record.merge props { state })
]
NT.CacheOff -> pure $ R.fragment
[loadedNgramsTableHeader { searchQuery }
[loadedNgramsTableHeader { searchQuery, params}
, ngramsTreeEdit (treeEdit)
, mainNgramsTableCacheOff (Record.merge props { state })
]
......
......@@ -7,6 +7,8 @@ import Data.Foldable (intercalate)
import Data.Nullable (Nullable, null)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), Variant(..))
import Gargantext.Components.Table (changePage)
import Gargantext.Components.Table.Types (Params)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
......@@ -18,6 +20,7 @@ here = R2.here "Gargantext.Components.NgramsTable.Search"
type SearchInputProps =
( searchQuery :: T.Box String
, params :: T.Box Params
)
-- "key": to prevent refreshing & losing input
......@@ -26,14 +29,14 @@ searchInput = R2.leafComponent searchInputCpt
searchInputCpt :: R.Component ( key :: String | SearchInputProps )
searchInputCpt = here.component "searchInput" cpt
where
cpt { searchQuery } _ = do
cpt { searchQuery, params } _ = do
inputRef <- R.useRef null
pure $ R2.row
[ H.div { className: "col-12" }
[ H.div { className: "input-group" }
[ searchFieldInput { inputRef, searchQuery } []
, searchButton { inputRef, searchQuery } []
, searchButton { inputRef, searchQuery, params } []
]
]
]
......@@ -41,6 +44,7 @@ searchInputCpt = here.component "searchInput" cpt
type SearchButtonProps =
( inputRef :: R.Ref (Nullable DOM.Element)
, searchQuery :: T.Box String
, params :: T.Box Params
)
searchButton :: R2.Component SearchButtonProps
......@@ -48,7 +52,7 @@ searchButton = R.createElement searchButtonCpt
searchButtonCpt :: R.Component SearchButtonProps
searchButtonCpt = here.component "searchButton" cpt where
cpt { inputRef, searchQuery } _ = do
cpt { inputRef, searchQuery, params } _ = do
-- | States
-- |
searchQuery' <- T.useLive T.unequal searchQuery
......@@ -59,9 +63,11 @@ searchButtonCpt = here.component "searchButton" cpt where
onReset _ = do
R2.setInputValue inputRef ""
T.write_ "" searchQuery
changePage 1 params
onSubmit _ = do
T.write_ (R2.getInputValue inputRef) searchQuery
changePage 1 params
-- | Render
-- |
......
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