[breadcrumb] approute logic moved to frontend

parent 163a9238
......@@ -5,12 +5,13 @@ module Gargantext.Components.Forest.Breadcrumb
where
import Data.Array as A
import Data.Either (Either(..), either)
import Data.Int (fromString)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.String (Pattern(..), split)
import Gargantext.Components.App.Store as Store
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.GraphQL.Endpoints (getBreadcrumb)
import Gargantext.Components.GraphQL.Endpoints (getBreadcrumb, getNodeChildren, getNodeParent)
import Gargantext.Components.GraphQL.Tree (BreadcrumbInfo, TreeNode)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Ends (Backend(..))
......@@ -312,12 +313,6 @@ breadcrumbItemCpt = here.component "breadcrumbItemCpt" cpt where
treeId :: Session -> Int
treeId (Session {treeId: tId}) = tId
getLastUrlElement :: String -> String
getLastUrlElement str = fromMaybe "" $ A.last $ split (Pattern "/") str
getFirstUrlElement :: String -> String
getFirstUrlElement str = fromMaybe "" $ A.head $ split (Pattern "/") str
getInstanceText :: Session -> String
getInstanceText (Session { backend }) = cleanBackendUrl backend
......@@ -327,12 +322,75 @@ getUserText (Session { username }) = username
type LoadProps =
type LoadRawProps =
(
route :: AppRoute
nodeId :: Int
, session :: Session
-- , reload :: T.Box T2.Reload
)
loadBreadcrumbDataRaw :: Record LoadRawProps -> AffRESTError BreadcrumbInfo
loadBreadcrumbDataRaw { nodeId, session } = getBreadcrumb session nodeId
type LoadProps =
( route :: AppRoute
, session :: Session )
loadBreadcrumbData :: Record LoadProps -> AffRESTError BreadcrumbInfo
loadBreadcrumbData { route, session } = getBreadcrumb session route
loadBreadcrumbData { route: Annuaire _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: ContactPage _s nodeId annuaireId, session } = do
loadBreadcrumbDataRaw { nodeId: annuaireId, session }
loadBreadcrumbData { route: Corpus _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: CorpusCode _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: CorpusDocument _s corpusId listId documentId, session } = do
texts <- getNodeChildren session corpusId GT.NodeTexts
let docId = maybe corpusId _.id $ either (const Nothing) A.head texts
loadBreadcrumbDataRaw { nodeId: docId, session }
loadBreadcrumbData { route: Dashboard _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: Document _s listId documentId, session } = do
corpora <- getNodeParent session listId GT.Corpus
let nodeId = maybe listId _.id $ either (const Nothing) A.head corpora
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: Folder _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: FolderPrivate _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: FolderPublic _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: FolderShared _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: Lists _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: NodeTexts _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: PGraphExplorer _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: PhyloExplorer _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: RouteFile _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: RouteFrameCalc _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: RouteFrameCode _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: RouteFrameVisio _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: RouteFrameWrite _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: Team _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: TreeFlat _s nodeId _q, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: UserPage _s nodeId, session } = do
loadBreadcrumbDataRaw { nodeId, session }
loadBreadcrumbData { route: ForgotPassword _s } = do
pure $ Right { parents: [] }
loadBreadcrumbData { route: Home } = do
pure $ Right { parents: [] }
loadBreadcrumbData { route: Login } = do
pure $ Right { parents: [] }
......@@ -160,7 +160,7 @@ type Schema
, users :: { user_id :: Int } ==> Array User
, team :: { team_node_id :: Int } ==> Team
, tree :: { root_id :: Int } ==> TreeFirstLevel
, tree_branch :: { route :: AppRoute } ==> BreadcrumbInfo
, tree_branch :: { nodeId :: Int } ==> BreadcrumbInfo
}
type Mutation
......
......@@ -227,8 +227,8 @@ getContextNgrams session context_id list_id = do
eRes <- queryGql session "get context ngrams" query
pure $ rmap (\{ context_ngrams } -> NormNgramsTerm <$> context_ngrams) eRes
getBreadcrumb :: Session -> AppRoute -> AffRESTError BreadcrumbInfo
getBreadcrumb session route = do
eRes <- queryGql session "get breadcrumb branch" $ breadcrumbQuery `withVars` { route }
getBreadcrumb :: Session -> Int -> AffRESTError BreadcrumbInfo
getBreadcrumb session nodeId = do
eRes <- queryGql session "get breadcrumb branch" $ breadcrumbQuery `withVars` { nodeId }
-- liftEffect $ here.log2 "[getBreadcrumb] breadcrumb" tree_branch
pure $ rmap _.tree_branch eRes
......@@ -43,7 +43,7 @@ treeFirstLevelQuery = { tree: { root_id: Var :: _ "id" Int} =>>
}
}
breadcrumbQuery = { tree_branch: { route: Var :: _ "route" AppRoute } =>>
breadcrumbQuery = { tree_branch: { nodeId: Var :: _ "nodeId" Int } =>>
{ parents:
{ name: unit
, node_type: unit
......
......@@ -42,37 +42,6 @@ data AppRoute
| UserPage SessionId Int
derive instance Eq AppRoute
instance ArgGql AppRoute AppRoute
instance VarTypeName AppRoute where varTypeName _ = "AppRoute!"
instance JSON.WriteForeign AppRoute
where
writeImpl (Annuaire _s n) = JSON.writeImpl { "AnnuaireRoute": { nodeId: n } }
writeImpl (ContactPage _s n a) = JSON.writeImpl { "ContactPageRoute": { nodeId: n, annuaireId: a } }
writeImpl (Corpus _s n) = JSON.writeImpl { "CorpusRoute": { nodeId: n } }
writeImpl (CorpusCode _s n) = JSON.writeImpl { "CorpusCodeRoute": { nodeId: n } }
writeImpl (CorpusDocument _s c l d) = JSON.writeImpl { "CorpusDocumentRoute": { corpusId: c, listId: l, documentId: d } }
writeImpl (Dashboard _s n) = JSON.writeImpl { "DashboardRoute": { nodeId: n } }
writeImpl (Document _s l d) = JSON.writeImpl { "DocumentRoute": { listId: l, documentId: d } }
writeImpl (Folder _s n) = JSON.writeImpl { "FolderRoute": { nodeId: n } }
writeImpl (FolderPrivate _s n) = JSON.writeImpl { "FolderPrivateRoute": { nodeId: n } }
writeImpl (FolderPublic _s n) = JSON.writeImpl { "FolderPublicRoute": { nodeId: n } }
writeImpl (FolderShared _s n) = JSON.writeImpl { "FolderSharedRoute": { nodeId: n } }
writeImpl (Lists _s n) = JSON.writeImpl { "ListsRoute": { nodeId: n } }
writeImpl (NodeTexts _s n) = JSON.writeImpl { "NodeTextsRoute": { nodeId: n } }
writeImpl (PGraphExplorer _s n) = JSON.writeImpl { "PGraphExplorerRoute": { nodeId: n } }
writeImpl (PhyloExplorer _s n) = JSON.writeImpl { "PhyloExplorerRoute": { nodeId: n } }
writeImpl (RouteFile _s n) = JSON.writeImpl { "RouteFileRoute": { nodeId: n } }
writeImpl (RouteFrameCalc _s n) = JSON.writeImpl { "RouteFrameCalcRoute": { nodeId: n } }
writeImpl (RouteFrameCode _s n) = JSON.writeImpl { "RouteFrameCodeRoute": { nodeId: n } }
writeImpl (RouteFrameVisio _s n) = JSON.writeImpl { "RouteFrameVisioRoute": { nodeId: n } }
writeImpl (RouteFrameWrite _s n) = JSON.writeImpl { "RouteFrameWriteRoute": { nodeId: n } }
writeImpl (Team _s n) = JSON.writeImpl { "TeamRoute": { nodeId: n } }
writeImpl (TreeFlat _s n q) = JSON.writeImpl { "TreeFlatRoute": { nodeId: n, query: q } }
writeImpl (UserPage _s n) = JSON.writeImpl { "UserPageRoute": { nodeId: n } }
writeImpl (ForgotPassword _) = JSON.writeImpl { "ForgotPasswordRoute": {} }
writeImpl Home = JSON.writeImpl { "HomeRoute": {} }
writeImpl Login = JSON.writeImpl { "LoginRoute": {} }
instance Argonaut.EncodeJson AppRoute where encodeJson = encodeJsonArgonaut
instance Show AppRoute where
show Home = "Home"
......
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