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
Grégoire Locqueville
purescript-gargantext
Commits
710142ee
Commit
710142ee
authored
Mar 22, 2021
by
Karen Konou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up code
parent
554cbb9f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
36 deletions
+34
-36
Corpus.purs
src/Gargantext/Components/Nodes/Corpus.purs
+34
-36
No files found.
src/Gargantext/Components/Nodes/Corpus.purs
View file @
710142ee
...
@@ -25,14 +25,13 @@ import Gargantext.Components.Node (NodePoly(..), HyperdataList)
...
@@ -25,14 +25,13 @@ import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..))
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata(..))
import Gargantext.Data.Array as GDA
import Gargantext.Data.Array as GDA
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(NodeAPI, Children
)
)
import Gargantext.Routes (SessionRoute(NodeAPI, Children
, TreeFirstLevel), AppRoute(Home), appPath, nodeTypeAppRoute
)
import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Sessions (Session, get, put, sessionId)
import Gargantext.Types (NodeType(..), AffTableResult, SessionId)
import Gargantext.Types (NodeType(..), AffTableResult, SessionId)
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Reload as GUR
import Gargantext.Routes
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
...
@@ -57,8 +56,15 @@ corpusLayoutCpt = R.hooksComponentWithModule thisModule "corpusLayout" cpt
...
@@ -57,8 +56,15 @@ corpusLayoutCpt = R.hooksComponentWithModule thisModule "corpusLayout" cpt
where
where
cpt { nodeId, session } _ = do
cpt { nodeId, session } _ = do
let sid = sessionId session
let sid = sessionId session
viewType <- R.useState' Folders
pure $ H.div{} [
H.div{} [viewTypeSelector {state: viewType} ]
, H.div{} [renderContent (fst viewType) nodeId session sid]
]
pure $ corpusLayoutWithKey { key: show sid <> "-" <> show nodeId, nodeId, session }
renderContent Folders nodeId session _ = folderViewLoad {nodeId, session}
renderContent Code nodeId session sid = corpusLayoutWithKey { key: show sid <> "-" <> show nodeId, nodeId, session }
corpusLayoutWithKey :: Record KeyProps -> R.Element
corpusLayoutWithKey :: Record KeyProps -> R.Element
...
@@ -85,11 +91,10 @@ corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
...
@@ -85,11 +91,10 @@ corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
corpusLayoutViewCpt :: R.Component ViewProps
corpusLayoutViewCpt :: R.Component ViewProps
corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" cpt
corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" cpt
where
where
cpt {corpus: (NodePoly {hyperdata: Hyperdata {fields}
, parentId
}), nodeId, reload, session} _ = do
cpt {corpus: (NodePoly {hyperdata: Hyperdata {fields}}), nodeId, reload, session} _ = do
let fieldsWithIndex = List.mapWithIndex (\idx -> \t -> Tuple idx t) fields
let fieldsWithIndex = List.mapWithIndex (\idx -> \t -> Tuple idx t) fields
fieldsS <- R.useState' fieldsWithIndex
fieldsS <- R.useState' fieldsWithIndex
fieldsRef <- R.useRef fields
fieldsRef <- R.useRef fields
viewType <- R.useState' Folders
-- handle props change of fields
-- handle props change of fields
R.useEffect1' fields $ do
R.useEffect1' fields $ do
...
@@ -104,18 +109,12 @@ corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" c
...
@@ -104,18 +109,12 @@ corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" c
[ H.div { className: "btn btn-primary " <> (saveEnabled fieldsWithIndex fieldsS)
[ H.div { className: "btn btn-primary " <> (saveEnabled fieldsWithIndex fieldsS)
, on: { click: onClickSave {fields: fieldsS, nodeId, reload, session} }
, on: { click: onClickSave {fields: fieldsS, nodeId, reload, session} }
}
}
[ H.span { className: "fa fa-floppy-o" } [ ]
[ H.span { className: "fa fa-floppy-o" } [ ] ]
]
, H.div { className: "col-1" } [ viewTypeSelector {state: viewType} ]
]
]
, H.div {}
, H.div {}
[ renderContent (fst viewType)
[ fieldsCodeEditor { fields: fieldsS
{ fields: fieldsS
, nodeId
, session}
{ parentId
, nodeId
, nodeId
, session}
]
, session } []
]
, H.div { className: "row" }
, H.div { className: "row" }
[ H.div { className: "btn btn-primary"
[ H.div { className: "btn btn-primary"
, on: { click: onClickAdd fieldsS }
, on: { click: onClickAdd fieldsS }
...
@@ -125,10 +124,6 @@ corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" c
...
@@ -125,10 +124,6 @@ corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" c
]
]
]
]
renderContent :: ViewType -> Record FieldsCodeEditorProps -> Record FolderLoadProps -> R.Element
renderContent Code props _ = fieldsCodeEditor props []
renderContent Folders _ props = folderViewLoad props
saveEnabled :: FTFieldsWithIndex -> R.State FTFieldsWithIndex -> String
saveEnabled :: FTFieldsWithIndex -> R.State FTFieldsWithIndex -> String
saveEnabled fs (fsS /\ _) = if fs == fsS then "disabled" else "enabled"
saveEnabled fs (fsS /\ _) = if fs == fsS then "disabled" else "enabled"
...
@@ -147,29 +142,21 @@ corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" c
...
@@ -147,29 +142,21 @@ corpusLayoutViewCpt = R.hooksComponentWithModule thisModule "corpusLayoutView" c
onClickAdd (_ /\ setFieldsS) _ = do
onClickAdd (_ /\ setFieldsS) _ = do
setFieldsS $ \fieldsS -> List.snoc fieldsS $ Tuple (List.length fieldsS) defaultField
setFieldsS $ \fieldsS -> List.snoc fieldsS $ Tuple (List.length fieldsS) defaultField
type FolderLoadProps =
(
nodeId :: Int
, parentId :: Int
, session :: Session
)
data FolderStyle = FolderUp | FolderChild
data FolderStyle = FolderUp | FolderChild
folderViewLoad :: Record
Folder
LoadProps -> R.Element
folderViewLoad :: Record LoadProps -> R.Element
folderViewLoad props = R.createElement folderViewLoadCpt props []
folderViewLoad props = R.createElement folderViewLoadCpt props []
folderViewLoadCpt :: R.Component
Folder
LoadProps
folderViewLoadCpt :: R.Component LoadProps
folderViewLoadCpt = R.hooksComponentWithModule thisModule "folderViewLoadCpt" cpt where
folderViewLoadCpt = R.hooksComponentWithModule thisModule "folderViewLoadCpt" cpt where
cpt {
parentId,
nodeId, session} _ = do
cpt {nodeId, session} _ = do
useLoader {nodeId, session} loadFolders $
useLoader {nodeId, session} loadFolders $
\folders -> folderView {folders,
parentId,
nodeId, session}
\folders -> folderView {folders, nodeId, session}
type FolderViewProps =
type FolderViewProps =
(
(
nodeId :: Int
nodeId :: Int
, folders:: FTree
, folders:: FTree
, parentId :: Int
, session :: Session
, session :: Session
)
)
...
@@ -178,17 +165,26 @@ folderView props = R.createElement folderViewCpt props []
...
@@ -178,17 +165,26 @@ folderView props = R.createElement folderViewCpt props []
folderViewCpt :: R.Component FolderViewProps
folderViewCpt :: R.Component FolderViewProps
folderViewCpt = R.hooksComponentWithModule thisModule "folderViewCpt" cpt where
folderViewCpt = R.hooksComponentWithModule thisModule "folderViewCpt" cpt where
cpt {
parentId, nodeId, session, folders: (NTree _
(foldersS))} _ = do
cpt {
nodeId, session, folders: (NTree (LNode {parent_id: parentId})
(foldersS))} _ = do
let sid = sessionId session
let sid = sessionId session
let children = makeFolderElements foldersS sid
let children = makeFolderElements foldersS sid
let parent = makeParentFolder parentId sid
pure $ H.div {className: "folders"} $
[folder {style: FolderUp, text: "..", nodeId: parentId, sid: sid, nodeType: FolderPrivate} []]
<> children
pure $ H.div {className: "folders"} $
parent
<> children
makeFolderElements :: Array (NTree LNode) -> SessionId -> Array R.Element
makeFolderElements :: Array (NTree LNode) -> SessionId -> Array R.Element
makeFolderElements foldersS sid = makeFolderElementsMap <$> foldersS where
makeFolderElements foldersS sid = makeFolderElementsMap <$> foldersS where
makeFolderElementsMap :: NTree LNode -> R.Element
makeFolderElementsMap :: NTree LNode -> R.Element
makeFolderElementsMap (NTree (LNode node) _) = folder {style: FolderChild, text: node.name, nodeId: node.id, nodeType: node.nodeType, sid: sid} []
makeFolderElementsMap (NTree (LNode node) _) = folder {style: FolderChild, text: node.name, nodeId: node.id, nodeType: node.nodeType, sid: sid} []
makeParentFolder :: Maybe Int -> SessionId -> Array R.Element
makeParentFolder (Just parentId) sid =
-- 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
[ folder {style: FolderUp, text: "..", nodeId: parentId, nodeType: FolderPrivate, sid: sid} [] ]
makeParentFolder Nothing _ = []
type FolderProps =
type FolderProps =
(
(
style :: FolderStyle
style :: FolderStyle
...
@@ -208,6 +204,7 @@ folderCpt = R.hooksComponentWithModule thisModule "folderCpt" cpt where
...
@@ -208,6 +204,7 @@ folderCpt = R.hooksComponentWithModule thisModule "folderCpt" cpt where
, H.br {}
, H.br {}
, H.text text]
, H.text text]
icon :: FolderStyle -> NodeType -> String
icon FolderUp _ = "fa-folder-open"
icon FolderUp _ = "fa-folder-open"
icon _ Dashboard = "fa-signal"
icon _ Dashboard = "fa-signal"
icon _ Texts = "fa-newspaper-o"
icon _ Texts = "fa-newspaper-o"
...
@@ -216,6 +213,7 @@ folderCpt = R.hooksComponentWithModule thisModule "folderCpt" cpt where
...
@@ -216,6 +213,7 @@ folderCpt = R.hooksComponentWithModule thisModule "folderCpt" cpt where
icon _ NodeFile = "fa-file"
icon _ NodeFile = "fa-file"
icon FolderChild _ = "fa-folder"
icon FolderChild _ = "fa-folder"
getFolderPath :: NodeType -> SessionId -> Int -> String
getFolderPath nodeType sid nodeId = appPath $ fromMaybe Home $ nodeTypeAppRoute nodeType sid nodeId
getFolderPath nodeType sid nodeId = appPath $ fromMaybe Home $ nodeTypeAppRoute nodeType sid nodeId
...
...
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