Commit 8c46f761 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-merge' into dev

parents 2be10f99 b5a6a3ff
module Gargantext.Components.FolderView where module Gargantext.Components.FolderView where
import Data.Array as A import Data.Array as A
import Data.Eq ((==))
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Nullable (null) import Data.Nullable (null)
import Data.Traversable (traverse_) import Data.Traversable (traverse_)
...@@ -26,11 +27,11 @@ import Gargantext.Components.GraphQL.Endpoints (getTreeFirstLevel) ...@@ -26,11 +27,11 @@ import Gargantext.Components.GraphQL.Endpoints (getTreeFirstLevel)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, TreeNode) 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 (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, otherwise, pure, unit, void, ($), (<$>), (<>))
import Gargantext.Routes (AppRoute(Home), nodeTypeAppRoute) import Gargantext.Routes (AppRoute(Home), nodeTypeAppRoute)
import Gargantext.Sessions (Session, 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
...@@ -45,8 +46,7 @@ here :: R2.Here ...@@ -45,8 +46,7 @@ here :: R2.Here
here = R2.here "Gargantext.Components.FolderView" here = R2.here "Gargantext.Components.FolderView"
type Props = type Props =
( backFolder :: Boolean ( boxes :: Boxes
, boxes :: Boxes
, nodeId :: Int , nodeId :: Int
, session :: Session , session :: Session
) )
...@@ -57,15 +57,14 @@ folderView :: R2.Leaf Props ...@@ -57,15 +57,14 @@ folderView :: R2.Leaf Props
folderView = R2.leafComponent folderViewCpt folderView = R2.leafComponent folderViewCpt
folderViewCpt :: R.Component Props folderViewCpt :: R.Component Props
folderViewCpt = here.component "folderViewCpt" cpt where folderViewCpt = here.component "folderViewCpt" cpt where
cpt { backFolder, boxes, nodeId, session } _ = do cpt { boxes, nodeId, session } _ = do
setPopoverRef <- R.useRef Nothing setPopoverRef <- R.useRef Nothing
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload reload' <- T.useLive T.unequal reload
useLoader { errorHandler useLoader { errorHandler
, loader: loadFolders , loader: loadFolders
, path: { nodeId, session, reload: reload'} , path: { nodeId, session, reload: reload'}
, render: \folders -> folderViewMain { backFolder , render: \folders -> folderViewMain { boxes
, boxes
, folders , folders
, nodeId , nodeId
, reload , reload
...@@ -75,8 +74,7 @@ folderViewCpt = here.component "folderViewCpt" cpt where ...@@ -75,8 +74,7 @@ folderViewCpt = here.component "folderViewCpt" cpt where
errorHandler = logRESTError here "[folderView]" errorHandler = logRESTError here "[folderView]"
type FolderViewProps = type FolderViewProps =
( backFolder :: Boolean ( boxes :: Boxes
, boxes :: Boxes
, folders :: TreeFirstLevel , folders :: TreeFirstLevel
, nodeId :: Int , nodeId :: Int
, reload :: T.Box T2.Reload , reload :: T.Box T2.Reload
...@@ -88,17 +86,14 @@ folderViewMain :: R2.Component FolderViewProps ...@@ -88,17 +86,14 @@ folderViewMain :: R2.Component FolderViewProps
folderViewMain = R.createElement folderViewMainCpt folderViewMain = R.createElement folderViewMainCpt
folderViewMainCpt :: R.Component FolderViewProps folderViewMainCpt :: R.Component FolderViewProps
folderViewMainCpt = here.component "folderViewMainCpt" cpt where folderViewMainCpt = here.component "folderViewMainCpt" cpt where
cpt { backFolder cpt { boxes
, boxes , folders: {parent: parentNode, children}
, folders: {parent: parentNode, root: {node_type: nodeType}, children}
, nodeId , nodeId
, reload , reload
, session , session
, setPopoverRef } _ = do , setPopoverRef } _ = do
linkHandlers <- useLinkHandler
let foldersS = A.sortBy sortFolders children let foldersS = A.sortBy sortFolders children
let backHome = isBackHome nodeType let parent = makeParentFolder parentNode session
let parent = makeParentFolder linkHandlers parentNode session backFolder backHome
let childrenEl = makeFolderElements foldersS { boxes, nodeId, reload, session, setPopoverRef } let childrenEl = makeFolderElements foldersS { boxes, nodeId, reload, session, setPopoverRef }
pure $ H.div {className: "fv folders"} $ parent <> childrenEl pure $ H.div {className: "fv folders"} $ parent <> childrenEl
...@@ -115,30 +110,15 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where ...@@ -115,30 +110,15 @@ folderViewMainCpt = here.component "folderViewMainCpt" cpt where
, style: FolderChild , style: FolderChild
, text: node.name } [] , text: node.name } []
makeParentFolder :: Record Methods -> Maybe TreeNode -> Session -> Boolean -> Boolean -> Array R.Element makeParentFolder :: Maybe TreeNode -> Session -> Array R.Element
makeParentFolder _ (Just parent) session _ _ = makeParentFolder (Just parent) session =
-- FIXME: The NodeType here should not be hardcoded to FolderPrivate but we currently can't get the actual NodeType [ folderSimple {style: FolderUp, text: "..", nodeId: parent.id, nodeType: parent.node_type, session: session} [] ]
-- without performing another API call. Also parentId is never being returned by this API even when it clearly exists makeParentFolder Nothing _ = []
[ 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 ".."] ]
makeParentFolder linkHandlers Nothing _ true _ = [ H.button {className: "btn btn-primary", on: { click: \_ -> linkHandlers.goToPreviousPage unit } } [ H.i { className: "fa fa-folder-open" } []
, H.br {}
, H.text ".."] ]
makeParentFolder _ Nothing _ _ _ = []
sortFolders :: TreeNode-> TreeNode -> Ordering sortFolders :: TreeNode-> TreeNode -> Ordering
sortFolders a b = compare a.id b.id sortFolders a b = compare a.id b.id
isBackHome :: GT.NodeType -> Boolean
isBackHome GT.FolderPrivate = true
isBackHome GT.FolderPublic = true
isBackHome GT.FolderShared = true
isBackHome _ = false
type FolderSimpleProps = type FolderSimpleProps =
( (
style :: FolderStyle style :: FolderStyle
...@@ -156,11 +136,18 @@ folderSimpleCpt = here.component "folderSimpleCpt" cpt where ...@@ -156,11 +136,18 @@ folderSimpleCpt = here.component "folderSimpleCpt" cpt where
cpt {style, text, nodeId, session, nodeType} _ = do cpt {style, text, nodeId, session, nodeType} _ = do
{ goToRoute } <- useLinkHandler { goToRoute } <- useLinkHandler
let sid = sessionId session let sid = sessionId session
let rootId = treeId session
pure $ H.button { className: "btn btn-primary" pure $ H.button { className: "btn btn-primary"
, on: {click: \_ -> goToRoute $ getFolderPath nodeType sid nodeId} } , on: {click: \_ -> goToRoute $ route nodeId rootId nodeType sid} }
[ H.i { className: icon style nodeType } [] [ H.i { className: icon style nodeType } []
, H.br {} , H.br {}
, H.text text ] , H.text text ]
where
treeId (Session {treeId: tId}) = tId
route nId rootId nType sid
| rootId == nodeId = Home
| otherwise = getFolderPath nType sid nId
icon :: FolderStyle -> GT.NodeType -> String icon :: FolderStyle -> GT.NodeType -> String
icon FolderUp _ = "fa fa-folder-open" icon FolderUp _ = "fa fa-folder-open"
......
...@@ -88,8 +88,7 @@ corpusLayoutMainCpt = here.component "corpusLayoutMain" cpt ...@@ -88,8 +88,7 @@ corpusLayoutMainCpt = here.component "corpusLayoutMain" cpt
H.hr {} H.hr {}
, ,
FV.folderView FV.folderView
{ backFolder: true { boxes
, boxes
, nodeId , nodeId
, session , session
} }
......
...@@ -183,8 +183,7 @@ tutorialCpt = here.component "tutorial" cpt where ...@@ -183,8 +183,7 @@ tutorialCpt = here.component "tutorial" cpt where
sessionToFolder session@(Session {treeId, username, backend}) = sessionToFolder session@(Session {treeId, username, backend}) =
H.span { className: "folder" } [ H.span { className: "folder" } [
H.div { className: "d-flex justify-content-center" } [ H.text (username <> "@" <> (cleanBackendUrl backend)) ] H.div { className: "d-flex justify-content-center" } [ H.text (username <> "@" <> (cleanBackendUrl backend)) ]
, H.div {} [ FV.folderView { backFolder: false , H.div {} [ FV.folderView { boxes
, boxes
, nodeId: treeId , nodeId: treeId
, session } ] ] , 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