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 ...@@ -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 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." ] (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 (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."]] 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) ...@@ -23,6 +23,7 @@ import Gargantext.Sessions (Session)
type Props = ( session :: Session type Props = ( session :: Session
, databases :: Array Database , databases :: Array Database
, langs :: Array Lang , langs :: Array Lang
, node_id :: Maybe Int
) )
searchBar :: Record Props -> R.Element searchBar :: Record Props -> R.Element
...@@ -31,10 +32,10 @@ searchBar props = R.createElement searchBarCpt props [] ...@@ -31,10 +32,10 @@ searchBar props = R.createElement searchBarCpt props []
searchBarCpt :: R.Component Props searchBarCpt :: R.Component Props
searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt
where where
cpt {session, databases, langs} _ = do cpt {session, databases, langs, node_id} _ = do
search <- R.useState' Nothing search <- R.useState' Nothing
onSearchChange session search 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 onSearchChange :: Session -> R.State (Maybe Search) -> R.Hooks Unit
...@@ -58,8 +59,8 @@ onSearchChange session (search /\ setSearch) = ...@@ -58,8 +59,8 @@ onSearchChange session (search /\ setSearch) =
searchQuery {database: Nothing, lang, term} = searchQuery {database: Nothing, lang, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {database: Just db, lang, term, filters} = searchQuery {database: Just db, lang, term, filters, node_id} =
over SearchQuery (_ {databases=[db], lang=lang, query=term, filters=filters'}) defaultSearchQuery over SearchQuery (_ {databases=[db], lang=lang, query=term, filters=filters', node_id=node_id}) defaultSearchQuery
where where
filters' = toInt filters filters' = toInt filters
toInt (Just (HAL_StructId {structIds})) = Set.toUnfoldable structIds toInt (Just (HAL_StructId {structIds})) = Set.toUnfoldable structIds
......
...@@ -24,6 +24,7 @@ type Search = { database :: Maybe Database ...@@ -24,6 +24,7 @@ type Search = { database :: Maybe Database
, lang :: Maybe Lang , lang :: Maybe Lang
, org :: Maybe Org , org :: Maybe Org
, filters :: Maybe HAL_Filters , filters :: Maybe HAL_Filters
, node_id :: Maybe Int
} }
defaultSearch :: Search defaultSearch :: Search
...@@ -32,6 +33,7 @@ defaultSearch = { database: Nothing ...@@ -32,6 +33,7 @@ defaultSearch = { database: Nothing
, lang: Nothing , lang: Nothing
, org : Nothing , org : Nothing
, filters: Nothing , filters: Nothing
, node_id: Nothing
} }
type Props = type Props =
...@@ -40,6 +42,7 @@ type Props = ...@@ -40,6 +42,7 @@ type Props =
, langs :: Array Lang , langs :: Array Lang
-- State hook for a search, how we get data in and out -- State hook for a search, how we get data in and out
, search :: R.State (Maybe Search) , search :: R.State (Maybe Search)
, node_id :: Maybe Int
) )
searchField :: Record Props -> R.Element searchField :: Record Props -> R.Element
...@@ -48,7 +51,7 @@ searchField p = R.createElement searchFieldComponent p [] ...@@ -48,7 +51,7 @@ searchField p = R.createElement searchFieldComponent p []
searchFieldComponent :: R.Memo Props searchFieldComponent :: R.Memo Props
searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
where where
cpt props _ = do cpt props@{node_id} _ = do
let search = maybe defaultSearch identity (fst props.search) let search = maybe defaultSearch identity (fst props.search)
term <- R.useState' search.term term <- R.useState' search.term
db@(curDb /\ setDb) <- R.useState' (Nothing :: Maybe Database) db@(curDb /\ setDb) <- R.useState' (Nothing :: Maybe Database)
...@@ -99,7 +102,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -99,7 +102,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
else else
div {} [] div {} []
, div { className: "" } , 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) hasChanged p p' = (fst p.search /= fst p'.search)
|| (p.databases /= p'.databases ) || (p.databases /= p'.databases )
...@@ -220,14 +223,15 @@ searchInput (term /\ setTerm) = ...@@ -220,14 +223,15 @@ searchInput (term /\ setTerm) =
] ]
submitButton :: R.State (Maybe Database) submitButton :: Maybe Int
-> R.State (Maybe Database)
-> R.State String -> R.State String
-> R.State (Maybe Lang) -> R.State (Maybe Lang)
-> R.State (Maybe Org) -> R.State (Maybe Org)
-> R.State (Maybe HAL_Filters) -> R.State (Maybe HAL_Filters)
-> R.State (Maybe Search) -> R.State (Maybe Search)
-> R.Element -> R.Element
submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) = submitButton node_id (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ /\ setSearch) =
R.fragment [ div { className : "" } [] R.fragment [ div { className : "" } []
, button { className: "btn btn-primary" , button { className: "btn btn-primary"
, type: "button" , type: "button"
...@@ -238,4 +242,4 @@ submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ ...@@ -238,4 +242,4 @@ submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_
doSearch = \_ -> do doSearch = \_ -> do
case term of case term of
"" -> setSearch $ const Nothing "" -> 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