Commit 8602174e authored by Alexandre Delanoë's avatar Alexandre Delanoë

[SEARCH FORM] adding node_id.

parent 8c5aa0b4
......@@ -317,7 +317,7 @@ panelAction d {id,name,nodeType,action, session} p = case action of
(Just Download) -> R.fragment [ H.p {} [H.text $ "Soon, you will be able to dowload your file here"]]
(Just SearchBox) -> R.fragment [ H.p {} [ H.text $ "Search and create a private corpus with the search query as corpus name." ]
, searchBar {session, databases:allDatabases, langs:allLangs}
, searchBar {session, databases:allDatabases, langs:allLangs, node_id: (Just id)}
]
(Just Delete) -> case nodeType of
NodeUser -> R.fragment [ H.div {} [H.text "Yes, we are RGPD compliant! But you can not delete User Node yet (we are still on development). Thanks for your comprehensin."]]
......
......@@ -23,6 +23,7 @@ import Gargantext.Sessions (Session)
type Props = ( session :: Session
, databases :: Array Database
, langs :: Array Lang
, node_id :: Maybe Int
)
searchBar :: Record Props -> R.Element
......@@ -31,10 +32,10 @@ searchBar props = R.createElement searchBarCpt props []
searchBarCpt :: R.Component Props
searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt
where
cpt {session, databases, langs} _ = do
cpt {session, databases, langs, node_id} _ = do
search <- R.useState' Nothing
onSearchChange session search
pure $ H.div { className: "" } [ searchField {databases, langs, search}]
pure $ H.div { className: "" } [ searchField {databases, langs, search, node_id}]
onSearchChange :: Session -> R.State (Maybe Search) -> R.Hooks Unit
......@@ -58,8 +59,8 @@ onSearchChange session (search /\ setSearch) =
searchQuery {database: Nothing, lang, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {database: Just db, lang, term, filters} =
over SearchQuery (_ {databases=[db], lang=lang, query=term, filters=filters'}) defaultSearchQuery
searchQuery {database: Just db, lang, term, filters, node_id} =
over SearchQuery (_ {databases=[db], lang=lang, query=term, filters=filters', node_id=node_id}) defaultSearchQuery
where
filters' = toInt filters
toInt (Just (HAL_StructId {structIds})) = Set.toUnfoldable structIds
......
......@@ -24,6 +24,7 @@ type Search = { database :: Maybe Database
, lang :: Maybe Lang
, org :: Maybe Org
, filters :: Maybe HAL_Filters
, node_id :: Maybe Int
}
defaultSearch :: Search
......@@ -32,6 +33,7 @@ defaultSearch = { database: Nothing
, lang: Nothing
, org : Nothing
, filters: Nothing
, node_id: Nothing
}
type Props =
......@@ -40,6 +42,7 @@ type Props =
, langs :: Array Lang
-- State hook for a search, how we get data in and out
, search :: R.State (Maybe Search)
, node_id :: Maybe Int
)
searchField :: Record Props -> R.Element
......@@ -48,7 +51,7 @@ searchField p = R.createElement searchFieldComponent p []
searchFieldComponent :: R.Memo Props
searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
where
cpt props _ = do
cpt props@{node_id} _ = do
let search = maybe defaultSearch identity (fst props.search)
term <- R.useState' search.term
db@(curDb /\ setDb) <- R.useState' (Nothing :: Maybe Database)
......@@ -99,7 +102,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
else
div {} []
, div { className: "" }
[ submitButton db term lang org filters props.search ]
[ submitButton node_id db term lang org filters props.search ]
]
hasChanged p p' = (fst p.search /= fst p'.search)
|| (p.databases /= p'.databases )
......@@ -220,14 +223,15 @@ searchInput (term /\ setTerm) =
]
submitButton :: R.State (Maybe Database)
submitButton :: Maybe Int
-> R.State (Maybe Database)
-> R.State String
-> R.State (Maybe Lang)
-> R.State (Maybe Org)
-> R.State (Maybe HAL_Filters)
-> R.State (Maybe Search)
-> R.Element
submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) =
submitButton node_id (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) =
R.fragment [ div { className : "" } []
, button { className: "btn btn-primary"
, type: "button"
......@@ -238,4 +242,4 @@ submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_
doSearch = \_ -> do
case term of
"" -> setSearch $ const Nothing
_ -> setSearch $ const $ Just { database, lang, filters, term, org}
_ -> setSearch $ const $ Just { database, lang, filters, term, org, node_id}
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