Commit a2747b50 authored by Yoelis Acourt's avatar Yoelis Acourt

chore: refactor search form for legibility

parent 4868dbf0
...@@ -5,8 +5,8 @@ import Effect (Effect) ...@@ -5,8 +5,8 @@ import Effect (Effect)
import Effect.Aff (Aff, launchAff) import Effect.Aff (Aff, launchAff)
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
import Gargantext.Components.App.Store as Store import Gargantext.Components.App.Store as Store
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchBar (searchBar) import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchForm (defaultSearch, searchFormContent)
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField (defaultSearch) import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (allDatabases)
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..)) import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Utils (loadLanguages) import Gargantext.Components.Forest.Tree.Node.Action.Utils (loadLanguages)
import Gargantext.Components.Lang (Lang) import Gargantext.Components.Lang (Lang)
...@@ -67,19 +67,22 @@ actionSearchWithLangsCpt = here.component "actionSearchWithLangs" cpt ...@@ -67,19 +67,22 @@ actionSearchWithLangsCpt = here.component "actionSearchWithLangs" cpt
[ H.text $ "Search and create a private " [ H.text $ "Search and create a private "
<> "corpus with the search query as corpus name." <> "corpus with the search query as corpus name."
] ]
, searchBar , H.form { className: "search-bar m-2" }
{ errors [ searchFormContent
, langs { databases: allDatabases
, onSearch: searchOn dispatch , errors
, search , langs
, session , onSearch: searchOn dispatch
} , search
[] , session
}
[]
]
] ]
where where
searchOn searchOn
:: (Action -> Aff Unit) :: (Action -> Aff Unit)
-> GAT.Task -> GT.AsyncTaskWithType
-> Effect Unit -> Effect Unit
searchOn dispatch' task = do searchOn dispatch' task = do
_ <- launchAff $ dispatch' (DoSearch task) _ <- launchAff $ dispatch' (DoSearch task)
......
module Gargantext.Components.Forest.Tree.Node.Action.Search.SearchBar
( Props
, searchBar
) where
import Effect (Effect)
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField (searchField)
import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (Search, allDatabases)
import Gargantext.Components.Lang (Lang)
import Gargantext.Prelude (Unit, pure, ($))
import Gargantext.Sessions (Session)
import Gargantext.Types (FrontendError)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Search.SearchBar"
type Props =
( errors :: T.Box (Array FrontendError)
, langs :: Array Lang
, onSearch :: GAT.Task -> Effect Unit
, search :: T.Box Search
, session :: Session
)
searchBar :: R2.Component Props
searchBar = R.createElement searchBarCpt
searchBarCpt :: R.Component Props
searchBarCpt = here.component "searchBar" cpt
where
cpt { errors, langs, onSearch, search, session } _ = do
--onSearchChange session s
pure $ H.form { className: "search-bar m-2" }
[ searchField
{ databases: allDatabases
, errors
, langs
, onSearch
, search
, session
}
[]
]
module Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField where module Gargantext.Components.Forest.Tree.Node.Action.Search.SearchForm where
import Gargantext.Prelude import Gargantext.Prelude
...@@ -12,7 +12,6 @@ import Data.Tuple (Tuple(..)) ...@@ -12,7 +12,6 @@ import Data.Tuple (Tuple(..))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.AsyncTasks as GAT
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, getUser) import Gargantext.Components.GraphQL.Endpoints (getIMTSchools, getUser)
...@@ -54,16 +53,16 @@ type Props = ...@@ -54,16 +53,16 @@ type Props =
, errors :: T.Box (Array FrontendError) , errors :: T.Box (Array FrontendError)
, 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
, onSearch :: GAT.Task -> Effect Unit , onSearch :: GT.AsyncTaskWithType -> Effect Unit
, search :: T.Box Search , search :: T.Box Search
, session :: Session , session :: Session
) )
searchField :: R2.Component Props searchFormContent :: R2.Component Props
searchField = R.createElement searchFieldCpt searchFormContent = R.createElement searchFormContentCpt
searchFieldCpt :: R.Component Props searchFormContentCpt :: R.Component Props
searchFieldCpt = here.component "searchField" cpt searchFormContentCpt = here.component "searchFormContent" cpt
where where
cpt { databases, errors, langs, onSearch, search, session } _ = do cpt { databases, errors, langs, onSearch, search, session } _ = do
selection <- T.useBox ListSelection.MyListsFirst selection <- T.useBox ListSelection.MyListsFirst
...@@ -71,10 +70,6 @@ searchFieldCpt = here.component "searchField" cpt ...@@ -71,10 +70,6 @@ searchFieldCpt = here.component "searchField" cpt
pure $ pure $
H.div { className: "search-field" } H.div { className: "search-field" }
[ searchInput { search } [] [ searchInput { search } []
-- , if length s.term < 3 -- search with love : <3
-- then
-- H.div {}[]
-- else
, datafieldInput { databases, langs, search, session } [] , datafieldInput { databases, langs, search, session } []
, ListSelection.selection { selection, session } [] , ListSelection.selection { selection, session } []
, submitButton { errors, onSearch, search, selection, session } [] , submitButton { errors, onSearch, search, selection, session } []
...@@ -202,76 +197,6 @@ componentCNRSCpt = here.component "componentCNRS" cpt ...@@ -202,76 +197,6 @@ componentCNRSCpt = here.component "componentCNRS" cpt
--, filterInput fi --, filterInput fi
] ]
isExternal :: Maybe DataField -> Boolean
isExternal (Just (External _)) = true
isExternal _ = false
isArxiv :: Maybe DataField -> Boolean
isArxiv
( Just
(External Arxiv)
) = true
isArxiv _ = false
isHAL :: Maybe DataField -> Boolean
isHAL
( Just
(External (HAL _))
) = true
isHAL _ = false
isIsTex :: Maybe DataField -> Boolean
isIsTex
( Just
(External (IsTex))
) = true
isIsTex _ = false
isIMT :: Maybe DataField -> Boolean
isIMT
( Just
( External
( HAL
(Just (IMT _))
)
)
) = true
isIMT _ = false
isCNRS :: Maybe DataField -> Boolean
isCNRS
( Just
( External
( HAL
(Just (CNRS _))
)
)
) = true
isCNRS _ = false
isPubmed :: Maybe DataField -> Boolean
isPubmed
( Just
(External PubMed)
) = true
isPubmed _ = false
isEPO :: Maybe DataField -> Boolean
isEPO
( Just
(External EPO)
) = true
isEPO _ = false
needsLang :: Maybe DataField -> Boolean
needsLang (Just Gargantext) = true
needsLang (Just Web) = true
needsLang
( Just
(External (HAL _))
) = true
needsLang _ = false
isIn :: IMT_org -> Maybe DataField -> Boolean isIn :: IMT_org -> Maybe DataField -> Boolean
isIn isIn
org org
...@@ -386,11 +311,11 @@ type DatabaseInputProps = ...@@ -386,11 +311,11 @@ type DatabaseInputProps =
, search :: T.Box Search , search :: T.Box Search
) )
databaseInput :: R2.Component DatabaseInputProps dataSourceSelection :: R2.Component DatabaseInputProps
databaseInput = R.createElement databaseInputCpt dataSourceSelection = R.createElement dataSourceSelectionCpt
databaseInputCpt :: R.Component DatabaseInputProps dataSourceSelectionCpt :: R.Component DatabaseInputProps
databaseInputCpt = here.component "databaseInput" cpt dataSourceSelectionCpt = here.component "dataSourceSelection" cpt
where where
cpt cpt
{ databases { databases
...@@ -649,6 +574,9 @@ type DatafieldInputProps = ...@@ -649,6 +574,9 @@ type DatafieldInputProps =
, session :: Session , session :: Session
) )
empty :: R.Element
empty = H.div {} [ H.text "" ]
datafieldInput :: R2.Component DatafieldInputProps datafieldInput :: R2.Component DatafieldInputProps
datafieldInput = R.createElement datafieldInputCpt datafieldInput = R.createElement datafieldInputCpt
...@@ -659,39 +587,21 @@ datafieldInputCpt = here.component "datafieldInput" cpt ...@@ -659,39 +587,21 @@ datafieldInputCpt = here.component "datafieldInput" cpt
search' <- T.useLive T.unequal search search' <- T.useLive T.unequal search
iframeRef <- R.useRef null iframeRef <- R.useRef null
let
optionalFields = case search'.datafield of
Just (External PubMed) -> pubmedInput { search, session } []
Just (External EPO) -> epoInput { search, session } []
Just (External (HAL (Just (IMT _)))) -> componentIMT { search, session } [ langNav { langs, search } [] ]
Just (External (HAL (Just (CNRS _)))) -> componentCNRS { search } [ langNav { langs, search } [] ]
Just (External (HAL _)) -> orgInput { orgs: allOrgs, search } [ langNav { langs, search } [] ]
Just (External OpenAlex) -> H.div {} [ H.text "Optional filters" ]
Just Web -> langNav { langs, search } []
_ -> empty -- Default for unsupported or missing fields
pure $ H.div {} pure $ H.div {}
[ dataFieldNav { search } [] [ dataFieldNav { search } []
, dataSourceSelection { databases, search } []
, if isExternal search'.datafield then databaseInput { databases, search } [] , optionalFields
else H.div {} []
, if isPubmed search'.datafield then pubmedInput { search, session } []
else H.div {} []
, if isEPO search'.datafield then epoInput { search, session } []
else H.div {} []
, if isHAL search'.datafield then orgInput { orgs: allOrgs, search } []
else H.div {} []
, if isIMT search'.datafield then componentIMT { search, session } []
else H.div {} []
-- , if isHAL search'.datafield
-- then componentYears { search } []
-- else H.div {} []
, if isCNRS search'.datafield then componentCNRS { search } []
else H.div {} []
, if needsLang search'.datafield then
if search'.datafield == Just Web then
langNav { langs: A.filter (\lang -> lang == FR) langs, search } []
else
langNav { langs, search } []
else
H.div {} []
, H.div {} [ searchIframes { iframeRef, search } [] ] , H.div {} [ searchIframes { iframeRef, search } [] ]
] ]
...@@ -745,7 +655,7 @@ searchInputCpt = here.component "searchInput" cpt ...@@ -745,7 +655,7 @@ searchInputCpt = here.component "searchInput" cpt
type SubmitButtonProps = type SubmitButtonProps =
( errors :: T.Box (Array FrontendError) ( errors :: T.Box (Array FrontendError)
, onSearch :: GAT.Task -> Effect Unit , onSearch :: GT.AsyncTaskWithType -> Effect Unit
, search :: T.Box Search , search :: T.Box Search
, selection :: T.Box ListSelection.Selection , selection :: T.Box ListSelection.Selection
, session :: Session , session :: Session
...@@ -780,14 +690,14 @@ submitButtonComponent = here.component "submitButton" cpt ...@@ -780,14 +690,14 @@ submitButtonComponent = here.component "submitButton" cpt
type TriggerSearch = type TriggerSearch =
( errors :: T.Box (Array FrontendError) ( errors :: T.Box (Array FrontendError)
, onSearch :: GAT.Task -> Effect Unit , onSearch :: GT.AsyncTaskWithType -> Effect Unit
, search :: T.Box Search , search :: T.Box Search
, selection :: T.Box ListSelection.Selection , selection :: T.Box ListSelection.Selection
, session :: Session , session :: Session
) )
triggerSearch triggerSearch
:: { onSearch :: (GAT.Task -> Effect Unit) :: { onSearch :: (GT.AsyncTaskWithType -> Effect Unit)
, errors :: T.Box (Array FrontendError) , errors :: T.Box (Array FrontendError)
, session :: Session , session :: Session
, selection :: ListSelection.Selection , selection :: ListSelection.Selection
......
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