[search] implement custom pubmed api key

parent d180ce86
...@@ -18,7 +18,7 @@ import Effect.Aff (launchAff_) ...@@ -18,7 +18,7 @@ import Effect.Aff (launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.Forest.Tree.Node.Action.Search.Frame (searchIframes) import Gargantext.Components.Forest.Tree.Node.Action.Search.Frame (searchIframes)
import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (DataField(..), Database(..), IMT_org(..), Org(..), SearchQuery(..), allOrgs, dataFields, defaultSearchQuery, doc, performSearch, datafield2database, Search, dbFromInputValue, dbToInputValue) import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (DataField(..), Database(..), IMT_org(..), Org(..), SearchQuery(..), allOrgs, dataFields, defaultSearchQuery, doc, performSearch, datafield2database, Search, dbFromInputValue, dbToInputValue)
import Gargantext.Components.GraphQL.Endpoints (getIMTSchools) import Gargantext.Components.GraphQL.Endpoints (getIMTSchools, getUser)
import Gargantext.Components.GraphQL.IMT as GQLIMT import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.InputWithEnter (inputWithEnter) import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Lang (Lang(..)) import Gargantext.Components.Lang (Lang(..))
...@@ -27,7 +27,7 @@ import Gargantext.Components.ListSelection.Types as ListSelection ...@@ -27,7 +27,7 @@ import Gargantext.Components.ListSelection.Types as ListSelection
import Gargantext.Config.REST (logRESTError) import Gargantext.Config.REST (logRESTError)
import Gargantext.Config.Utils (handleRESTError) import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session(..))
import Gargantext.Types (FrontendError) import Gargantext.Types (FrontendError)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -42,6 +42,7 @@ defaultSearch :: Search ...@@ -42,6 +42,7 @@ defaultSearch :: Search
defaultSearch = { databases : Empty defaultSearch = { databases : Empty
, datafield : Just (External Empty) , datafield : Just (External Empty)
, node_id : Nothing , node_id : Nothing
, pubmedApiKey : Nothing
, lang : Nothing , lang : Nothing
, term : "" , term : ""
, url : "" , url : ""
...@@ -377,38 +378,57 @@ databaseInputCpt = here.component "databaseInput" cpt ...@@ -377,38 +378,57 @@ databaseInputCpt = here.component "databaseInput" cpt
] ]
-- type PubmedInputProps = ( type PubmedInputProps = (
-- search :: T.Box Search search :: T.Box Search
-- , session :: Session , session :: Session
-- ) )
-- pubmedInput :: R2.Component PubmedInputProps pubmedInput :: R2.Component PubmedInputProps
-- pubmedInput = R.createElement pubmedInputCpt pubmedInput = R.createElement pubmedInputCpt
-- pubmedInputCpt :: R.Component PubmedInputProps pubmedInputCpt :: R.Component PubmedInputProps
-- pubmedInputCpt = here.component "pubmedInput" cpt where pubmedInputCpt = here.component "pubmedInput" cpt where
-- cpt { search, session } _ = do cpt { search, session: session@(Session { treeId }) } _ = do
-- search' <- T.useLive T.unequal search useLoader { errorHandler
, loader: \_ -> getUser session treeId
-- case search'.datafield of , path: unit
-- Just (External (PubMed p@{ api_key })) -> , render: \user -> pubmedInputLoaded { pubmedAPIKey: user.u_hyperdata.pubmed_api_key
-- -- TODO Fetch current API key , search } [] }
-- pure $ where
-- H.div { className: "form-group p-1 m-0" } errorHandler = logRESTError here "[componentIMT]"
-- [ H.div { className: "text-primary center" } [ H.text "Pubmed API key" ]
-- , H.input { className: "form-control"
-- , defaultValue: fromMaybe "" api_key type PubmedInputLoadedProps = (
-- , on: { blur: modifyPubmedAPIKey search p pubmedAPIKey :: Maybe String
-- , change: modifyPubmedAPIKey search p , search :: T.Box Search
-- , input: modifyPubmedAPIKey search p } } ] )
-- _ -> pure $ H.div {} []
-- where pubmedInputLoaded :: R2.Component PubmedInputLoadedProps
-- modifyPubmedAPIKey search p e = do pubmedInputLoaded = R.createElement pubmedInputLoadedCpt
-- let val = R.unsafeEventValue e pubmedInputLoadedCpt :: R.Component PubmedInputLoadedProps
-- let mVal = case val of pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt where
-- "" -> Nothing cpt { pubmedAPIKey, search } _ = do
-- s -> Just s search' <- T.useLive T.unequal search
-- T.modify_ (\s ->
-- s { datafield = Just (External (PubMed p { api_key = mVal })) }) search R.useEffectOnce' $ do
when (search'.pubmedApiKey /= pubmedAPIKey) $ do
T.write_ (search' { pubmedApiKey = pubmedAPIKey }) search
pure $
H.div { className: "form-group p-1 m-0" }
[ H.div { className: "text-primary center" } [ H.text "Pubmed API key" ]
, H.input { className: "form-control"
, defaultValue: fromMaybe "" search'.pubmedApiKey
, on: { blur: modifyPubmedAPIKey search
, change: modifyPubmedAPIKey search
, input: modifyPubmedAPIKey search } } ]
where
modifyPubmedAPIKey search e = do
let val = R.unsafeEventValue e
let mVal = case val of
"" -> Nothing
s -> Just s
T.modify_ (\s ->
s { pubmedApiKey = mVal }) search
type OrgInputProps = type OrgInputProps =
...@@ -475,9 +495,9 @@ datafieldInputCpt = here.component "datafieldInput" cpt where ...@@ -475,9 +495,9 @@ datafieldInputCpt = here.component "datafieldInput" cpt where
then databaseInput { databases, search, session } [] then databaseInput { databases, search, session } []
else H.div {} [] else H.div {} []
-- , if isPubmed search'.datafield , if isPubmed search'.datafield
-- then pubmedInput { search, session } [] then pubmedInput { search, session } []
-- else H.div {} [] else H.div {} []
, if isHAL search'.datafield , if isHAL search'.datafield
then orgInput { orgs: allOrgs, search } [] then orgInput { orgs: allOrgs, search } []
...@@ -629,8 +649,8 @@ searchQuery selection { datafield: Nothing, term } = ...@@ -629,8 +649,8 @@ searchQuery selection { datafield: Nothing, term } =
searchQuery selection { databases searchQuery selection { databases
, datafield: datafield@(Just (External (HAL Nothing))) , datafield: datafield@(Just (External (HAL Nothing)))
, lang , lang
, term
, node_id , node_id
, term
, years } = , years } =
over SearchQuery (_ { databases = databases over SearchQuery (_ { databases = databases
, datafield = datafield , datafield = datafield
...@@ -643,8 +663,8 @@ searchQuery selection { databases ...@@ -643,8 +663,8 @@ searchQuery selection { databases
searchQuery selection { databases searchQuery selection { databases
, datafield: datafield@(Just (External (HAL (Just (IMT imtOrgs))))) , datafield: datafield@(Just (External (HAL (Just (IMT imtOrgs)))))
, lang , lang
, term
, node_id , node_id
, term
, years } = , years } =
over SearchQuery (_ { databases = databases over SearchQuery (_ { databases = databases
, datafield = datafield , datafield = datafield
...@@ -653,7 +673,21 @@ searchQuery selection { databases ...@@ -653,7 +673,21 @@ searchQuery selection { databases
, query = queryHAL term (Just imtOrgs) lang years , query = queryHAL term (Just imtOrgs) lang years
, selection = selection , selection = selection
}) defaultSearchQuery }) defaultSearchQuery
searchQuery selection { databases
, datafield: datafield@(Just (External PubMed))
, lang
, pubmedApiKey
, node_id
, term
, years } =
over SearchQuery (_ { databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, pubmedAPIKey = pubmedApiKey
, query = term
, selection = selection
}) defaultSearchQuery
searchQuery selection { databases, datafield, lang, term, node_id } = searchQuery selection { databases, datafield, lang, term, node_id } =
over SearchQuery (_ { databases = databases over SearchQuery (_ { databases = databases
, datafield = datafield , datafield = datafield
......
...@@ -29,6 +29,7 @@ type Search = { databases :: Database ...@@ -29,6 +29,7 @@ type Search = { databases :: Database
, url :: String , url :: String
, lang :: Maybe Lang , lang :: Maybe Lang
, node_id :: Maybe Int , node_id :: Maybe Int
, pubmedApiKey :: Maybe String
, term :: String , term :: String
, years :: Array String , years :: Array String
} }
......
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