Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
b642764a
Commit
b642764a
authored
Dec 19, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-warnings-cleanup' into dev-sigmajs-selector
parents
6db0c594
00bcbcee
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
68 deletions
+94
-68
SearchBar.purs
src/Gargantext/Components/Search/SearchBar.purs
+4
-35
SearchField.purs
src/Gargantext/Components/Search/SearchField.purs
+90
-33
No files found.
src/Gargantext/Components/Search/SearchBar.purs
View file @
b642764a
...
@@ -6,12 +6,13 @@ import Prelude (Unit, bind, discard, pure, ($))
...
@@ -6,12 +6,13 @@ import Prelude (Unit, bind, discard, pure, ($))
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (over)
import Data.Newtype (over)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff_)
import Effect (Effect)
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Reactix as R
import Reactix as R
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_)
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Gargantext.Components.Search.Types -- (Database, SearchQuery(..), defaultSearchQuery, performSearch, Lang(..))
import Gargantext.Components.Search.Types -- (Database, SearchQuery(..), defaultSearchQuery, performSearch, Lang(..))
import Gargantext.Components.Modals.Modal (modalShow)
import Gargantext.Components.Modals.Modal (modalShow)
import Gargantext.Components.Search.SearchField (Search, searchField)
import Gargantext.Components.Search.SearchField (Search, searchField)
...
@@ -29,38 +30,6 @@ searchBarCpt :: R.Component Props
...
@@ -29,38 +30,6 @@ 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, langs, search: search@(s /\ _)} _ = do
cpt {session, langs, search: search@(s /\ _)} _ = do
onSearchChange session s
--
onSearchChange session s
pure $ H.div {"style": {"margin" :"10px"}}
pure $ H.div {"style": {"margin" :"10px"}}
[ searchField {databases:allDatabases, langs, search}]
[ searchField {databases:allDatabases, langs, search, session}]
onSearchChange :: Session -> Search -> R.Hooks Unit
onSearchChange session s =
--R.useLayoutEffect1' search $ traverse_ triggerSearch search
--R.useEffect' $ traverse_ triggerSearch search
R.useEffectOnce' $ triggerSearch s
where
triggerSearch :: Search -> Effect Unit
triggerSearch q =
launchAff_ $ do
liftEffect $ do
-- log2 "Searching datafield: " $ show q.database
log2 "Searching term: " q.term
log2 "Searching lang: " q.lang
r <- (performSearch session $ searchQuery q) :: Aff Unit
liftEffect $ do
log2 "Return:" r
modalShow "addCorpus"
searchQuery :: Search -> SearchQuery
searchQuery {datafield: Nothing, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {datafield, lang, term, node_id} =
over SearchQuery (_ { datafield=datafield
, lang=lang
, query=term
, node_id=node_id
}) defaultSearchQuery
src/Gargantext/Components/Search/SearchField.purs
View file @
b642764a
module Gargantext.Components.Search.SearchField
module Gargantext.Components.Search.SearchField
( Search, Props, defaultSearch, searchField, searchFieldComponent, isIsTex) where
( Search, Props, defaultSearch, searchField, searchFieldComponent, isIsTex) where
import Prelude (const, map, pure, show, discard, ($), (&&), (<), (<$>), (<>), (==), (<<<))
import Prelude (const, map, pure, show, discard, ($), (&&), (<), (<$>), (<>), (==), (<<<)
, Unit, bind
)
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe(..), maybe)
import Data.Newtype (over)
import Data.String (length)
import Data.String (length)
import Data.Set as Set
import Data.Set as Set
import Data.Tuple (fst)
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Effect (Effect)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Gargantext.Components.Modals.Modal (modalShow)
import Gargantext.Components.Search.Types -- (Database(..), readDatabase, Lang(..), readLang, Org(..), readOrg, allOrgs, allIMTorgs, HAL_Filters(..), IMT_org(..))
import Gargantext.Components.Search.Types -- (Database(..), readDatabase, Lang(..), readLang, Org(..), readOrg, allOrgs, allIMTorgs, HAL_Filters(..), IMT_org(..))
import Gargantext.Sessions (Session)
select :: forall props.
select :: forall props.
R.IsComponent String props (Array R.Element)
R.IsComponent String props (Array R.Element)
...
@@ -45,13 +52,16 @@ type Props =
...
@@ -45,13 +52,16 @@ 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 Search
, search :: R.State Search
, session :: Session
)
)
searchField :: Record Props -> R.Element
searchField :: Record Props -> R.Element
searchField p = R.createElement searchFieldComponent p []
searchField p = R.createElement searchFieldComponent p []
searchFieldComponent :: R.Memo Props
--searchFieldComponent :: R.Memo Props
searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
--searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
searchFieldComponent :: R.Component Props
searchFieldComponent = R.hooksComponent "G.C.S.SearchField" cpt
where
where
cpt props@{search: search@(s /\ _)} _ = do
cpt props@{search: search@(s /\ _)} _ = do
pure $
pure $
...
@@ -60,7 +70,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
...
@@ -60,7 +70,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
H.div { className: "row" }
H.div { className: "row" }
[
[
H.div { className: "col-md-12" }
H.div { className: "col-md-12" }
[ searchInput
search
[ searchInput
{search}
, if length s.term < 3
, if length s.term < 3
then
then
H.div {}[]
H.div {}[]
...
@@ -87,11 +97,11 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
...
@@ -87,11 +97,11 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
, H.div { className : "panel-footer" }
, H.div { className : "panel-footer" }
[ if needsLang s.datafield then langNav search props.langs else H.div {} []
[ if needsLang s.datafield then langNav search props.langs else H.div {} []
, H.div {} []
, H.div {} []
, H.div {className: "flex-center"} [submitButton
search
]
, H.div {className: "flex-center"} [submitButton
{search, session: props.session}
]
]
]
]
]
eqProps
p p' = (fst p.search == fst p'.search)
eqProps
:: Record Props -> Record Props -> Boolean
&&
(p.databases == p'.databases )
eqProps p p' =
(p.databases == p'.databases )
&& (p.langs == p'.langs )
&& (p.langs == p'.langs )
&& (eqSearch (fst p.search) (fst p'.search))
&& (eqSearch (fst p.search) (fst p'.search))
-- && (fst p.filters == fst p'.filters )
-- && (fst p.filters == fst p'.filters )
...
@@ -293,31 +303,78 @@ filterInput (term /\ setTerm) =
...
@@ -293,31 +303,78 @@ filterInput (term /\ setTerm) =
]
]
searchInput :: R.State Search -> R.Element
type SearchInputProps =
searchInput ({term} /\ setSearch) =
(
search :: R.State Search
)
searchInput :: Record SearchInputProps -> R.Element
searchInput p = R.createElement searchInputComponent p []
searchInputComponent :: R.Component SearchInputProps
searchInputComponent = R.hooksComponent "G.C.S.SearchInput" cpt
where
cpt {search: (search /\ setSearch)} _ = do
pure $
H.div { className : "" }
H.div { className : "" }
[ H.input { defaultValue:
term
[ H.input { defaultValue: search.
term
, className: "form-control"
, className: "form-control"
, type: "text"
, type: "text"
, on: { change : onChange
}
, on: { change : onChange setSearch
}
, placeholder: "Your Query here" }
, placeholder: "Your Query here" }
]
]
where
onChange setSearch e = do
onChange e = do
let value = R2.unsafeEventValue e
setSearch $ _ { term = R2.unsafeEventValue e }
setSearch $ _ { term = value }
type SubmitButtonProps =
(
search :: R.State Search
, session :: Session
)
submitButton :: Record SubmitButtonProps -> R.Element
submitButton p = R.createElement submitButtonComponent p []
submitButton :: R.State Search
submitButtonComponent :: R.Component SubmitButtonProps
-> R.Element
submitButtonComponent = R.hooksComponent "G.C.S.SubmitButton" cpt
submitButton (search /\ setSearch) =
where
cpt {search: search /\ setSearch, session} _ =
pure $
H.button { className: "btn btn-primary"
H.button { className: "btn btn-primary"
, type: "button"
, type: "button"
, on: {click: doS
earch}
, on: {click: doSearch session s
earch}
, style: { width: "100%" }
, style: { width: "100%" }
} [ H.text "Launch Search" ]
} [ H.text "Launch Search" ]
where
doSearch = \_ -> do
doSearch s q = \_ -> do
log2 "[submitButton] searching" search
log2 "[submitButton] searching" q
case search.term of
triggerSearch s q
"" -> setSearch $ const defaultSearch
--case search.term of
_ -> setSearch $ const search
-- "" -> setSearch $ const defaultSearch
-- _ -> setSearch $ const q
triggerSearch :: Session -> Search -> Effect Unit
triggerSearch s q =
launchAff_ $ do
liftEffect $ do
-- log2 "Searching datafield: " $ show q.database
log2 "Searching term: " q.term
log2 "Searching lang: " q.lang
r <- (performSearch s $ searchQuery q) :: Aff Unit
liftEffect $ do
log2 "Return:" r
modalShow "addCorpus"
searchQuery :: Search -> SearchQuery
searchQuery {datafield: Nothing, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {datafield, lang, term, node_id} =
over SearchQuery (_ { datafield=datafield
, lang=lang
, query=term
, node_id=node_id
}) defaultSearchQuery
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment