diff --git a/src/Gargantext/Components/FolderView.purs b/src/Gargantext/Components/FolderView.purs index 9d22a7cacf31873b9d4924c96ee55dd694113ca3..bfaa134f2a27e38b67193c0d914ac3722b2e7b40 100644 --- a/src/Gargantext/Components/FolderView.purs +++ b/src/Gargantext/Components/FolderView.purs @@ -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.Upload (uploadArbitraryFile, uploadFile) 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.GraphQL.Endpoints (getTreeFirstLevel) +import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, TreeNode) import Gargantext.Config.REST (AffRESTError, logRESTError) import Gargantext.Config.Utils (handleRESTError) import Gargantext.Hooks.LinkHandler (Methods, useLinkHandler) import Gargantext.Hooks.Loader (useLoader) import Gargantext.Prelude (Ordering, Unit, bind, compare, discard, pure, unit, void, ($), (<$>), (<>)) -import Gargantext.Routes (AppRoute(Home), SessionRoute(..), nodeTypeAppRoute) -import Gargantext.Sessions (Session, get, sessionId) +import Gargantext.Routes (AppRoute(Home), nodeTypeAppRoute) +import Gargantext.Sessions (Session, sessionId) import Gargantext.Types (NodeType(..)) import Gargantext.Types as GT import Gargantext.Utils.Popover as Popover @@ -76,7 +77,7 @@ folderViewCpt = here.component "folderViewCpt" cpt where type FolderViewProps = ( backFolder :: Boolean , boxes :: Boxes - , folders :: FTree + , folders :: TreeFirstLevel , nodeId :: Int , reload :: T.Box T2.Reload , session :: Session @@ -89,24 +90,24 @@ folderViewMainCpt :: R.Component FolderViewProps folderViewMainCpt = here.component "folderViewMainCpt" cpt where cpt { backFolder , boxes - , folders: NTree (LNode {parent_id: parentId, nodeType}) (folders) + , folders: {parent: parentNode, root: {node_type: nodeType}, children} , nodeId , reload , session , setPopoverRef } _ = do linkHandlers <- useLinkHandler - let foldersS = A.sortBy sortFolders folders + let foldersS = A.sortBy sortFolders children let backHome = isBackHome nodeType - let parent = makeParentFolder linkHandlers parentId session backFolder backHome - let children = makeFolderElements foldersS { boxes, nodeId, reload, session, setPopoverRef } + let parent = makeParentFolder linkHandlers parentNode session backFolder backHome + 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 - makeFolderElementsMap :: NTree LNode -> R.Element - makeFolderElementsMap (NTree (LNode node) _) = folder { boxes: props.boxes + makeFolderElementsMap :: TreeNode -> R.Element + makeFolderElementsMap node = folder { boxes: props.boxes , nodeId: node.id - , nodeType: node.nodeType + , nodeType: node.node_type , parentId: props.nodeId , reload: props.reload , session: props.session @@ -114,11 +115,11 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where , style: FolderChild , text: node.name } [] - makeParentFolder :: Record Methods -> Maybe Int -> Session -> Boolean -> Boolean -> Array R.Element - makeParentFolder _ (Just parentId) session _ _ = + makeParentFolder :: Record Methods -> Maybe TreeNode -> Session -> Boolean -> Boolean -> Array R.Element + makeParentFolder _ (Just parent) session _ _ = -- 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 - [ 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" } [] , H.br {} , H.text ".."] ] @@ -128,8 +129,8 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where makeParentFolder _ Nothing _ _ _ = [] - sortFolders :: FTree -> FTree -> Ordering - sortFolders a b = compare (fTreeID a) (fTreeID b) + sortFolders :: TreeNode-> TreeNode -> Ordering + sortFolders a b = compare a.id b.id isBackHome :: GT.NodeType -> Boolean isBackHome GT.FolderPrivate = true @@ -261,8 +262,8 @@ type LoadProps = reload :: T2.Reload ) -loadFolders :: Record LoadProps -> AffRESTError FTree -loadFolders {nodeId, session} = get session $ TreeFirstLevel (Just nodeId) "" +loadFolders :: Record LoadProps -> AffRESTError TreeFirstLevel +loadFolders {nodeId, session} = getTreeFirstLevel session nodeId type PerformActionProps = ( boxes :: Boxes diff --git a/src/Gargantext/Components/GraphQL.purs b/src/Gargantext/Components/GraphQL.purs index f3ae01b9bf82b37fa5fdbd793f6448d401bda8bf..a69be42608acbedb3914d4bb3caba1ac0abf2cfc 100644 --- a/src/Gargantext/Components/GraphQL.purs +++ b/src/Gargantext/Components/GraphQL.purs @@ -11,6 +11,7 @@ import Effect.Aff (Aff) import Effect.Class (liftEffect) import Foreign (unsafeToForeign, ForeignError) import Gargantext.Components.GraphQL.Node (Node) +import Gargantext.Components.GraphQL.Tree (TreeFirstLevel) import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM) import Gargantext.Ends (Backend(..)) import Gargantext.Sessions (Session(..)) @@ -70,6 +71,7 @@ type Schema = { node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType , user_infos :: { user_id :: Int } ==> Array UserInfo , users :: { user_id :: Int } ==> Array User + , tree :: { root_id :: Int } ==> TreeFirstLevel } type Mutation diff --git a/src/Gargantext/Components/GraphQL/Endpoints.purs b/src/Gargantext/Components/GraphQL/Endpoints.purs index c3f46d1680fcbe4ddde1da4b1802631e03425f38..04924b0c728326d45b11fc36dab16b0d04f09293 100644 --- a/src/Gargantext/Components/GraphQL/Endpoints.purs +++ b/src/Gargantext/Components/GraphQL/Endpoints.purs @@ -2,6 +2,7 @@ module Gargantext.Components.GraphQL.Endpoints where import Gargantext.Components.GraphQL.Node import Gargantext.Components.GraphQL.User +import Gargantext.Components.GraphQL.Tree import Gargantext.Prelude import Data.Array as A @@ -41,3 +42,9 @@ getUserInfo session id = do -- NOTE Contact is at G.C.N.A.U.C.Types 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 + diff --git a/src/Gargantext/Components/GraphQL/Tree.purs b/src/Gargantext/Components/GraphQL/Tree.purs new file mode 100644 index 0000000000000000000000000000000000000000..ef8bf885fc8acb66e77c0bb63d195dfd92c326ca --- /dev/null +++ b/src/Gargantext/Components/GraphQL/Tree.purs @@ -0,0 +1,35 @@ +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 + } + } + }