Commit be376bfa authored by Karen Konou's avatar Karen Konou

[Folder View] Use GQL API

parent 0539153f
...@@ -21,15 +21,16 @@ import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..)) ...@@ -21,15 +21,16 @@ import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest) import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadArbitraryFile, uploadFile) import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadArbitraryFile, uploadFile)
import Gargantext.Components.Forest.Tree.Node.Box (nodePopupView) import Gargantext.Components.Forest.Tree.Node.Box (nodePopupView)
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..), fTreeID)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut(..)) import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut(..))
import Gargantext.Components.GraphQL.Endpoints (getTreeFirstLevel)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, TreeNode)
import Gargantext.Config.REST (AffRESTError, logRESTError) import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Config.Utils (handleRESTError) import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Hooks.LinkHandler (Methods, useLinkHandler) import Gargantext.Hooks.LinkHandler (Methods, useLinkHandler)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Ordering, Unit, bind, compare, discard, pure, unit, void, ($), (<$>), (<>)) import Gargantext.Prelude (Ordering, Unit, bind, compare, discard, pure, unit, void, ($), (<$>), (<>))
import Gargantext.Routes (AppRoute(Home), SessionRoute(..), nodeTypeAppRoute) import Gargantext.Routes (AppRoute(Home), nodeTypeAppRoute)
import Gargantext.Sessions (Session, get, sessionId) import Gargantext.Sessions (Session, sessionId)
import Gargantext.Types (NodeType(..)) import Gargantext.Types (NodeType(..))
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Popover as Popover import Gargantext.Utils.Popover as Popover
...@@ -76,7 +77,7 @@ folderViewCpt = here.component "folderViewCpt" cpt where ...@@ -76,7 +77,7 @@ folderViewCpt = here.component "folderViewCpt" cpt where
type FolderViewProps = type FolderViewProps =
( backFolder :: Boolean ( backFolder :: Boolean
, boxes :: Boxes , boxes :: Boxes
, folders :: FTree , folders :: TreeFirstLevel
, nodeId :: Int , nodeId :: Int
, reload :: T.Box T2.Reload , reload :: T.Box T2.Reload
, session :: Session , session :: Session
...@@ -89,24 +90,24 @@ folderViewMainCpt :: R.Component FolderViewProps ...@@ -89,24 +90,24 @@ folderViewMainCpt :: R.Component FolderViewProps
folderViewMainCpt = here.component "folderViewMainCpt" cpt where folderViewMainCpt = here.component "folderViewMainCpt" cpt where
cpt { backFolder cpt { backFolder
, boxes , boxes
, folders: NTree (LNode {parent_id: parentId, nodeType}) (folders) , folders: {parent: parentNode, root: {node_type: nodeType}, children}
, nodeId , nodeId
, reload , reload
, session , session
, setPopoverRef } _ = do , setPopoverRef } _ = do
linkHandlers <- useLinkHandler linkHandlers <- useLinkHandler
let foldersS = A.sortBy sortFolders folders let foldersS = A.sortBy sortFolders children
let backHome = isBackHome nodeType let backHome = isBackHome nodeType
let parent = makeParentFolder linkHandlers parentId session backFolder backHome let parent = makeParentFolder linkHandlers parentNode session backFolder backHome
let children = makeFolderElements foldersS { boxes, nodeId, reload, session, setPopoverRef } let childrenEl = makeFolderElements foldersS { boxes, nodeId, reload, session, setPopoverRef }
pure $ H.div {className: "fv folders"} $ parent <> children pure $ H.div {className: "fv folders"} $ parent <> childrenEl
makeFolderElements foldersS props = makeFolderElementsMap <$> foldersS where makeFolderElements foldersS props = makeFolderElementsMap <$> foldersS where
makeFolderElementsMap :: NTree LNode -> R.Element makeFolderElementsMap :: TreeNode -> R.Element
makeFolderElementsMap (NTree (LNode node) _) = folder { boxes: props.boxes makeFolderElementsMap node = folder { boxes: props.boxes
, nodeId: node.id , nodeId: node.id
, nodeType: node.nodeType , nodeType: node.node_type
, parentId: props.nodeId , parentId: props.nodeId
, reload: props.reload , reload: props.reload
, session: props.session , session: props.session
...@@ -114,11 +115,11 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where ...@@ -114,11 +115,11 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where
, style: FolderChild , style: FolderChild
, text: node.name } [] , text: node.name } []
makeParentFolder :: Record Methods -> Maybe Int -> Session -> Boolean -> Boolean -> Array R.Element makeParentFolder :: Record Methods -> Maybe TreeNode -> Session -> Boolean -> Boolean -> Array R.Element
makeParentFolder _ (Just parentId) session _ _ = makeParentFolder _ (Just parent) session _ _ =
-- FIXME: The NodeType here should not be hardcoded to FolderPrivate but we currently can't get the actual NodeType -- FIXME: The NodeType here should not be hardcoded to FolderPrivate but we currently can't get the actual NodeType
-- without performing another API call. Also parentId is never being returned by this API even when it clearly exists -- without performing another API call. Also parentId is never being returned by this API even when it clearly exists
[ folderSimple {style: FolderUp, text: "..", nodeId: parentId, nodeType: GT.FolderPrivate, session: session} [] ] [ folderSimple {style: FolderUp, text: "..", nodeId: parent.id, nodeType: GT.FolderPrivate, session: session} [] ]
makeParentFolder linkHandlers Nothing _ _ true = [ H.button {className: "btn btn-primary", on: { click: \_ -> linkHandlers.goToRoute Home}} [ H.i { className: "fa fa-folder-open" } [] makeParentFolder linkHandlers Nothing _ _ true = [ H.button {className: "btn btn-primary", on: { click: \_ -> linkHandlers.goToRoute Home}} [ H.i { className: "fa fa-folder-open" } []
, H.br {} , H.br {}
, H.text ".."] ] , H.text ".."] ]
...@@ -128,8 +129,8 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where ...@@ -128,8 +129,8 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where
makeParentFolder _ Nothing _ _ _ = [] makeParentFolder _ Nothing _ _ _ = []
sortFolders :: FTree -> FTree -> Ordering sortFolders :: TreeNode-> TreeNode -> Ordering
sortFolders a b = compare (fTreeID a) (fTreeID b) sortFolders a b = compare a.id b.id
isBackHome :: GT.NodeType -> Boolean isBackHome :: GT.NodeType -> Boolean
isBackHome GT.FolderPrivate = true isBackHome GT.FolderPrivate = true
...@@ -261,8 +262,8 @@ type LoadProps = ...@@ -261,8 +262,8 @@ type LoadProps =
reload :: T2.Reload reload :: T2.Reload
) )
loadFolders :: Record LoadProps -> AffRESTError FTree loadFolders :: Record LoadProps -> AffRESTError TreeFirstLevel
loadFolders {nodeId, session} = get session $ TreeFirstLevel (Just nodeId) "" loadFolders {nodeId, session} = getTreeFirstLevel session nodeId
type PerformActionProps = type PerformActionProps =
( boxes :: Boxes ( boxes :: Boxes
......
...@@ -11,6 +11,7 @@ import Effect.Aff (Aff) ...@@ -11,6 +11,7 @@ import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError) import Foreign (unsafeToForeign, ForeignError)
import Gargantext.Components.GraphQL.Node (Node) import Gargantext.Components.GraphQL.Node (Node)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM) import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Ends (Backend(..)) import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..)) import Gargantext.Sessions (Session(..))
...@@ -70,6 +71,7 @@ type Schema ...@@ -70,6 +71,7 @@ type Schema
= { node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType = { node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType
, user_infos :: { user_id :: Int } ==> Array UserInfo , user_infos :: { user_id :: Int } ==> Array UserInfo
, users :: { user_id :: Int } ==> Array User , users :: { user_id :: Int } ==> Array User
, tree :: { root_id :: Int } ==> TreeFirstLevel
} }
type Mutation type Mutation
......
...@@ -2,6 +2,7 @@ module Gargantext.Components.GraphQL.Endpoints where ...@@ -2,6 +2,7 @@ module Gargantext.Components.GraphQL.Endpoints where
import Gargantext.Components.GraphQL.Node import Gargantext.Components.GraphQL.Node
import Gargantext.Components.GraphQL.User import Gargantext.Components.GraphQL.User
import Gargantext.Components.GraphQL.Tree
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array as A import Data.Array as A
...@@ -41,3 +42,9 @@ getUserInfo session id = do ...@@ -41,3 +42,9 @@ getUserInfo session id = do
-- NOTE Contact is at G.C.N.A.U.C.Types -- NOTE Contact is at G.C.N.A.U.C.Types
Just ui -> Right ui Just ui -> Right ui
getTreeFirstLevel :: Session -> Int -> AffRESTError TreeFirstLevel
getTreeFirstLevel session id = do
{ tree } <- queryGql session "get tree first level" $ treeFirstLevelQuery `withVars` { id }
liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree
pure $ Right tree -- TODO: error handling
module Gargantext.Components.GraphQL.Tree where
import Gargantext.Prelude
import Data.Maybe (Maybe)
import Gargantext.Types (NodeType)
import GraphQL.Client.Args ((=>>))
import GraphQL.Client.Variable (Var(..))
type TreeNode =
{ name :: String
, id :: Int
, node_type :: NodeType
}
type TreeFirstLevel =
{ root :: TreeNode
, children :: Array TreeNode
, parent :: Maybe TreeNode
}
treeFirstLevelQuery = { tree: { root_id: Var :: _ "id" Int} =>>
{ root: { name: unit
, node_type: unit
, id: unit
}
, children: { name: unit
, node_type: unit
, id: unit
}
, parent: { name: unit
, node_type: unit
, id: unit
}
}
}
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