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
410205dc
Commit
410205dc
authored
Oct 11, 2019
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext
into dev
parents
2896c5c5
0859bf96
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
196 additions
and
165 deletions
+196
-165
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+1
-1
Loader.purs
src/Gargantext/Components/Loader.purs
+25
-132
Login.purs
src/Gargantext/Components/Login.purs
+2
-2
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+1
-1
OldLoader.purs
src/Gargantext/Components/OldLoader.purs
+135
-0
Table.purs
src/Gargantext/Components/Table.purs
+2
-2
Tree.purs
src/Gargantext/Components/Tree.purs
+14
-9
Texts.purs
src/Gargantext/Pages/Texts.purs
+16
-18
No files found.
src/Gargantext/Components/DocsTable.purs
View file @
410205dc
...
@@ -295,7 +295,7 @@ pageCpt = R.memo' $ R.hooksComponent "G.C.DocsTable.pageCpt" cpt where
...
@@ -295,7 +295,7 @@ pageCpt = R.memo' $ R.hooksComponent "G.C.DocsTable.pageCpt" cpt where
row (DocumentsView r) =
row (DocumentsView r) =
{ row:
{ row:
[ H.div {} [ H.a { className, style, on: {click: click Favorite} } [] ]
[ H.div {} [ H.a { className, style, on: {click: click Favorite} } [] ]
, H.input { type: "checkbox", checked, on: {click: click Trash} }
, H.input { type: "checkbox",
defaultValue:
checked, on: {click: click Trash} }
-- TODO show date: Year-Month-Day only
-- TODO show date: Year-Month-Day only
, H.div { style } [ R2.showText r.date ]
, H.div { style } [ R2.showText r.date ]
, H.div { style } [ H.text r.title ]
, H.div { style } [ H.text r.title ]
...
...
src/Gargantext/Components/Loader.purs
View file @
410205dc
module Gargantext.Components.Loader where
module Gargantext.Components.Loader where
import Control.Monad.Cont.Trans (lift)
import Prelude
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..), isNothing, maybe, maybe')
import React as React
import Data.Tuple.Nested ((/\))
import React (ReactClass, Children)
import Gargantext.Prelude
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Thermite (Render, PerformAction, simpleSpec, modifyState_, createReactSpec)
import Reactix as R
import Gargantext.Utils.Reactix as R2
data Action path = ForceReload | SetPath path
import Gargantext.Components.LoadingSpinner (loadingSpinner)
type InnerPropsRow path loaded row =
type Props path loaded =
( path :: path
( path :: path
, loaded :: loaded
, load :: path -> Aff loaded
, dispatch :: Action path -> Effect Unit
, paint :: loaded -> R.Element )
| row
)
loader :: forall path loaded. path -> (path -> Aff loaded) -> (loaded -> R.Element) -> R.Element
loader path load paint =
type InnerProps path loaded row = Record (InnerPropsRow path loaded row)
R.createElement loaderCpt {path,load,paint} []
type InnerClass path loaded = ReactClass (InnerProps path loaded (children :: Children))
loaderCpt :: forall path loaded. R.Component (Props path loaded)
loaderCpt = R.hooksComponent "G.C.Loader" cpt where
type PropsRow path loaded row =
cpt {path, load, paint} _ = do
( path :: path
(loaded /\ setLoaded) <- R.useState' Nothing
, component :: InnerClass path loaded
R.useEffect3 path load paint $ do
| row
R2.affEffect "G.H.Loader.useAff" $
)
load path >>= (liftEffect <<< setLoaded <<< const <<< Just)
pure $ maybe' (\_ -> loadingSpinner {}) paint loaded
type Props path loaded = Record (PropsRow path loaded (children :: Children))
type Props' path loaded = Record (PropsRow path loaded ())
type State path loaded = { currentPath :: path, loaded :: Maybe loaded }
createLoaderClass' :: forall path loaded props
. Eq path
=> Show path
=> String
-> (path -> Aff loaded)
-> Render (State path loaded) {path :: path | props} (Action path)
-> ReactClass { path :: path, children :: Children | props }
createLoaderClass' name loader render =
React.component name
(\this -> do
logs $ "createLoaderClass' " <> name
s <- spec this
pure { state: s.state
, render: s.render
, componentDidMount: do
logs $ name <> ".componentDidMount"
dispatcher this ForceReload
, componentDidUpdate: \{path: prevPath} {currentPath} _snapshot -> do
{path} <- React.getProps this
logs $ name <> ".componentDidUpdate " <> show {currentPath, path, prevPath}
-- This guard is the similar to the one in performAction (SetPath ...),
-- however we need it here to avoid potential infinite loops.
-- https://reactjs.org/docs/react-component.html#componentdidupdate
-- Moreover we want to make sure that not only the new prop
-- `path` is different from the one in the state (`currentPath`)
-- but also that it is different than the previous `path` prop
-- (`prevPath`). This avoid the path being reset to the
-- previous value.
when (prevPath /= path && path /= currentPath) do
dispatcher this (SetPath path)
})
where
initialState {path} = {currentPath: path, loaded: Nothing}
performAction :: PerformAction (State path loaded) {path :: path | props} (Action path)
performAction ForceReload _ {currentPath} = do
logs $ name <> ".ForceReload {currentPath: " <> show currentPath <> "}"
loaded <- lift $ loader currentPath
modifyState_ $ _ { loaded = Just loaded }
performAction (SetPath newPath) _ {currentPath} = do
logs $ name <> ".SetPath " <> show {newPath, currentPath}
when (newPath /= currentPath) do
loaded <- lift $ loader newPath
modifyState_ $ _ { currentPath = newPath, loaded = Just loaded }
{spec, dispatcher} = createReactSpec (simpleSpec performAction render) initialState
type LoaderClass path loaded =
ReactClass (Record (PropsRow path loaded (children :: Children)))
createLoaderClass :: forall path loaded
. Eq path
=> Show path
=> String
-> (path -> Aff loaded)
-> LoaderClass path loaded
createLoaderClass name loader =
createLoaderClass' name loader render
where
render :: Render (State path loaded) (Props' path loaded) (Action path)
render _ _ {loaded: Nothing} _ =
-- TODO load spinner
[]
render dispatch {component} {currentPath, loaded: Just loaded} c =
[React.createElement component {path: currentPath, loaded, dispatch} c]
{-
createLoaderClass :: forall path loaded
. String
-> (path -> Aff loaded)
-> ReactClass (Props path loaded)
createLoaderClass name loader = React.component name mk
where
mk this =
pure
{ state: { loaded: Nothing, fiber: Nothing }
, componentDidMount: do
logs "componentDidMount"
{path} <- React.getProps this
fiber <- launchAff $ do
newState <- loader path
makeAff $ \cb -> do
void $ React.modifyStateWithCallback
this
(_ {loaded = Just newState})
(cb (Right unit))
pure nonCanceler
React.modifyState this (_ { fiber = Just fiber })
, componentWillUnmount: do
{fiber} <- React.getState this
traverse_ (launchAff_ <<< killFiber (error "Loader: killFiber"))
fiber
, render: do
{path, component} <- React.getProps this
{loaded} <- React.getState this
pure $ React.createElement component {path, loaded} []
}
-}
src/Gargantext/Components/Login.purs
View file @
410205dc
...
@@ -37,13 +37,13 @@ modal :: Record ModalProps -> R.Element -> R.Element
...
@@ -37,13 +37,13 @@ modal :: Record ModalProps -> R.Element -> R.Element
modal props child = R.createElement modalCpt props [ child ]
modal props child = R.createElement modalCpt props [ child ]
modalCpt :: R.Component ModalProps
modalCpt :: R.Component ModalProps
modalCpt = R.hooksComponent "
M
odal" cpt where
modalCpt = R.hooksComponent "
G.C.Login.m
odal" cpt where
cpt {visible} children = do
cpt {visible} children = do
R.createPortal elems <$> R2.getPortalHost
R.createPortal elems <$> R2.getPortalHost
where
where
click _ = log "click!" *> (snd visible) (const false)
click _ = log "click!" *> (snd visible) (const false)
elems =
elems =
[ H.div { id: "loginModal", className: modalClass (fst visible)
[ H.div { id: "loginModal", className: modalClass (fst visible)
, key: 0
, role: "dialog", "data": {show: true}, style: {display: "block"}}
, role: "dialog", "data": {show: true}, style: {display: "block"}}
[ H.div { className: "modal-dialog", role: "document"}
[ H.div { className: "modal-dialog", role: "document"}
[ H.div { className: "modal-content" }
[ H.div { className: "modal-content" }
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
410205dc
...
@@ -87,7 +87,7 @@ import Partial.Unsafe (unsafePartial)
...
@@ -87,7 +87,7 @@ import Partial.Unsafe (unsafePartial)
import Gargantext.Config.REST (get, put, post)
import Gargantext.Config.REST (get, put, post)
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Components.Loader as Loader
import Gargantext.Components.
Old
Loader as Loader
import Gargantext.Ends (url)
import Gargantext.Ends (url)
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session)
import Gargantext.Sessions (Session)
...
...
src/Gargantext/Components/OldLoader.purs
0 → 100644
View file @
410205dc
module Gargantext.Components.OldLoader where
import Control.Monad.Cont.Trans (lift)
import Data.Maybe (Maybe(..))
import React as React
import React (ReactClass, Children)
import Gargantext.Prelude
import Effect (Effect)
import Effect.Aff (Aff)
import Thermite (Render, PerformAction, simpleSpec, modifyState_, createReactSpec)
data Action path = ForceReload | SetPath path
type InnerPropsRow path loaded row =
( path :: path
, loaded :: loaded
, dispatch :: Action path -> Effect Unit
| row
)
type InnerProps path loaded row = Record (InnerPropsRow path loaded row)
type InnerClass path loaded = ReactClass (InnerProps path loaded (children :: Children))
type PropsRow path loaded row =
( path :: path
, component :: InnerClass path loaded
| row
)
type Props path loaded = Record (PropsRow path loaded (children :: Children))
type Props' path loaded = Record (PropsRow path loaded ())
type State path loaded = { currentPath :: path, loaded :: Maybe loaded }
createLoaderClass' :: forall path loaded props
. Eq path
=> Show path
=> String
-> (path -> Aff loaded)
-> Render (State path loaded) {path :: path | props} (Action path)
-> ReactClass { path :: path, children :: Children | props }
createLoaderClass' name loader render =
React.component name
(\this -> do
logs $ "createLoaderClass' " <> name
s <- spec this
pure { state: s.state
, render: s.render
, componentDidMount: do
logs $ name <> ".componentDidMount"
dispatcher this ForceReload
, componentDidUpdate: \{path: prevPath} {currentPath} _snapshot -> do
{path} <- React.getProps this
logs $ name <> ".componentDidUpdate " <> show {currentPath, path, prevPath}
-- This guard is the similar to the one in performAction (SetPath ...),
-- however we need it here to avoid potential infinite loops.
-- https://reactjs.org/docs/react-component.html#componentdidupdate
-- Moreover we want to make sure that not only the new prop
-- `path` is different from the one in the state (`currentPath`)
-- but also that it is different than the previous `path` prop
-- (`prevPath`). This avoid the path being reset to the
-- previous value.
when (prevPath /= path && path /= currentPath) do
dispatcher this (SetPath path)
})
where
initialState {path} = {currentPath: path, loaded: Nothing}
performAction :: PerformAction (State path loaded) {path :: path | props} (Action path)
performAction ForceReload _ {currentPath} = do
logs $ name <> ".ForceReload {currentPath: " <> show currentPath <> "}"
loaded <- lift $ loader currentPath
modifyState_ $ _ { loaded = Just loaded }
performAction (SetPath newPath) _ {currentPath} = do
logs $ name <> ".SetPath " <> show {newPath, currentPath}
when (newPath /= currentPath) do
loaded <- lift $ loader newPath
modifyState_ $ _ { currentPath = newPath, loaded = Just loaded }
{spec, dispatcher} = createReactSpec (simpleSpec performAction render) initialState
type LoaderClass path loaded =
ReactClass (Record (PropsRow path loaded (children :: Children)))
createLoaderClass :: forall path loaded
. Eq path
=> Show path
=> String
-> (path -> Aff loaded)
-> LoaderClass path loaded
createLoaderClass name loader =
createLoaderClass' name loader render
where
render :: Render (State path loaded) (Props' path loaded) (Action path)
render _ _ {loaded: Nothing} _ =
-- TODO load spinner
[]
render dispatch {component} {currentPath, loaded: Just loaded} c =
[React.createElement component {path: currentPath, loaded, dispatch} c]
{-
createLoaderClass :: forall path loaded
. String
-> (path -> Aff loaded)
-> ReactClass (Props path loaded)
createLoaderClass name loader = React.component name mk
where
mk this =
pure
{ state: { loaded: Nothing, fiber: Nothing }
, componentDidMount: do
logs "componentDidMount"
{path} <- React.getProps this
fiber <- launchAff $ do
newState <- loader path
makeAff $ \cb -> do
void $ React.modifyStateWithCallback
this
(_ {loaded = Just newState})
(cb (Right unit))
pure nonCanceler
React.modifyState this (_ { fiber = Just fiber })
, componentWillUnmount: do
{fiber} <- React.getState this
traverse_ (launchAff_ <<< killFiber (error "Loader: killFiber"))
fiber
, render: do
{path, component} <- React.getProps this
{loaded} <- React.getState this
pure $ React.createElement component {path, loaded} []
}
-}
src/Gargantext/Components/Table.purs
View file @
410205dc
...
@@ -179,7 +179,7 @@ graphContainer {title} props =
...
@@ -179,7 +179,7 @@ graphContainer {title} props =
-- , props.paginationLinks
-- , props.paginationLinks
sizeDD :: PageSizes -> R2.Setter PageSizes -> R.Element
sizeDD :: PageSizes -> R2.Setter PageSizes -> R.Element
sizeDD ps setPageSize = H.span {} [ R2.select { className, on: {change} } sizes ]
sizeDD ps setPageSize = H.span {} [ R2.select { className,
defaultValue: ps,
on: {change} } sizes ]
where
where
className = "form-control"
className = "form-control"
change e = setPageSize $ const (string2PageSize $ R2.unsafeEventValue e)
change e = setPageSize $ const (string2PageSize $ R2.unsafeEventValue e)
...
@@ -278,4 +278,4 @@ string2PageSize "200" = PS200
...
@@ -278,4 +278,4 @@ string2PageSize "200" = PS200
string2PageSize _ = PS10
string2PageSize _ = PS10
optps :: PageSizes -> PageSizes -> R.Element
optps :: PageSizes -> PageSizes -> R.Element
optps
cv val = H.option {selected: (cv == val),
value: show val} [R2.showText val]
optps
_cv val = H.option {
value: show val} [R2.showText val]
src/Gargantext/Components/Tree.purs
View file @
410205dc
...
@@ -5,6 +5,7 @@ import Prelude hiding (div)
...
@@ -5,6 +5,7 @@ import Prelude hiding (div)
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log2)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Array (filter)
import Data.Array (filter)
import Data.FunctorWithIndex (mapWithIndex)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
import Data.Generic.Rep.Show (genericShow)
...
@@ -225,7 +226,6 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
...
@@ -225,7 +226,6 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
popupOpen <- R.useState' (Nothing :: Maybe NodePopup)
popupOpen <- R.useState' (Nothing :: Maybe NodePopup)
droppedFile <- R.useState' (Nothing :: Maybe DroppedFile)
droppedFile <- R.useState' (Nothing :: Maybe DroppedFile)
isDragOver <- R.useState' false
isDragOver <- R.useState' false
pure $ H.span (dropProps droppedFile isDragOver)
pure $ H.span (dropProps droppedFile isDragOver)
[ folderIcon folderOpen
[ folderIcon folderOpen
, H.a { href: (url frontends (NodePath (sessionId session) nodeType (Just id)))
, H.a { href: (url frontends (NodePath (sessionId session) nodeType (Just id)))
...
@@ -288,14 +288,19 @@ childNodes :: Session -> Frontends
...
@@ -288,14 +288,19 @@ childNodes :: Session -> Frontends
-> Array R.Element
-> Array R.Element
childNodes _ _ _ _ _ [] = []
childNodes _ _ _ _ _ [] = []
childNodes _ _ _ (false /\ _) _ _ = []
childNodes _ _ _ (false /\ _) _ _ = []
childNodes session frontends reload (true /\ _) mCurrentRoute ary = map (\ctree -> childNode {tree: ctree}) ary
childNodes session frontends reload (true /\ _) route ary =
where
mapWithIndex (\index tree -> childNode {tree, session, frontends, reload, route, key: index}) ary
childNode :: Tree -> R.Element
childNode props = R.createElement el props []
type ChildProps = ( tree :: FTree, session :: Session, frontends :: Frontends, key :: Int, reload :: R.State Reload, route :: Maybe AppRoute )
el = R.hooksComponent "ChildNodeView" cpt
cpt {tree} _ = do
childNode :: Record ChildProps -> R.Element
treeState <- R.useState' {tree}
childNode props = R.createElement childNodeCpt props []
pure $ toHtml reload treeState session frontends mCurrentRoute
childNodeCpt :: R.Component ChildProps
childNodeCpt = R.hooksComponent "G.C.Tree.childNode" cpt where
cpt {tree, reload, session, frontends, route} _ = do
treeState <- R.useState' {tree}
pure $ toHtml reload treeState session frontends route
-- END toHtml
-- END toHtml
...
...
src/Gargantext/Pages/Texts.purs
View file @
410205dc
...
@@ -10,6 +10,7 @@ import Effect.Exception (error)
...
@@ -10,6 +10,7 @@ import Effect.Exception (error)
import Reactix as R
import Reactix as R
--------------------------------------------------------
--------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Components.Loader (loader)
import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Table as Table
import Gargantext.Components.Table as Table
import Gargantext.Config.REST (get)
import Gargantext.Config.REST (get)
...
@@ -28,25 +29,22 @@ textsLayout props = R.createElement textsLayoutCpt props []
...
@@ -28,25 +29,22 @@ textsLayout props = R.createElement textsLayoutCpt props []
------------------------------------------------------------------------
------------------------------------------------------------------------
textsLayoutCpt :: R.Component Props
textsLayoutCpt :: R.Component Props
textsLayoutCpt = R.hooksComponent "TextsLoader" cpt
textsLayoutCpt = R.hooksComponent "G.P.Texts.textsLayout" cpt where
where
cpt path@{session} _ = do
cpt {session,nodeId} _ =
pure $ loader path loadCorpus paint
useLoader nodeId (getCorpus session) $
where
\corpusData@{corpusId, corpusNode, defaultListId} ->
paint corpusData@{corpusId, corpusNode, defaultListId} =
let
R.fragment [ Table.tableHeaderLayout headerProps, tabs ]
NodePoly { name, date, hyperdata: CorpusInfo corpus } = corpusNode
where
{desc, query, authors: user} = corpus
NodePoly { name, date, hyperdata: CorpusInfo corpus } = corpusNode
tabs = Tabs.tabs {session, corpusId, corpusData}
{desc, query, authors: user} = corpus
title = "Corpus " <> name
tabs = Tabs.tabs {session, corpusId, corpusData}
headerProps = { title, desc, query, date, user } in
title = "Corpus " <> name
R.fragment [Table.tableHeaderLayout headerProps, tabs]
headerProps = { title, desc, query, date, user }
------------------------------------------------------------------------
------------------------------------------------------------------------
getCorpus :: Session -> Int
-> Aff CorpusData
loadCorpus :: Record Props
-> Aff CorpusData
getCorpus session textsId
= do
loadCorpus {session, nodeId}
= do
liftEffect $ log2 "nodepolyurl: " nodePolyUrl
liftEffect $ log2 "nodepolyurl: " nodePolyUrl
-- fetch corpus via texts parentId
-- fetch corpus via texts parentId
(NodePoly {parentId: corpusId} :: NodePoly {}) <- get nodePolyUrl
(NodePoly {parentId: corpusId} :: NodePoly {}) <- get nodePolyUrl
...
@@ -60,6 +58,6 @@ getCorpus session textsId = do
...
@@ -60,6 +58,6 @@ getCorpus session textsId = do
Nothing ->
Nothing ->
throwError $ error "Missing default list"
throwError $ error "Missing default list"
where
where
nodePolyUrl = url session $ NodeAPI Corpus (Just
texts
Id)
nodePolyUrl = url session $ NodeAPI Corpus (Just
node
Id)
corpusNodeUrl = url session <<< NodeAPI Corpus <<< Just
corpusNodeUrl = url session <<< NodeAPI Corpus <<< Just
defaultListIdsUrl = url session <<< Children NodeList 0 1 Nothing <<< Just
defaultListIdsUrl = url session <<< Children NodeList 0 1 Nothing <<< Just
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