Commit 38615b10 authored by Karen Konou's avatar Karen Konou

[Folder view] Consolidate folder components

Also enables settings on root/parent folder
parent b092b18f
......@@ -33,7 +33,7 @@ import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Ordering, Unit, bind, compare, discard, otherwise, pure, unit, void, ($), (<$>), (<>))
import Gargantext.Routes (AppRoute(Home), nodeTypeAppRoute)
import Gargantext.Sessions (Session(..), sessionId)
import Gargantext.Types (NodeType(..))
import Gargantext.Types (NodeType(..), SessionId)
import Gargantext.Types as GT
import Gargantext.Utils.Popover as Popover
import Gargantext.Utils.Reactix as R2
......@@ -87,82 +87,58 @@ folderViewMain :: R2.Component FolderViewProps
folderViewMain = R.createElement folderViewMainCpt
folderViewMainCpt :: R.Component FolderViewProps
folderViewMainCpt = here.component "folderViewMainCpt" cpt where
cpt { boxes
, folders: {parent: parentNode, children}
, nodeId
, reload
, session
, setPopoverRef } _ = do
cpt props@{ folders: {parent: parentNode, children, root} } _ = do
let folders' = A.sortBy sortFolders children
let parent = makeParentFolder parentNode session
let childrenEl = makeFolderElements folders' { boxes, nodeId, reload, session, setPopoverRef }
let parent = makeParentFolder root parentNode props
let childrenEl = makeFolderElements folders' props
pure $ H.div {className: "fv folders"} $ parent <> childrenEl
makeFolderElements :: Array TreeNode -> Record FolderViewProps -> Array R.Element
makeFolderElements folders' props = makeFolderElementsMap <$> folders' where
makeFolderElementsMap :: TreeNode -> R.Element
makeFolderElementsMap node = folder { boxes: props.boxes
, nodeId: node.id
, nodeType: node.node_type
, parentId: props.nodeId
, reload: props.reload
, session: props.session
, setPopoverRef: props.setPopoverRef
, style: FolderChild
, text: node.name } []
makeParentFolder :: Maybe TreeNode -> Session -> Array R.Element
makeParentFolder (Just parent) session =
[ folderSimple {style: FolderUp, text: "..", nodeId: parent.id, nodeType: parent.node_type, session: session} [] ]
makeParentFolder Nothing _ = []
, nodeId: node.id
, linkId: node.id
, nodeType: node.node_type
, linkNodeType: node.node_type
, parentId: props.nodeId
, reload: props.reload
, session: props.session
, setPopoverRef: props.setPopoverRef
, style: FolderChild
, text: node.name } []
makeParentFolder :: TreeNode -> Maybe TreeNode -> Record FolderViewProps -> Array R.Element
makeParentFolder root (Just parent) props =
[ folder { boxes: props.boxes
, nodeId: root.id
, linkId: parent.id
, linkNodeType: parent.node_type
, nodeType: root.node_type
, parentId: parent.id
, reload: props.reload
, session: props.session
, setPopoverRef: props.setPopoverRef
, style: FolderUp
, text: root.name } [] ]
makeParentFolder _ Nothing _ = []
sortFolders :: TreeNode-> TreeNode -> Ordering
sortFolders a b = compare a.id b.id
type FolderSimpleProps =
(
style :: FolderStyle
, text :: String
, nodeType :: GT.NodeType
, nodeId :: Int
, session :: Session
)
getFolderPath :: GT.NodeType -> GT.SessionId -> Int -> AppRoute
getFolderPath nodeType sid nodeId = fromMaybe Home $ nodeTypeAppRoute nodeType sid nodeId
icon :: FolderStyle -> GT.NodeType -> String
icon FolderUp _ = "fa fa-folder-open"
icon _ nodeType = GT.fldr nodeType false
treeId :: Session -> Int
treeId (Session {treeId: tId}) = tId
folderSimple :: R2.Component FolderSimpleProps
folderSimple = R.createElement folderSimpleCpt
folderSimpleCpt :: R.Component FolderSimpleProps
folderSimpleCpt = here.component "folderSimpleCpt" cpt where
cpt {style, text, nodeId, session, nodeType} _ = do
{ goToRoute } <- useLinkHandler
let sid = sessionId session
let rootId = treeId session
pure $ H.button { className: "btn btn-primary"
, on: {click: \_ -> goToRoute $ route nodeId rootId nodeType sid} }
[ H.i { className: icon style nodeType } []
, H.br {}
, H.text text ]
where
route nId rootId nType sid
| rootId == nodeId = Home
| otherwise = getFolderPath nType sid nId
type FolderProps =
( boxes :: Boxes
( style :: FolderStyle
, text :: String
, nodeType :: GT.NodeType
, nodeId :: Int
, linkNodeType :: GT.NodeType
, linkId :: Int
, session :: Session
, boxes :: Boxes
, parentId :: Int
, reload :: T.Box T2.Reload
, setPopoverRef :: R.Ref (Maybe (Boolean -> Effect Unit))
| FolderSimpleProps
)
folder :: R2.Component FolderProps
......@@ -172,6 +148,8 @@ folderCpt = here.component "folderCpt" cpt where
cpt props@{ boxes
, nodeId
, nodeType
, linkId
, linkNodeType
, parentId
, reload
, session
......@@ -179,6 +157,7 @@ folderCpt = here.component "folderCpt" cpt where
, style
, text } _ = do
let sid = sessionId session
let rootId = treeId session
let dispatch a = performAction a { boxes, nodeId, parentId, reload, session, setPopoverRef }
popoverRef <- R.useRef null
{ goToRoute } <- useLinkHandler
......@@ -198,7 +177,7 @@ folderCpt = here.component "folderCpt" cpt where
popOverIcon
, mNodePopupView (Record.merge props { dispatch }) (onPopoverClose popoverRef)
]]
, H.button {on: {click: \_ -> goToRoute $ getFolderPath nodeType sid nodeId }, className: "btn btn-primary fv btn" } [
, H.button {on: {click: \_ -> goToRoute $ route linkId rootId linkNodeType sid }, className: "btn btn-primary fv btn" } [
H.i {className: icon style nodeType} []
, H.br {}
, H.text text]]
......@@ -219,6 +198,17 @@ folderCpt = here.component "folderCpt" cpt where
, name: props.text
, session: props.session
}
route :: Int -> Int -> NodeType -> SessionId -> AppRoute
route lId rootId nType sid
| rootId == lId = Home
| otherwise = getFolderPath nType sid lId
icon :: FolderStyle -> GT.NodeType -> String
icon FolderUp _ = "fa fa-folder-open"
icon _ nodeType = GT.fldr nodeType false
getFolderPath :: GT.NodeType -> GT.SessionId -> Int -> AppRoute
getFolderPath nodeType sid nodeId = fromMaybe Home $ nodeTypeAppRoute nodeType sid nodeId
backButton :: R2.Component ()
backButton = R.createElement backButtonCpt
......@@ -272,6 +262,9 @@ backButtonSmartMainCpt = here.component "backButtonSmartMain" cpt where
| rootId == pId = handlers.goToRoute Home
| otherwise = handlers.goToPreviousPage unit
treeId :: Session -> Int
treeId (Session {treeId: tId}) = tId
type LoadProps =
(
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