Commit 8191570e authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] merge

parents be54a2e0 2f5f9891
...@@ -4,16 +4,14 @@ import Gargantext.Prelude ...@@ -4,16 +4,14 @@ import Gargantext.Prelude
import Data.Array as A import Data.Array as A
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Set (Set)
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 Gargantext.Components.Forest.Tree (treeView) import Gargantext.Components.Forest.Tree (treeView)
import Gargantext.Components.Forest.Tree.Node.Action (Reload) import Gargantext.Components.Forest.Tree.Node.Action (Reload)
import Gargantext.Components.Login.Types (TreeId)
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Routes (AppRoute) import Gargantext.Routes (AppRoute)
import Gargantext.Sessions (Session(..), Sessions, unSessions) import Gargantext.Sessions (Session(..), Sessions, OpenNodes, unSessions)
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
...@@ -33,7 +31,7 @@ forestCpt = R.hooksComponent "G.C.Forest.forest" cpt where ...@@ -33,7 +31,7 @@ forestCpt = R.hooksComponent "G.C.Forest.forest" cpt where
cpt {frontends, route, sessions, showLogin } _ = do cpt {frontends, route, sessions, showLogin } _ = do
-- NOTE: this is a hack to reload the tree view on demand -- NOTE: this is a hack to reload the tree view on demand
reload <- R.useState' (0 :: Reload) reload <- R.useState' (0 :: Reload)
openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: Set TreeId) openNodes <- R2.useLocalStorageState R2.openNodesKey (Set.empty :: OpenNodes)
R2.useCache R2.useCache
(frontends /\ route /\ sessions /\ fst openNodes /\ fst reload) (frontends /\ route /\ sessions /\ fst openNodes /\ fst reload)
(cpt' openNodes reload showLogin) (cpt' openNodes reload showLogin)
......
module Gargantext.Components.Forest.Tree where module Gargantext.Components.Forest.Tree where
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), CreateValue(..), FTree, ID, LNode(..), NTree(..), Reload, RenameValue(..), Tree, createNode, deleteNode, loadNode, renameNode)
import Gargantext.Prelude (Unit, bind, const, discard, map, pure, void, ($), (+), (/=), (<>))
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Data.Array as A import Data.Array as A
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Tuple (Tuple(..), fst, snd) import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Reactix as R import Gargantext.Components.Forest.Tree.Node.Action (Action(..), CreateValue(..), FTree, ID, LNode(..), NTree(..), Reload, RenameValue(..), Tree, createNode, deleteNode, loadNode, renameNode)
import Reactix.DOM.HTML as H
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile) import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile)
import Gargantext.Components.Forest.Tree.Node.Box (nodeMainSpan) import Gargantext.Components.Forest.Tree.Node.Box (nodeMainSpan)
import Gargantext.Components.Loader (loader) import Gargantext.Components.Loader (loader)
import Gargantext.Components.Login.Types (TreeId)
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Prelude (Unit, bind, const, discard, map, pure, void, ($), (+), (/=), (<>))
import Gargantext.Routes (AppRoute) import Gargantext.Routes (AppRoute)
import Gargantext.Sessions (Session) import Gargantext.Sessions (OpenNodes, Session, mkNodeId)
import Gargantext.Types as GT import Gargantext.Types as GT
import Reactix as R
import Reactix.DOM.HTML as H
------------------------------------------------------------------------ ------------------------------------------------------------------------
type Props = ( root :: ID type Props = ( root :: ID
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
, session :: Session , session :: Session
, frontends :: Frontends , frontends :: Frontends
, openNodes :: R.State (Set TreeId) , openNodes :: R.State OpenNodes
, reload :: R.State Reload , reload :: R.State Reload
) )
...@@ -47,7 +43,7 @@ type Props' = ( root :: ID ...@@ -47,7 +43,7 @@ type Props' = ( root :: ID
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
, session :: Session , session :: Session
, frontends :: Frontends , frontends :: Frontends
, openNodes :: R.State (Set TreeId) , openNodes :: R.State OpenNodes
, reload :: R.State Reload , reload :: R.State Reload
) )
...@@ -65,7 +61,7 @@ type TreeViewProps = ( tree :: FTree ...@@ -65,7 +61,7 @@ type TreeViewProps = ( tree :: FTree
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
, frontends :: Frontends , frontends :: Frontends
, session :: Session , session :: Session
, openNodes :: R.State (Set TreeId) , openNodes :: R.State OpenNodes
, reload :: R.State Reload , reload :: R.State Reload
) )
...@@ -88,7 +84,7 @@ toHtml :: R.State Reload ...@@ -88,7 +84,7 @@ toHtml :: R.State Reload
-> Session -> Session
-> Frontends -> Frontends
-> Maybe AppRoute -> Maybe AppRoute
-> R.State (Set TreeId) -> R.State OpenNodes
-> R.Element -> R.Element
toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asyncTasks} /\ setTreeState) session frontends mCurrentRoute openNodes = R.createElement el {} [] toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asyncTasks} /\ setTreeState) session frontends mCurrentRoute openNodes = R.createElement el {} []
where where
...@@ -96,10 +92,11 @@ toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asy ...@@ -96,10 +92,11 @@ toHtml reload treeState@(ts@{tree: (NTree (LNode {id, name, nodeType}) ary), asy
pAction = performAction session reload openNodes treeState pAction = performAction session reload openNodes treeState
cpt props _ = do cpt props _ = do
let folderIsOpen = Set.member id (fst openNodes) let nodeId = mkNodeId session id
let setFn = if folderIsOpen then Set.delete else Set.insert let folderIsOpen = Set.member nodeId (fst openNodes)
let toggleFolderIsOpen _ = (snd openNodes) (setFn id) let setFn = if folderIsOpen then Set.delete else Set.insert
let folderOpen = Tuple folderIsOpen toggleFolderIsOpen let toggleFolderIsOpen _ = (snd openNodes) (setFn nodeId)
let folderOpen = Tuple folderIsOpen toggleFolderIsOpen
let withId (NTree (LNode {id: id'}) _) = id' let withId (NTree (LNode {id: id'}) _) = id'
...@@ -126,7 +123,7 @@ childNodes :: Session ...@@ -126,7 +123,7 @@ childNodes :: Session
-> R.State Reload -> R.State Reload
-> R.State Boolean -> R.State Boolean
-> Maybe AppRoute -> Maybe AppRoute
-> R.State (Set TreeId) -> R.State OpenNodes
-> Array FTree -> Array FTree
-> Array R.Element -> Array R.Element
childNodes _ _ _ _ _ _ [] = [] childNodes _ _ _ _ _ _ [] = []
...@@ -145,14 +142,14 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary = ...@@ -145,14 +142,14 @@ childNodes session frontends reload (true /\ _) mCurrentRoute openNodes ary =
performAction :: Session performAction :: Session
-> R.State Int -> R.State Int
-> R.State (Set TreeId) -> R.State OpenNodes
-> R.State Tree -> R.State Tree
-> Action -> Action
-> Aff Unit -> Aff Unit
performAction session (_ /\ setReload) (_ /\ setOpenNodes) (s@{tree: NTree (LNode {id}) _} /\ setTree) DeleteNode = do performAction session (_ /\ setReload) (_ /\ setOpenNodes) (s@{tree: NTree (LNode {id}) _} /\ setTree) DeleteNode = do
void $ deleteNode session id void $ deleteNode session id
liftEffect do liftEffect do
setOpenNodes (Set.delete id) setOpenNodes (Set.delete (mkNodeId session id))
setReload (_ + 1) setReload (_ + 1)
performAction session (_ /\ setReload) _ ({tree: NTree (LNode {id}) _} /\ setTree) (SearchQuery task) = do performAction session (_ /\ setReload) _ ({tree: NTree (LNode {id}) _} /\ setTree) (SearchQuery task) = do
...@@ -167,7 +164,7 @@ performAction session _ _ ({tree: NTree (LNode {id}) _} /\ setTree) (Submit name ...@@ -167,7 +164,7 @@ performAction session _ _ ({tree: NTree (LNode {id}) _} /\ setTree) (Submit name
performAction session (_ /\ setReload) (_ /\ setOpenNodes) (s@{tree: NTree (LNode {id}) _} /\ setTree) (CreateSubmit name nodeType) = do performAction session (_ /\ setReload) (_ /\ setOpenNodes) (s@{tree: NTree (LNode {id}) _} /\ setTree) (CreateSubmit name nodeType) = do
void $ createNode session id $ CreateValue {name, nodeType} void $ createNode session id $ CreateValue {name, nodeType}
liftEffect do liftEffect do
setOpenNodes (Set.insert id) setOpenNodes (Set.insert (mkNodeId session id))
setReload (_ + 1) setReload (_ + 1)
performAction session _ _ ({tree: NTree (LNode {id}) _} /\ setTree) (UploadFile fileType contents) = do performAction session _ _ ({tree: NTree (LNode {id}) _} /\ setTree) (UploadFile fileType contents) = do
......
module Gargantext.Components.Login.Types where module Gargantext.Components.Login.Types where
import Prelude import Prelude
import Data.Argonaut ( class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject
, (.:), (.:!), (:=), (~>) import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (.:!), (:=), (~>))
)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq) import Data.Generic.Rep.Eq (genericEq)
import Data.Lens (Iso', iso) import Data.Lens (Iso', iso)
......
...@@ -12,12 +12,13 @@ import Data.Generic.Rep.Eq (genericEq) ...@@ -12,12 +12,13 @@ import Data.Generic.Rep.Eq (genericEq)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Sequence (Seq) import Data.Sequence (Seq)
import Data.Sequence as Seq import Data.Sequence as Seq
import Data.Set (Set)
import Data.Traversable (traverse) import Data.Traversable (traverse)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Components.Login.Types (AuthRequest(..), AuthResponse(..), AuthInvalid(..), AuthData(..)) import Gargantext.Components.Login.Types (AuthData(..), AuthInvalid(..), AuthRequest(..), AuthResponse(..), TreeId)
import Gargantext.Config.REST as REST import Gargantext.Config.REST as REST
import Gargantext.Ends (class ToUrl, Backend, backendUrl, toUrl, sessionPath) import Gargantext.Ends (class ToUrl, Backend(..), backendUrl, sessionPath, toUrl)
import Gargantext.Routes (SessionRoute) import Gargantext.Routes (SessionRoute)
import Gargantext.Types (NodePath, SessionId(..), nodePath) import Gargantext.Types (NodePath, SessionId(..), nodePath)
import Gargantext.Utils.Reactix (getls) import Gargantext.Utils.Reactix (getls)
...@@ -33,7 +34,8 @@ newtype Session = Session ...@@ -33,7 +34,8 @@ newtype Session = Session
{ backend :: Backend { backend :: Backend
, username :: String , username :: String
, token :: String , token :: String
, treeId :: Int } , treeId :: TreeId
}
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Main instances -- | Main instances
...@@ -58,9 +60,6 @@ sessionUrl (Session {backend}) = backendUrl backend ...@@ -58,9 +60,6 @@ sessionUrl (Session {backend}) = backendUrl backend
sessionId :: Session -> SessionId sessionId :: Session -> SessionId
sessionId = SessionId <<< show sessionId = SessionId <<< show
instance toUrlSessionString :: ToUrl Session String where
toUrl = sessionUrl
-------------------- --------------------
-- | JSON instances -- | JSON instances
instance encodeJsonSession :: EncodeJson Session where instance encodeJsonSession :: EncodeJson Session where
...@@ -140,6 +139,20 @@ tryRemove sid old@(Sessions ss) = ret where ...@@ -140,6 +139,20 @@ tryRemove sid old@(Sessions ss) = ret where
| new == old = Left unit | new == old = Left unit
| otherwise = Right new | otherwise = Right new
-- open tree nodes data
type OpenNodes = Set NodeId
type NodeId =
{ treeId :: TreeId -- Id of the node
, baseUrl :: String -- the baseUrl of the backend
}
mkNodeId :: Session -> TreeId -> NodeId
mkNodeId (Session {backend: Backend {baseUrl}}) treeId = { treeId, baseUrl }
instance toUrlSessionString :: ToUrl Session String where
toUrl = sessionUrl
data Action data Action
= Login Session = Login Session
| Logout Session | Logout Session
......
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