Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Merten
purescript-gargantext
Commits
4aca0e4a
Commit
4aca0e4a
authored
Oct 02, 2023
by
Fabien Manière
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
continue breadcrumb, trying to get session
parent
32b35f15
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
126 deletions
+135
-126
Breadcrumb.purs
src/Gargantext/Components/Forest/Breadcrumb.purs
+135
-126
No files found.
src/Gargantext/Components/Forest/Breadcrumb.purs
View file @
4aca0e4a
...
@@ -18,7 +18,7 @@ import Gargantext.Context.Session as SessionContext
...
@@ -18,7 +18,7 @@ import Gargantext.Context.Session as SessionContext
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.GraphQL.Endpoints (getBreadcrumb)
import Gargantext.Components.GraphQL.Endpoints (getBreadcrumb)
import Gargantext.Components.GraphQL.Tree (BreadcrumbInfo)
import Gargantext.Components.GraphQL.Tree (BreadcrumbInfo
, TreeNode
)
import Gargantext.Components.Login.Types (TreeId, UserId)
import Gargantext.Components.Login.Types (TreeId, UserId)
import Gargantext.Ends (Frontends, Backend(..))
import Gargantext.Ends (Frontends, Backend(..))
import Gargantext.Hooks.Session (useSession)
import Gargantext.Hooks.Session (useSession)
...
@@ -43,19 +43,23 @@ import Gargantext.Hooks.Loader (useLoader)
...
@@ -43,19 +43,23 @@ import Gargantext.Hooks.Loader (useLoader)
here :: R2.Here
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Breadcrumb"
here = R2.here "Gargantext.Components.Forest.Breadcrumb"
type Props = ( boxes :: Boxes )
type PropsBoxes = ( boxes :: Boxes )
type Props =
( nodeId :: Int
, session :: Maybe Session
)
maybeToSession :: Maybe Session -> Session
maybeToSession s = fromMaybe Nothing s
component :: R2.Leaf Props
component :: R2.Leaf PropsBoxes
component = R2.leaf componentCpt
component = R2.leaf componentCpt
componentCpt :: R.Component Props
componentCpt :: R.Component Props
Boxes
componentCpt = here.component "breadcrumb" cpt where
componentCpt = here.component "breadcrumb" cpt where
cpt props@{ boxes: { session } } _ = do
cpt props@{ boxes: { session } } _ = do
-- | States
-- | States
-- |
-- |
-- ref <- R.useRef $ R.createContext Nothing
-- context <- R.readRef ref
-- session <- useSession
-- session' :: Session
session' <- T.useLive T.unequal session
session' <- T.useLive T.unequal session
-- R.provideContext SessionContext.context session'
-- R.provideContext SessionContext.context session'
...
@@ -66,117 +70,109 @@ componentCpt = here.component "breadcrumb" cpt where
...
@@ -66,117 +70,109 @@ componentCpt = here.component "breadcrumb" cpt where
-- | Behaviors
-- | Behaviors
-- |
-- |
let
let
-- context = R.readRef ref
-- currentUrl = url
currentUrl = url
-- fragment = Fragment.toString $ Fragment.fromString "http://localhost:8008/#/corpus/user1@localhost:8008/112"
-- fragment = Fragment.toString $ Fragment.fromString "http://localhost:8008/#/corpus/user1@localhost:8008/112"
-- fragment = Fragment.toString $ Fragment.fromString url
-- fragment = Fragment.toString $ Fragment.fromString url
currentNodeId = fromMaybe 0 $ fromString $ getLastUrlElement currentUrl
currentNodeId = fromMaybe 0 $ fromString $ getLastUrlElement url
-- getBreadcrumbData =
-- case session' of
-- Nothing -> Nothing
-- Just _ -> getBreadcrumb $ fromMaybe Session { backend = ""
-- , caches = Map.empty
-- , token = ""
-- , treeId = 0
-- , userName = ""
-- , userId = 0 } $ session' currentNodeId
case session' of
case session' of
Nothing -> pure $ H.div {} []
Nothing -> pure $ H.div {} []
Just (session') -> do
Just (session') -> do
-- let breadcrumbData = getBreadcrumb session' currentNodeId
-- breadcrumbData <- R2.useLayoutEffect1' $ getBreadcrumb session' currentNodeId
pure $
pure $
-- breadcrumb layout
-- breadcrumb layout
H.div {}
H.div {}
[
[
-- H.nav {} [
breadcrumbView { currentNodeId, session' }
-- breadcrumbView { boxes }
-- ]
-- ,
-- ,
H.nav
--
H.nav
{ className: "breadcrumb-wrapper bg-light"
--
{ className: "breadcrumb-wrapper bg-light"
, "aria-label": "breadcrumb" }
--
, "aria-label": "breadcrumb" }
[
--
[
H.ol { className: "breadcrumb text-small" }
--
H.ol { className: "breadcrumb text-small" }
[
--
[
H.li { className: "breadcrumb-item" }
--
H.li { className: "breadcrumb-item" }
[
--
[
H.a { href: "/" }
--
H.a { href: "/" }
[ H.span { className: "" }
--
[ H.span { className: "" }
[
--
[
B.icon { name: "home" }
--
B.icon { name: "home" }
]
--
]
, H.text "Home"
--
, H.text "Home"
]
--
]
]
--
]
, H.li { className: "breadcrum-item" }
--
, H.li { className: "breadcrum-item" }
[
--
[
H.span {}
--
H.span {}
[
--
[
H.text $ show session' <> " - " <> show currentNodeId
--
H.text $ show session' <> " - " <> show currentNodeId
-- H.text $ show breadcrumbData
--
-- H.text $ show breadcrumbData
]
--
]
]
--
]
,
--
,
H.li { className: "breadcrumb-item" }
--
H.li { className: "breadcrumb-item" }
[
--
[
H.a { href: "/" }
--
H.a { href: "/" }
[ H.span { className: "" }
--
[ H.span { className: "" }
[
--
[
B.icon { name: "folder-open-o" }
--
B.icon { name: "folder-open-o" }
]
--
]
, H.text "parent folder"
--
, H.text "parent folder"
]
--
]
]
--
]
,
--
,
H.li { className: "breadcrumb-item" }
--
H.li { className: "breadcrumb-item" }
[ H.span { className: "active-page" }
--
[ H.span { className: "active-page" }
[ H.span { className: "" }
--
[ H.span { className: "" }
[
--
[
B.icon { name: "book" }
--
B.icon { name: "book" }
]
--
]
, H.text "current node"
--
, H.text "current node"
]
--
]
]
--
]
]
--
]
]
--
]
]
]
-- where
-- breadcrumbData = getBreadcrumbData
breadcrumbView :: R2.Leaf Props
breadcrumbView :: R2.Leaf Props
breadcrumbView = R2.leaf breadcrumbViewCpt
breadcrumbView = R2.leaf breadcrumbViewCpt
breadcrumbViewCpt :: R.Component Props
breadcrumbViewCpt :: R.Component Props
breadcrumbViewCpt = here.component "breadcrumbViewCpt" cpt where
breadcrumbViewCpt = here.component "breadcrumbViewCpt" cpt where
cpt props@{ boxes: { session } } _ = do
cpt { nodeId, session } _ = do
session' <- T.useLive T.unequal session
-- session' <- session
url <- R.unsafeHooksEffect GU.href
-- session' <- T.useLive T.unequal session
let nodeId = fromMaybe 0 $ fromString $ getLastUrlElement url
-- url <- R.unsafeHooksEffect GU.href
-- let nodeId = fromMaybe 0 $ fromString $ getLastUrlElement url
session' <- liftEffect $ maybeToSession session
case session' of
case session' of
Nothing -> pure $ H.div {} []
Nothing -> pure $ H.div {} []
Just (session') -> do
Just (session') -> do
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: loadBreadcrumbData
, loader: loadBreadcrumbData
, path: { nodeId, session', reload: reload'}
, path: { nodeId: nodeId
, render: \items -> breadcrumbViewMain { items
, session: session'
, nodeId
-- , reload: reload'
, reload
}
, session'
, render: \items -> breadcrumbViewMain { items: items
} [] }
, nodeId: nodeId
where
, session: session'
-- , reload: reload
} []
}
where
errorHandler = logRESTError here "[breadcrumbView]"
errorHandler = logRESTError here "[breadcrumbView]"
type BreadcrumbViewProps =
type BreadcrumbViewProps =
( items :: BreadcrumbInfo
( items :: BreadcrumbInfo
, nodeId :: Int
, nodeId :: Int
, reload :: T.Box T2.Reload
--
, reload :: T.Box T2.Reload
, session :: Session
, session :: Session
)
)
...
@@ -185,58 +181,71 @@ breadcrumbViewMain = R.createElement breadcrumbViewMainCpt
...
@@ -185,58 +181,71 @@ breadcrumbViewMain = R.createElement breadcrumbViewMainCpt
breadcrumbViewMainCpt :: R.Component BreadcrumbViewProps
breadcrumbViewMainCpt :: R.Component BreadcrumbViewProps
breadcrumbViewMainCpt = here.component "breadcrumbViewMainCpt" cpt where
breadcrumbViewMainCpt = here.component "breadcrumbViewMainCpt" cpt where
cpt props@{ items: { parents } } _ = do
cpt props@{ items: { parents } } _ = do
let breadcrumbItems = makeBreadcrumbItems parents
let items = makeBreadcrumbElements parents props
-- let breadcrumbItems = pure $ H.text "breadcrumb in devlopment"
pure $
pure $
H.div { className: "breadcrumb-view" } $
items
H.div
{ className: "breadcrumb-view" } $
breadcrumbItems
makeBreadcrumbElements :: Array TreeNode -> Record BreadcrumbViewProps -> Array R.Element
makeBreadcrumbElements items' props = makeBreadcrumbElementsMap <$> items' where
makeBreadcrumbItems :: Array TreeNode -> Maybe TreeNode -> Record BreadcrumbViewProps -> Array R.Element
makeBreadcrumbElementsMap :: TreeNode -> R.Element
makeBreadcrumbItems root (Just parent) props =
makeBreadcrumbElementsMap node = breadcrumbItem { nodeId: node.id
[
, linkId: node.id
breadcrumbItem
, nodeType: node.node_type
{ name: parent.name
, linkNodeType: node.node_type
, parent_id: parent.parent_id
, parentId: props.nodeId
, node_type: parent.node_type
-- , reload: props.reload
, id: parent.id
, session: props.session
}
-- , style: FolderChild
]
, text: node.name
-- where
, disabled: false
-- disabled { node_type } = if node_type == GT.FolderShared then true else false
}
makeBreadcrumbItems _ Nothing _ = []
type BreadcrumbItemProps =
type BreadcrumbItemProps =
( disabled :: Boolean
( node_type :: NodeType
, linkNodeType :: NodeType
, id :: Int
, linkId :: Int
, parent_id :: Int
, nodeType :: NodeType
, name :: String
, nodeId :: Int
, parentId :: Int
-- , reload :: T.Box T2.Reload
, session :: Session
-- , style :: FolderStyle
, text :: String
)
)
breadcrumbItem :: R2.Leaf BreadcrumbItemProps
breadcrumbItem :: R2.Leaf BreadcrumbItemProps
breadcrumbItem = R2.leaf breadcrumbItemCpt
breadcrumbItem = R2.leaf breadcrumbItemCpt
breadcrumbItemCpt :: R.Component BreadcrumbItemProps
breadcrumbItemCpt :: R.Component BreadcrumbItemProps
breadcrumbItemCpt = here.component "breadcrumbItemCpt" cpt where
breadcrumbItemCpt = here.component "breadcrumbItemCpt" cpt where
cpt props@{ nodeType
cpt props@{ nodeId
, nodeId
, linkId
, nodeType
, linkNodeType
, parentId
, parentId
, reload
--
, reload
, session
, session
, style
--
, style
, text
, text
, disabled
} _ = do
} _ = do
pure $ H.div {} []
pure $
H.div { className: "bItem" }
[
H.text props.text
]
getLastUrlElement :: String -> String
getLastUrlElement :: String -> String
getLastUrlElement str = fromMaybe "" $ A.last $ split (Pattern "/") str
getLastUrlElement str = fromMaybe "" $ A.last $ split (Pattern "/") str
type LoadProps =
type LoadProps =
(
(
session :: Session
,
session :: Session
nodeId :: Int,
, nodeId :: Int
reload ::
T2.Reload
-- , reload :: T.Box
T2.Reload
)
)
loadBreadcrumbData :: Record LoadProps -> AffRESTError BreadcrumbInfo
loadBreadcrumbData :: Record LoadProps -> AffRESTError BreadcrumbInfo
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment