Commit c57c60c8 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[list selection] some improvements to list selection

Also, implemented list selection on the Corpus/New screen.
parent 9ca6ad41
...@@ -14,6 +14,8 @@ import Gargantext.Components.Forest.Tree.Node.Action.Search.Frame (searchIframes ...@@ -14,6 +14,8 @@ 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(..), allIMTorgs, allOrgs, dataFields, defaultSearchQuery, doc, performSearch, datafield2database, Search) import Gargantext.Components.Forest.Tree.Node.Action.Search.Types (DataField(..), Database(..), IMT_org(..), Org(..), SearchQuery(..), allIMTorgs, allOrgs, dataFields, defaultSearchQuery, doc, performSearch, datafield2database, Search)
import Gargantext.Components.InputWithEnter (inputWithEnter) import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Lang (Lang) import Gargantext.Components.Lang (Lang)
import Gargantext.Components.ListSelection as ListSelection
import Gargantext.Components.ListSelection.Types as ListSelection
import Gargantext.Config.Utils (handleRESTError) import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (FrontendError) import Gargantext.Types (FrontendError)
...@@ -51,49 +53,19 @@ searchField = R.createElement searchFieldCpt ...@@ -51,49 +53,19 @@ searchField = R.createElement searchFieldCpt
searchFieldCpt :: R.Component Props searchFieldCpt :: R.Component Props
searchFieldCpt = here.component "searchField" cpt searchFieldCpt = here.component "searchField" cpt
where where
cpt props@{ errors, onSearch, search, session } _ = do cpt { databases, errors, langs, onSearch, search, session } _ = do
search' <- T.useLive T.unequal search selection <- T.useBox ListSelection.MyListsFirst
iframeRef <- R.useRef null
let params =
[ searchInput { search } []
-- , if length s.term < 3 -- search with love : <3
-- then
-- H.div {}[]
-- else
, H.div {}
[ dataFieldNav { datafields: dataFields, search } []
, if isExternal search'.datafield
then databaseInput { databases: props.databases, search } []
else H.div {} []
, if isHAL search'.datafield
then orgInput { orgs: allOrgs, search } []
else H.div {} []
, if isIMT search'.datafield
then componentIMT { search } []
else H.div {} []
, if isCNRS search'.datafield
then componentCNRS { search } []
else H.div {} []
, if needsLang search'.datafield
then langNav { langs: props.langs, search } []
else H.div {} []
, H.div {} [ searchIframes { iframeRef, search } [] ]
]
]
let button = submitButton { errors, onSearch, search, session } []
pure $ pure $
H.div { className: "search-field" } H.div { className: "search-field" }
[ [ searchInput { search } []
R.fragment params -- , if length s.term < 3 -- search with love : <3
, -- then
button -- H.div {}[]
-- else
, datafieldInput { databases, langs, search } []
, ListSelection.selection { selection, session } []
, submitButton { errors, onSearch, search, selection, session } []
] ]
--pure $ panel params button --pure $ panel params button
...@@ -381,6 +353,45 @@ filterInput (term /\ setTerm) = ...@@ -381,6 +353,45 @@ filterInput (term /\ setTerm) =
] ]
-} -}
type DatafieldInputProps =
( databases :: Array Database
, langs :: Array Lang
, search :: T.Box Search )
datafieldInput :: R2.Component DatafieldInputProps
datafieldInput = R.createElement datafieldInputCpt
datafieldInputCpt :: R.Component DatafieldInputProps
datafieldInputCpt = here.component "datafieldInput" cpt where
cpt { databases, langs, search } _ = do
search' <- T.useLive T.unequal search
iframeRef <- R.useRef null
pure $ H.div {}
[ dataFieldNav { datafields: dataFields, search } []
, if isExternal search'.datafield
then databaseInput { databases, search } []
else H.div {} []
, if isHAL search'.datafield
then orgInput { orgs: allOrgs, search } []
else H.div {} []
, if isIMT search'.datafield
then componentIMT { search } []
else H.div {} []
, if isCNRS search'.datafield
then componentCNRS { search } []
else H.div {} []
, if needsLang search'.datafield
then langNav { langs, search } []
else H.div {} []
, H.div {} [ searchIframes { iframeRef, search } [] ]
]
type SearchInputProps = type SearchInputProps =
( (
search :: T.Box Search search :: T.Box Search
...@@ -426,10 +437,11 @@ searchInputCpt = here.component "searchInput" cpt ...@@ -426,10 +437,11 @@ searchInputCpt = here.component "searchInput" cpt
-- setSearch $ _ { term = value } -- setSearch $ _ { term = value }
type SubmitButtonProps = type SubmitButtonProps =
( errors :: T.Box (Array FrontendError) ( errors :: T.Box (Array FrontendError)
, onSearch :: GT.AsyncTaskWithType -> Effect Unit , onSearch :: GT.AsyncTaskWithType -> Effect Unit
, search :: T.Box Search , search :: T.Box Search
, session :: Session , selection :: T.Box ListSelection.Selection
, session :: Session
) )
submitButton :: R2.Component SubmitButtonProps submitButton :: R2.Component SubmitButtonProps
...@@ -437,57 +449,70 @@ submitButton = R.createElement submitButtonComponent ...@@ -437,57 +449,70 @@ submitButton = R.createElement submitButtonComponent
submitButtonComponent :: R.Component SubmitButtonProps submitButtonComponent :: R.Component SubmitButtonProps
submitButtonComponent = here.component "submitButton" cpt submitButtonComponent = here.component "submitButton" cpt
where where
cpt { errors, onSearch, search, session } _ = do cpt { errors, onSearch, search, selection, session } _ = do
search' <- T.useLive T.unequal search search' <- T.useLive T.unequal search
selection' <- T.useLive T.unequal selection
pure $ pure $
H.button { className: "btn btn-primary" H.button { className: "btn btn-primary"
, "type" : "button" , "type" : "button"
, on : { click: doSearch onSearch errors session search' } , on : { click: doSearch onSearch errors session selection' search' }
, style : { width: "100%" } , style : { width: "100%" }
} }
[ H.text "Launch Search" ] [ H.text "Launch Search" ]
doSearch os errors s q = \_ -> do doSearch onSearch errors session selection search = \_ -> do
log2 "[submitButton] searching" q log2 "[submitButton] searching" search
triggerSearch os errors s q triggerSearch { onSearch, errors, session, selection, search }
--case search.term of --case search.term of
-- "" -> setSearch $ const defaultSearch -- "" -> setSearch $ const defaultSearch
-- _ -> setSearch $ const q -- _ -> setSearch $ const q
triggerSearch :: (GT.AsyncTaskWithType -> Effect Unit) type TriggerSearch =
-> T.Box (Array FrontendError) ( errors :: T.Box (Array FrontendError)
-> Session , onSearch :: GT.AsyncTaskWithType -> Effect Unit
-> Search , search :: T.Box Search
, selection :: T.Box ListSelection.Selection
, session :: Session
)
triggerSearch :: { onSearch :: (GT.AsyncTaskWithType -> Effect Unit)
, errors :: T.Box (Array FrontendError)
, session :: Session
, selection :: ListSelection.Selection
, search :: Search }
-> Effect Unit -> Effect Unit
triggerSearch os errors s q = triggerSearch { onSearch, errors, session, selection, search } =
launchAff_ $ do launchAff_ $ do
liftEffect $ do liftEffect $ do
let here' = "[triggerSearch] Searching " let here' = "[triggerSearch] Searching "
log2 (here' <> "databases: ") (show q.databases) log2 (here' <> "databases: ") (show search.databases)
log2 (here' <> "datafield: ") (show q.datafield) log2 (here' <> "datafield: ") (show search.datafield)
log2 (here' <> "term: ") q.term log2 (here' <> "term: ") search.term
log2 (here' <> "lang: ") (show q.lang) log2 (here' <> "lang: ") (show search.lang)
case q.node_id of case search.node_id of
Nothing -> liftEffect $ log "[triggerSearch] node_id is Nothing, don't know what to do" Nothing -> liftEffect $ log "[triggerSearch] node_id is Nothing, don't know what to do"
Just id -> do Just id -> do
eTask <- performSearch s id $ searchQuery q eTask <- performSearch session id $ searchQuery selection search
handleRESTError errors eTask $ \task -> liftEffect $ do handleRESTError errors eTask $ \task -> liftEffect $ do
log2 "[triggerSearch] task" task log2 "[triggerSearch] task" task
os task onSearch task
--liftEffect $ do --liftEffect $ do
-- log2 "Return:" r -- log2 "Return:" r
-- modalShow "addCorpus" -- modalShow "addCorpus"
searchQuery :: Search -> SearchQuery searchQuery :: ListSelection.Selection -> Search -> SearchQuery
searchQuery {datafield: Nothing, term} = searchQuery selection { datafield: Nothing, term } =
over SearchQuery (_ {query=term}) defaultSearchQuery over SearchQuery (_ { query = term
searchQuery {databases, datafield, lang, term, node_id} = , selection = selection }) defaultSearchQuery
over SearchQuery (_ { databases= databases searchQuery selection { databases, datafield, lang, term, node_id } =
, datafield= datafield over SearchQuery (_ { databases = databases
, lang = lang , datafield = datafield
, query = term , lang = lang
, node_id = node_id , node_id = node_id
, query = term
, selection = selection
}) defaultSearchQuery }) defaultSearchQuery
...@@ -19,6 +19,7 @@ import URI.Query as Q ...@@ -19,6 +19,7 @@ import URI.Query as Q
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.Lang (Lang) import Gargantext.Components.Lang (Lang)
import Gargantext.Components.ListSelection.Types as ListSelection
import Gargantext.Config.REST (RESTError) import Gargantext.Config.REST (RESTError)
import Gargantext.Ends (class ToUrl, backendUrl) import Gargantext.Ends (class ToUrl, backendUrl)
import Gargantext.Routes as GR import Gargantext.Routes as GR
...@@ -330,21 +331,23 @@ newtype SearchQuery = SearchQuery ...@@ -330,21 +331,23 @@ newtype SearchQuery = SearchQuery
, node_id :: Maybe Int , node_id :: Maybe Int
, offset :: Maybe Int , offset :: Maybe Int
, order :: Maybe SearchOrder , order :: Maybe SearchOrder
, selection :: ListSelection.Selection
} }
derive instance Generic SearchQuery _ derive instance Generic SearchQuery _
derive instance Newtype SearchQuery _ derive instance Newtype SearchQuery _
defaultSearchQuery :: SearchQuery defaultSearchQuery :: SearchQuery
defaultSearchQuery = SearchQuery defaultSearchQuery = SearchQuery
{ query: "" { query : ""
, databases: Empty , databases : Empty
, datafield: Nothing , datafield : Nothing
, files_id : [] , files_id : []
, lang : Nothing , lang : Nothing
, limit : Nothing , limit : Nothing
, node_id : Nothing , node_id : Nothing
, offset : Nothing , offset : Nothing
, order : Nothing , order : Nothing
, selection : ListSelection.MyListsFirst
} }
instance ToUrl Session SearchQuery where instance ToUrl Session SearchQuery where
......
...@@ -60,7 +60,7 @@ idsSelectorCpt :: R.Component IdsSelectorProps ...@@ -60,7 +60,7 @@ idsSelectorCpt :: R.Component IdsSelectorProps
idsSelectorCpt = here.component "idsSelector" cpt where idsSelectorCpt = here.component "idsSelector" cpt where
cpt { selection, session } _ = do cpt { selection, session } _ = do
pure $ H.div { className: "ids-selector" } pure $ H.div { className: "ids-selector" }
[ listTree { name: "", root, selection, session } ] -- $ map checkbox [1, 2, 3, 4] [ listTree { name: "", nodeType: NodeUser, root, selection, session } ] -- $ map checkbox [1, 2, 3, 4]
where where
Session { treeId: root } = session Session { treeId: root } = session
...@@ -77,6 +77,7 @@ loadTreeChildren { root, session } = do ...@@ -77,6 +77,7 @@ loadTreeChildren { root, session } = do
type ListTreeProps = type ListTreeProps =
( name :: String ( name :: String
, nodeType :: NodeType
, root :: ID , root :: ID
, selection :: T.Box Selection , selection :: T.Box Selection
, session :: Session ) , session :: Session )
...@@ -85,10 +86,10 @@ listTree :: R2.Leaf ListTreeProps ...@@ -85,10 +86,10 @@ listTree :: R2.Leaf ListTreeProps
listTree props = R.createElement listTreeCpt props [] listTree props = R.createElement listTreeCpt props []
listTreeCpt :: R.Component ListTreeProps listTreeCpt :: R.Component ListTreeProps
listTreeCpt = here.component "listTree" cpt where listTreeCpt = here.component "listTree" cpt where
cpt { name, root, selection, session } _ = do cpt { name, nodeType, root, selection, session } _ = do
pure $ H.div { className: "tree" } pure $ H.div { className: "tree" }
[ H.div { className: "root" } [ H.div { className: "root" }
[ H.i { className: fldr Corpus true } [] [ H.i { className: fldr nodeType true } []
, H.text $ "[" <> show root <> "] " <> name ] , H.text $ "[" <> show root <> "] " <> name ]
, listTreeChildren { render: listTree , listTreeChildren { render: listTree
, root , root
...@@ -136,8 +137,16 @@ listTreeChildrenLoadedCpt = here.component "listTreeChildrenLoaded" cpt where ...@@ -136,8 +137,16 @@ listTreeChildrenLoadedCpt = here.component "listTreeChildrenLoaded" cpt where
cpt { loaded, render, root, selection, session } _ = do cpt { loaded, render, root, selection, session } _ = do
pure $ H.div { className: "children" } (element <$> loaded) pure $ H.div { className: "children" } (element <$> loaded)
where where
element (NodeSimple { id, name, nodeType: Corpus }) = element (NodeSimple { id, name, nodeType: nodeType@Folder }) =
render { root: id, name, selection, session } render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@FolderPrivate }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@FolderPublic }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@FolderShared }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: nodeType@Corpus }) =
render { root: id, name, nodeType, selection, session }
element (NodeSimple { id, name, nodeType: NodeList}) = element (NodeSimple { id, name, nodeType: NodeList}) =
renderListElement { id, name, selection } renderListElement { id, name, selection }
element _ = H.div {} [] element _ = H.div {} []
...@@ -156,12 +165,8 @@ renderListElementCpt = here.component "renderListElement" cpt where ...@@ -156,12 +165,8 @@ renderListElementCpt = here.component "renderListElement" cpt where
let ids = selectedListIds selection' let ids = selectedListIds selection'
R.useEffect' $ do
here.log2 "[renderListElement] ids" ids
here.log2 "[renderListElement] value" $ A.elem id ids
pure $ H.div { className: "leaf" } pure $ H.div { className: "leaf" }
[ H.input { checked: A.elem id ids [ H.input { defaultChecked: A.elem id ids
, on: { click: click ids } , on: { click: click ids }
, type: "checkbox" } , type: "checkbox" }
, H.i { className: fldr NodeList true } [] , H.i { className: fldr NodeList true } []
......
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