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
864e0235
Unverified
Commit
864e0235
authored
Jul 05, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Loader2] upgrade some loaders
parent
5735f12b
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
161 additions
and
148 deletions
+161
-148
Loader2.purs
src/Gargantext/Components/Loader2.purs
+4
-2
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+6
-3
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+1
-0
Tree.purs
src/Gargantext/Components/Tree.purs
+1
-1
Specs.purs
src/Gargantext/Pages/Annuaire/User/Contacts/Specs.purs
+13
-35
Specs.purs
src/Gargantext/Pages/Annuaire/User/Contacts/Tabs/Specs.purs
+21
-6
Types.purs
src/Gargantext/Pages/Annuaire/User/Contacts/Types.purs
+0
-4
Corpus.purs
src/Gargantext/Pages/Corpus.purs
+25
-47
Document.purs
src/Gargantext/Pages/Corpus/Document.purs
+26
-27
Specs.purs
src/Gargantext/Pages/Corpus/Tabs/Specs.purs
+27
-19
Types.purs
src/Gargantext/Pages/Corpus/Tabs/Types.purs
+1
-2
Reactix.purs
src/Gargantext/Utils/Reactix.purs
+36
-2
No files found.
src/Gargantext/Components/Loader2.purs
View file @
864e0235
...
@@ -8,6 +8,8 @@ import Effect.Class (liftEffect)
...
@@ -8,6 +8,8 @@ import Effect.Class (liftEffect)
import Effect.Exception (error)
import Effect.Exception (error)
import Reactix as R
import Reactix as R
type Props path loaded = { path :: path, loaded :: loaded }
type State path loaded = { currentPath :: path, loaded :: Maybe loaded }
type State path loaded = { currentPath :: path, loaded :: Maybe loaded }
useLoader
useLoader
...
@@ -16,7 +18,7 @@ useLoader
...
@@ -16,7 +18,7 @@ useLoader
=> Show path
=> Show path
=> path
=> path
-> (path -> Aff loaded)
-> (path -> Aff loaded)
-> (
path ->
loaded -> R.Element)
-> (
Props path
loaded -> R.Element)
-> R.Hooks R.Element
-> R.Hooks R.Element
useLoader newPath loader render = do
useLoader newPath loader render = do
{currentPath, loaded} /\ setState <- R.useState' { currentPath: newPath, loaded: Nothing }
{currentPath, loaded} /\ setState <- R.useState' { currentPath: newPath, loaded: Nothing }
...
@@ -37,4 +39,4 @@ useLoader newPath loader render = do
...
@@ -37,4 +39,4 @@ useLoader newPath loader render = do
-- TODO load spinner
-- TODO load spinner
R.fragment []
R.fragment []
Just loadedData ->
Just loadedData ->
render
currentPath loadedData
render
{path: currentPath, loaded: loadedData}
src/Gargantext/Components/NgramsTable.purs
View file @
864e0235
...
@@ -298,14 +298,17 @@ ngramsTableClass :: Loader.InnerClass PageParams VersionedNgramsTable
...
@@ -298,14 +298,17 @@ ngramsTableClass :: Loader.InnerClass PageParams VersionedNgramsTable
ngramsTableClass = createClass "NgramsTable" ngramsTableSpec initialState
ngramsTableClass = createClass "NgramsTable" ngramsTableSpec initialState
type MainNgramsTableProps =
type MainNgramsTableProps =
Loader.InnerProps Int { defaultListId :: Int }
{ nodeId :: Int
( tabType :: TabType )
-- ^ This node can be a corpus or contact.
, defaultListId :: Int
, tabType :: TabType
}
mainNgramsTableSpec :: Spec {} MainNgramsTableProps Void
mainNgramsTableSpec :: Spec {} MainNgramsTableProps Void
mainNgramsTableSpec = simpleSpec defaultPerformAction render
mainNgramsTableSpec = simpleSpec defaultPerformAction render
where
where
render :: Render {} MainNgramsTableProps Void
render :: Render {} MainNgramsTableProps Void
render _ {
path: nodeId, loaded: {defaultListId}
, tabType} _ _ =
render _ {
nodeId, defaultListId
, tabType} _ _ =
[ ngramsLoader
[ ngramsLoader
{ path: initialPageParams nodeId [defaultListId] tabType
{ path: initialPageParams nodeId [defaultListId] tabType
, component: ngramsTableClass
, component: ngramsTableClass
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
864e0235
...
@@ -87,6 +87,7 @@ import Gargantext.Components.Loader as Loader
...
@@ -87,6 +87,7 @@ import Gargantext.Components.Loader as Loader
type CoreParams s =
type CoreParams s =
{ nodeId :: Int
{ nodeId :: Int
-- ^ This node can be a corpus or contact.
, listIds :: Array Int
, listIds :: Array Int
, tabType :: TabType
, tabType :: TabType
| s
| s
...
...
src/Gargantext/Components/Tree.purs
View file @
864e0235
...
@@ -184,7 +184,7 @@ treeLoadView setReload p = R.createElement el p []
...
@@ -184,7 +184,7 @@ treeLoadView setReload p = R.createElement el p []
where
where
el = R.hooksComponent "TreeLoadView" cpt
el = R.hooksComponent "TreeLoadView" cpt
cpt {root, mCurrentRoute} _ = do
cpt {root, mCurrentRoute} _ = do
useLoader root loadNode $ \
currentPath loaded
->
useLoader root loadNode $ \
{loaded}
->
loadedTreeView setReload {tree: loaded, mCurrentRoute}
loadedTreeView setReload {tree: loaded, mCurrentRoute}
treeview :: Spec {} Props Void
treeview :: Spec {} Props Void
...
...
src/Gargantext/Pages/Annuaire/User/Contacts/Specs.purs
View file @
864e0235
...
@@ -16,20 +16,20 @@ import Data.Newtype (unwrap)
...
@@ -16,20 +16,20 @@ import Data.Newtype (unwrap)
import Data.String (joinWith)
import Data.String (joinWith)
import Effect.Aff (Aff, throwError)
import Effect.Aff (Aff, throwError)
import Effect.Exception (error)
import Effect.Exception (error)
import Thermite (Render, Spec, defaultPerformAction, simpleSpec
, createClass
)
import Thermite (Render, Spec, defaultPerformAction, simpleSpec)
import React as React
import React as React
import React (ReactClass, ReactElement)
import React (ReactClass, ReactElement)
import React.DOM (div, h3, img, li, span, text, ul, text)
import React.DOM (div, h3, img, li, span, text, ul, text)
import React.DOM.Props (_id, className, src)
import React.DOM.Props (_id, className, src)
import Reactix as R
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Config (toUrl, End(..), NodeType(..), Path(..))
import Gargantext.Config (toUrl, End(..), NodeType(..), Path(..))
import Gargantext.Config.REST (get)
import Gargantext.Config.REST (get)
import Gargantext.Components.Node (NodePoly(..), HyperdataList(..))
import Gargantext.Components.Node (NodePoly(..), HyperdataList(..))
import Gargantext.Components.Loader
as Loader
import Gargantext.Components.Loader
2 (useLoader)
import Gargantext.Pages.Annuaire.User.Contacts.Types
import Gargantext.Pages.Annuaire.User.Contacts.Types
import Gargantext.Pages.Annuaire.User.Contacts.Tabs.Specs as Tabs
import Gargantext.Pages.Annuaire.User.Contacts.Tabs.Specs as Tabs
import Gargantext.Utils.Reactix as R2
--type Props = Loader.InnerProps Int Contact
display :: String -> Array ReactElement -> Array ReactElement
display :: String -> Array ReactElement -> Array ReactElement
display title elems =
display title elems =
...
@@ -153,30 +153,16 @@ infoRender (Tuple title content) =
...
@@ -153,30 +153,16 @@ infoRender (Tuple title content) =
-- | Below an example of a loader, use all code below and adapt it
-- | Below an example of a loader, use all code below and adapt it
-- to your code
-- to your code
-- layoutUser is exported by the module
-- layoutUser is exported by the module
-- only one subnode: contactLoader which as 2 parameters
-- - path (nodeId)
-- - components (which has to be drawn when loaded
layoutUser :: Spec {} {nodeId :: Int} Void
layoutUser :: Spec {} {nodeId :: Int} Void
layoutUser = simpleSpec defaultPerformAction render
layoutUser =
where
R2.elSpec $ R.hooksComponent "LayoutUser" \{nodeId} _ ->
render :: Render {} {nodeId :: Int} Void
useLoader nodeId getContact $ \{loaded: contactData} ->
render _ {nodeId} _ _ =
let {contactNode: Contact {name, hyperdata}} = contactData in
[ contactLoader { path: nodeId
R2.toElement
, component: createClass "LayoutUser" layoutUser' (const {})
[ ul [className "col-md-12 list-group"] $
} ]
display (fromMaybe "no name" name) (contactInfos hyperdata)
, Tabs.elt {nodeId, contactData}
-- | Take the spec and transform it in React Class
]
-- put here how to draw the Composant
-- props loaded: what has been loaded by the component loader
layoutUser' :: Spec {} Props Void
layoutUser' = simpleSpec defaultPerformAction render
<> Tabs.pureTabs
where
render :: Render {} Props Void
render dispatch {loaded: {contactNode: Contact {name, hyperdata}}} _ _ =
[ ul [className "col-md-12 list-group"] $
display (fromMaybe "no name" name) (contactInfos hyperdata)
]
-- | toUrl to get data
-- | toUrl to get data
getContact :: Int -> Aff ContactData
getContact :: Int -> Aff ContactData
...
@@ -190,11 +176,3 @@ getContact id = do
...
@@ -190,11 +176,3 @@ getContact id = do
-- Nothing ->
-- Nothing ->
-- throwError $ error "Missing default list"
-- throwError $ error "Missing default list"
pure {contactNode, defaultListId: 424242}
pure {contactNode, defaultListId: 424242}
-- | Change name for you
contactLoaderClass :: ReactClass (Loader.Props Int ContactData)
contactLoaderClass = Loader.createLoaderClass "ContactLoader" getContact
-- | Change type according to what has been loaded
contactLoader :: Loader.Props' Int ContactData -> ReactElement
contactLoader props = React.createElement contactLoaderClass props []
src/Gargantext/Pages/Annuaire/User/Contacts/Tabs/Specs.purs
View file @
864e0235
...
@@ -13,8 +13,10 @@ import Gargantext.Config (TabType(..), TabSubType(..), PTabNgramType(..))
...
@@ -13,8 +13,10 @@ import Gargantext.Config (TabType(..), TabSubType(..), PTabNgramType(..))
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Tab as Tab
import Gargantext.Pages.Annuaire.User.Contacts.Types (Props)
import Gargantext.Pages.Annuaire.User.Contacts.Types (ContactData)
import Thermite (Spec, focus, hideState, noState, cmapProps)
import React (Children, ReactElement, ReactClass, createElement)
import Thermite (Spec, focus, hideState, noState, cmapProps, createClass)
data Mode = Patents | Books | Communication
data Mode = Patents | Books | Communication
...
@@ -30,6 +32,19 @@ modeTabType Patents = PTabPatents
...
@@ -30,6 +32,19 @@ modeTabType Patents = PTabPatents
modeTabType Books = PTabBooks
modeTabType Books = PTabBooks
modeTabType Communication = PTabCommunication
modeTabType Communication = PTabCommunication
type PropsRow =
( nodeId :: Int
, contactData :: ContactData
)
type Props = Record PropsRow
elt :: Props -> ReactElement
elt props = createElement tabsClass props []
tabsClass :: ReactClass { children :: Children | PropsRow }
tabsClass = createClass "ContactsTabs" pureTabs (const {})
pureTabs :: Spec {} Props Void
pureTabs :: Spec {} Props Void
pureTabs = hideState (const {activeTab: 0}) statefulTabs
pureTabs = hideState (const {activeTab: 0}) statefulTabs
...
@@ -45,18 +60,18 @@ statefulTabs =
...
@@ -45,18 +60,18 @@ statefulTabs =
where
where
chart = mempty
chart = mempty
-- TODO totalRecords
-- TODO totalRecords
docs = cmapProps (\{
path: nodeId, loaded
} ->
docs = cmapProps (\{
nodeId, contactData: {defaultListId}
} ->
{ nodeId, chart
{ nodeId, chart
, tabType: TabPairing TabDocs
, tabType: TabPairing TabDocs
, totalRecords: 4736
, totalRecords: 4736
, listId:
loaded.
defaultListId
, listId: defaultListId
, corpusId: Nothing}) $
, corpusId: Nothing}) $
noState DT.docViewSpec
noState DT.docViewSpec
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
ngramsViewSpec {mode} =
ngramsViewSpec {mode} =
cmapProps (\{
loaded: {defaultListId}, path, dispatch
} ->
cmapProps (\{
contactData: {defaultListId}, nodeId
} ->
{
loaded: {defaultListId}, path, dispatch
, tabType})
{
defaultListId, nodeId
, tabType})
(noState NT.mainNgramsTableSpec)
(noState NT.mainNgramsTableSpec)
where
where
tabType = TabPairing $ TabNgramType $ modeTabType mode
tabType = TabPairing $ TabNgramType $ modeTabType mode
src/Gargantext/Pages/Annuaire/User/Contacts/Types.purs
View file @
864e0235
...
@@ -162,13 +162,9 @@ instance decodeUser :: DecodeJson Contact where
...
@@ -162,13 +162,9 @@ instance decodeUser :: DecodeJson Contact where
name <- obj .?? "name"
name <- obj .?? "name"
date <- obj .?| "date"
date <- obj .?| "date"
hyperdata <- obj .? "hyperdata"
hyperdata <- obj .? "hyperdata"
pure $ Contact { id, typename, userId
pure $ Contact { id, typename, userId
, parentId, name, date
, parentId, name, date
, hyperdata
, hyperdata
}
}
type ContactData = {contactNode :: Contact, defaultListId :: Int}
type ContactData = {contactNode :: Contact, defaultListId :: Int}
type PropsRow = Loader.InnerPropsRow Int ContactData ()
type Props = Record PropsRow
src/Gargantext/Pages/Corpus.purs
View file @
864e0235
module Gargantext.Pages.Corpus where
module Gargantext.Pages.Corpus where
import Data.Array (head)
import Data.Array (head)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff, throwError)
import Effect.Aff (Aff, throwError)
import Effect.Exception (error)
import Effect.Exception (error)
import React as React
import Reactix as R
import React (ReactClass, ReactElement)
import Thermite (Spec)
import Thermite (Spec, Render, simpleSpec, createClass, defaultPerformAction)
--------------------------------------------------------
--------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..), HyperdataList(..))
import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Loader as Loader
import Gargantext.Components.Loader2 (useLoader)
import Gargantext.Components.Loader (createLoaderClass)
import Gargantext.Components.Table as Table
import Gargantext.Components.Table as Table
import Gargantext.Config (toUrl, Path(..), NodeType(..), End(..))
import Gargantext.Config (toUrl, Path(..), NodeType(..), End(..))
import Gargantext.Config.REST (get)
import Gargantext.Config.REST (get)
import Gargantext.Pages.Corpus.Tabs.Types (CorpusData, CorpusInfo(..))
import Gargantext.Pages.Corpus.Tabs.Types (CorpusData, CorpusInfo(..))
import Gargantext.Pages.Corpus.Tabs.Types (Props) as Tabs
import Gargantext.Pages.Corpus.Tabs.Specs (elt) as Tabs
import Gargantext.Pages.Corpus.Tabs.Specs (pureTabs) as Tabs
import Gargantext.Utils.Reactix as R2
-------------------------------------------------------------------
type Props = Tabs.Props
------------------------------------------------------------------------
------------------------------------------------------------------------
layout :: Spec {} {nodeId :: Int} Void
layout :: Spec {} {nodeId :: Int} Void
layout = simpleSpec defaultPerformAction render
layout =
where
R2.elSpec $ R.hooksComponent "CorpusLoader" \{nodeId} _ ->
render :: Render {} {nodeId :: Int} Void
useLoader nodeId getCorpus $ \{path: corpusId
render _ {nodeId} _ _ =
,loaded: corpusData} ->
[ corpusLoader { path: nodeId
let {corpusNode:
, component: createClass "Layout" layout' (const {})
NodePoly { name: title
} ]
, date: date'
, hyperdata: CorpusInfo corpus
layout' :: Spec {} Props Void
}
layout' = corpusHeaderSpec <> Tabs.pureTabs
} = corpusData in
R2.toElement $
corpusHeaderSpec :: Spec {} Props Void
Table.renderTableHeaderLayout
corpusHeaderSpec = simpleSpec defaultPerformAction render
{ title: "Corpus " <> title
where
, desc: corpus.desc
render :: Render {} Props Void
, query: corpus.query
render dispatch {loaded: {corpusNode}} _ _ =
, date: date'
Table.renderTableHeaderLayout
, user: corpus.authors
{ title: "Corpus " <> title
}
, desc: corpus.desc
<> [Tabs.elt {corpusId, corpusData}]
, query: corpus.query
, date: date'
, user: corpus.authors
}
where
NodePoly { name: title
, date: date'
, hyperdata : CorpusInfo corpus
}
= corpusNode
------------------------------------------------------------------------
------------------------------------------------------------------------
getCorpus :: Int -> Aff CorpusData
getCorpus :: Int -> Aff CorpusData
...
@@ -65,9 +49,3 @@ getCorpus corpusId = do
...
@@ -65,9 +49,3 @@ getCorpus corpusId = do
pure {corpusNode, defaultListId}
pure {corpusNode, defaultListId}
Nothing ->
Nothing ->
throwError $ error "Missing default list"
throwError $ error "Missing default list"
corpusLoaderClass :: ReactClass (Loader.Props Int CorpusData)
corpusLoaderClass = createLoaderClass "CorpusLoader" getCorpus
corpusLoader :: Loader.Props' Int CorpusData -> ReactElement
corpusLoader props = React.createElement corpusLoaderClass props []
src/Gargantext/Pages/Corpus/Document.purs
View file @
864e0235
...
@@ -6,23 +6,23 @@ import Data.Generic.Rep.Show (genericShow)
...
@@ -6,23 +6,23 @@ import Data.Generic.Rep.Show (genericShow)
import Data.Map as Map
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe(..), maybe)
import Effect.Aff (Aff)
import Effect.Aff (Aff)
import React (ReactElement, ReactClass)
import React (ReactClass, Children)
import React as React
import React.DOM (div, h4, li, p, span, text, ul)
import React.DOM (div, h4, li, p, span, text, ul)
import React.DOM.Props (className)
import React.DOM.Props (className)
import Thermite (PerformAction, Render, Spec, simpleSpec, cmapProps, defaultPerformAction, createClass)
import Reactix as R
import Thermite (PerformAction, Render, Spec, simpleSpec, cmapProps, createClass)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Class (lift)
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Config (toUrl, NodeType(..), End(..), TabSubType(..), TabType(..), CTabNgramType(..))
import Gargantext.Config (toUrl, NodeType(..), End(..), TabSubType(..), TabType(..), CTabNgramType(..))
import Gargantext.Config.REST (get)
import Gargantext.Config.REST (get)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.Loader
as Loader
import Gargantext.Components.Loader
2 (useLoader)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField
import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField
import Gargantext.Types (TermList)
import Gargantext.Types (TermList)
import Gargantext.Utils.Reactix
( scuff )
import Gargantext.Utils.Reactix
as R2
type DocPath = { nodeId :: Int, listIds :: Array Int, corpusId :: Maybe Int, tabType :: TabType }
type DocPath = { nodeId :: Int, listIds :: Array Int, corpusId :: Maybe Int, tabType :: TabType }
...
@@ -32,7 +32,10 @@ type LoadedData =
...
@@ -32,7 +32,10 @@ type LoadedData =
{ document :: NodeDocument
{ document :: NodeDocument
, ngramsTable :: VersionedNgramsTable }
, ngramsTable :: VersionedNgramsTable }
type LoadedDataProps = Loader.InnerProps DocPath LoadedData ()
type Props =
{ loaded :: LoadedData
, path :: DocPath
}
-- This is a subpart of NgramsTable.State.
-- This is a subpart of NgramsTable.State.
type State = CoreState ()
type State = CoreState ()
...
@@ -273,10 +276,10 @@ instance decodeDocument :: DecodeJson Document
...
@@ -273,10 +276,10 @@ instance decodeDocument :: DecodeJson Document
--, text
--, text
}
}
docViewSpec :: Spec State
LoadedData
Props Action
docViewSpec :: Spec State Props Action
docViewSpec = simpleSpec performAction render
docViewSpec = simpleSpec performAction render
where
where
performAction :: PerformAction State
LoadedData
Props Action
performAction :: PerformAction State Props Action
performAction Refresh {path: {nodeId, listIds, tabType}} {ngramsVersion} = do
performAction Refresh {path: {nodeId, listIds, tabType}} {ngramsVersion} = do
commitPatch {nodeId, listIds, tabType} (Versioned {version: ngramsVersion, data: mempty})
commitPatch {nodeId, listIds, tabType} (Versioned {version: ngramsVersion, data: mempty})
performAction (SetTermListItem n pl) {path: {nodeId, listIds, tabType}} {ngramsVersion} =
performAction (SetTermListItem n pl) {path: {nodeId, listIds, tabType}} {ngramsVersion} =
...
@@ -287,10 +290,8 @@ docViewSpec = simpleSpec performAction render
...
@@ -287,10 +290,8 @@ docViewSpec = simpleSpec performAction render
performAction (AddNewNgram ngram termList) {path: params} _ =
performAction (AddNewNgram ngram termList) {path: params} _ =
lift $ addNewNgram ngram (Just termList) params
lift $ addNewNgram ngram (Just termList) params
render :: Render State LoadedDataProps Action
render :: Render State Props Action
render dispatch { path: pageParams
render dispatch { loaded: { ngramsTable: Versioned { data: initTable }, document } }
, loaded: { ngramsTable: Versioned { data: initTable }, document }
, dispatch: loaderDispatch }
{ ngramsTablePatch }
{ ngramsTablePatch }
_reactChildren =
_reactChildren =
[ autoUpdateElt { duration: 3000
[ autoUpdateElt { duration: 3000
...
@@ -327,23 +328,27 @@ docViewSpec = simpleSpec performAction render
...
@@ -327,23 +328,27 @@ docViewSpec = simpleSpec performAction render
ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable
ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable
setTermList ngram Nothing newList = dispatch $ AddNewNgram ngram newList
setTermList ngram Nothing newList = dispatch $ AddNewNgram ngram newList
setTermList ngram (Just oldList) newList = dispatch $ SetTermListItem ngram (replace oldList newList)
setTermList ngram (Just oldList) newList = dispatch $ SetTermListItem ngram (replace oldList newList)
annotate text = scuff $ AnnotatedField.annotatedField { ngrams: ngramsTable, setTermList, text }
annotate text =
R2.
scuff $ AnnotatedField.annotatedField { ngrams: ngramsTable, setTermList, text }
li' = li [className "list-group-item justify-content-between"]
li' = li [className "list-group-item justify-content-between"]
text' x = text $ maybe "Nothing" identity x
text' x = text $ maybe "Nothing" identity x
badge s = span [className "badge badge-default badge-pill"] [text s]
badge s = span [className "badge badge-default badge-pill"] [text s]
NodePoly {hyperdata : Document doc} = document
NodePoly {hyperdata : Document doc} = document
docViewClass :: ReactClass
{ children :: Children
, loaded :: LoadedData
, path :: DocPath
}
docViewClass = createClass "DocumentView" docViewSpec initialState
layout :: Spec {} {nodeId :: Int, listId :: Int, corpusId :: Maybe Int} Void
layout :: Spec {} {nodeId :: Int, listId :: Int, corpusId :: Maybe Int} Void
layout = cmapProps (\{nodeId, listId, corpusId} -> {nodeId, listIds: [listId], corpusId, tabType})
layout =
$ simpleSpec defaultPerformAction render
cmapProps (\{nodeId, listId, corpusId} -> {nodeId, listIds: [listId], corpusId, tabType}) $
R2.elSpec $ R.hooksComponent "DocumentLoader" \path _ ->
useLoader path loadData $ \props ->
R2.createElement' docViewClass props []
where
where
tabType = TabDocument (TabNgramType CTabTerms)
tabType = TabDocument (TabNgramType CTabTerms)
render :: Render {} DocPath Void
render _ path _ _ =
[ documentLoader
{ path
, component: createClass "DocumentView" docViewSpec initialState
} ]
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -363,9 +368,3 @@ loadData {nodeId, listIds, tabType} = do
...
@@ -363,9 +368,3 @@ loadData {nodeId, listIds, tabType} = do
, termSizeFilter : Nothing
, termSizeFilter : Nothing
}
}
pure {document, ngramsTable}
pure {document, ngramsTable}
documentLoaderClass :: ReactClass (Loader.Props DocPath LoadedData)
documentLoaderClass = Loader.createLoaderClass "DocumentLoader" loadData
documentLoader :: Loader.Props' DocPath LoadedData -> ReactElement
documentLoader props = React.createElement documentLoaderClass props []
src/Gargantext/Pages/Corpus/Tabs/Specs.purs
View file @
864e0235
...
@@ -9,7 +9,7 @@ import Data.Maybe (Maybe(..))
...
@@ -9,7 +9,7 @@ import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
import Gargantext.Config (CTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Config (CTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Pages.Corpus.Tabs.Types (Props)
import Gargantext.Pages.Corpus.Tabs.Types (Props
, PropsRow
)
import Gargantext.Pages.Corpus.Chart.Histo (histoSpec)
import Gargantext.Pages.Corpus.Chart.Histo (histoSpec)
import Gargantext.Pages.Corpus.Chart.Metrics (metricsSpec)
import Gargantext.Pages.Corpus.Chart.Metrics (metricsSpec)
...
@@ -21,10 +21,11 @@ import Gargantext.Components.NgramsTable as NT
...
@@ -21,10 +21,11 @@ import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Charts.Options.ECharts (chart) as ECharts
import Gargantext.Components.Charts.Options.ECharts (chart) as ECharts
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Tab as Tab
import Gargantext.Utils.Reactix as R2
import React (ReactElement)
import React (ReactElement
, ReactClass, createElement, Children
)
import React.DOM (div)
import React.DOM (div)
import Thermite (Spec, hideState, noState, cmapProps)
import Thermite (Spec, hideState, noState, cmapProps
, createClass
)
data Mode = Authors | Sources | Institutes | Terms
data Mode = Authors | Sources | Institutes | Terms
...
@@ -41,6 +42,12 @@ modeTabType Sources = CTabSources
...
@@ -41,6 +42,12 @@ modeTabType Sources = CTabSources
modeTabType Institutes = CTabInstitutes
modeTabType Institutes = CTabInstitutes
modeTabType Terms = CTabTerms
modeTabType Terms = CTabTerms
elt :: Props -> ReactElement
elt props = createElement tabsClass props []
tabsClass :: ReactClass { children :: Children | PropsRow }
tabsClass = createClass "CorpusTabs" pureTabs (const {})
pureTabs :: Spec {} Props Void
pureTabs :: Spec {} Props Void
pureTabs = hideState (const {activeTab: 0}) statefulTabs
pureTabs = hideState (const {activeTab: 0}) statefulTabs
...
@@ -58,43 +65,44 @@ statefulTabs =
...
@@ -58,43 +65,44 @@ statefulTabs =
where
where
-- TODO totalRecords
-- TODO totalRecords
docs = noState ( cmapProps (\{
path:
corpusId} -> {corpusId, tabType: TabCorpus TabDocs}) histoSpec
docs = noState ( cmapProps (\{corpusId} -> {corpusId, tabType: TabCorpus TabDocs}) histoSpec
<>
<>
(cmapProps (\{path: nodeId, loaded} ->
(cmapProps (\{corpusId, corpusData: {defaultListId}} ->
{ nodeId
{ nodeId: corpusId
-- ^ TODO merge nodeId and corpusId in DT
, chart : div [][]
, chart : div [][]
, tabType: TabCorpus TabDocs
, tabType: TabCorpus TabDocs
, totalRecords: 4737
, totalRecords: 4737
, listId:
loaded.
defaultListId
, listId: defaultListId
, corpusId: Just
node
Id}) $ noState DT.docViewSpec
, corpusId: Just
corpus
Id}) $ noState DT.docViewSpec
)
)
)
)
trash = cmapProps (\{
path: nodeId, loaded
} ->
trash = cmapProps (\{
corpusId, corpusData: {defaultListId}
} ->
{ nodeId
{ nodeId
: corpusId
, chart: div [][]
, chart: div [][]
, tabType: TabCorpus TabTrash
, tabType: TabCorpus TabTrash
, totalRecords: 4736
, totalRecords: 4736
, listId:
loaded.
defaultListId
, listId: defaultListId
, corpusId: Nothing}) $ noState DT.docViewSpec
, corpusId: Nothing}) $ noState DT.docViewSpec
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
ngramsViewSpec {mode} =
ngramsViewSpec {mode} =
noState
( (chart mode)
<>
noState
$ chart mode
<>
cmapProps (\{
loaded: {defaultListId}, path, dispatch
} ->
cmapProps (\{
corpusData: {defaultListId}, corpusId: nodeId
} ->
{
loaded: {defaultListId}, path, dispatch
, tabType})
{
defaultListId, nodeId
, tabType})
NT.mainNgramsTableSpec
NT.mainNgramsTableSpec
)
where
where
tabType = TabCorpus $ TabNgramType $ modeTabType mode
tabType = TabCorpus $ TabNgramType $ modeTabType mode
chart Authors = cmapProps (\{
path:
corpusId} -> {corpusId, tabType}) pieSpec
chart Authors = cmapProps (\{corpusId} -> {corpusId, tabType}) pieSpec
chart Sources = cmapProps (\{
path:
corpusId} -> {corpusId, tabType}) barSpec
chart Sources = cmapProps (\{corpusId} -> {corpusId, tabType}) barSpec
chart Institutes = cmapProps (\{
loaded: {defaultListId}, path:
corpusId} ->
chart Institutes = cmapProps (\{
corpusData: {defaultListId},
corpusId} ->
{corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
{corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
treeSpec
treeSpec
chart Terms = cmapProps (\{
loaded: {defaultListId}, path:
corpusId} ->
chart Terms = cmapProps (\{
corpusData: {defaultListId},
corpusId} ->
{corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
{corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
-- TODO limit should be select in the chart by default it is 1000
-- TODO limit should be select in the chart by default it is 1000
metricsSpec
metricsSpec
src/Gargantext/Pages/Corpus/Tabs/Types.purs
View file @
864e0235
...
@@ -45,8 +45,7 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
...
@@ -45,8 +45,7 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
type CorpusData = {corpusNode :: NodePoly CorpusInfo, defaultListId :: Int}
type CorpusData = {corpusNode :: NodePoly CorpusInfo, defaultListId :: Int}
-- TODO type Props = {nodeId :: Int, info :: Maybe (NodePoly CorpusInfo) }
type PropsRow = ( corpusId :: Int, corpusData :: CorpusData )
type PropsRow = Loader.InnerPropsRow Int CorpusData ()
type Props = Record PropsRow
type Props = Record PropsRow
-- TODO include Gargantext.Pages.Corpus.Tabs.States
-- TODO include Gargantext.Pages.Corpus.Tabs.States
...
...
src/Gargantext/Utils/Reactix.purs
View file @
864e0235
...
@@ -12,7 +12,8 @@ import Data.Tuple.Nested ((/\))
...
@@ -12,7 +12,8 @@ import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect (Effect)
import Effect.Uncurried (EffectFn1, mkEffectFn1)
import Effect.Uncurried (EffectFn1, mkEffectFn1)
import FFI.Simple ((...), defineProperty)
import FFI.Simple ((...), defineProperty)
import React (ReactElement)
import React (ReactClass, ReactElement, Children, class IsReactElement, class ReactPropFields)
import React as React
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML (ElemFactory)
import Reactix.DOM.HTML (ElemFactory)
import Reactix.React (createDOMElement)
import Reactix.React (createDOMElement)
...
@@ -21,7 +22,7 @@ import Thermite (Spec, simpleSpec, Render, defaultPerformAction)
...
@@ -21,7 +22,7 @@ import Thermite (Spec, simpleSpec, Render, defaultPerformAction)
import Unsafe.Coerce (unsafeCoerce)
import Unsafe.Coerce (unsafeCoerce)
newtype Point = Point { x :: Number, y :: Number }
newtype Point = Point { x :: Number, y :: Number }
-- | Turns a ReactElement into a
Reactix Element
-- | Turns a ReactElement into aReactix Element
-- | buff (v.) to polish
-- | buff (v.) to polish
buff :: ReactElement -> R.Element
buff :: ReactElement -> R.Element
buff = unsafeCoerce
buff = unsafeCoerce
...
@@ -31,6 +32,23 @@ buff = unsafeCoerce
...
@@ -31,6 +32,23 @@ buff = unsafeCoerce
scuff :: R.Element -> ReactElement
scuff :: R.Element -> ReactElement
scuff = unsafeCoerce
scuff = unsafeCoerce
class ToElement a where
toElement :: a -> R.Element
instance toElementElement :: ToElement R.Element where
toElement = identity
instance toElementReactElement :: ToElement ReactElement where
toElement = buff
instance toElementArray :: ToElement a => ToElement (Array a) where
toElement = R.fragment <<< map toElement
{-
instance isReactElementElement :: IsReactElement R.Element where
toElement = scuff
-}
elSpec :: forall component props
elSpec :: forall component props
. R.IsComponent component props (Array R.Element)
. R.IsComponent component props (Array R.Element)
=> component -> Spec {} (Record props) Void
=> component -> Spec {} (Record props) Void
...
@@ -39,6 +57,22 @@ elSpec cpt = simpleSpec defaultPerformAction render
...
@@ -39,6 +57,22 @@ elSpec cpt = simpleSpec defaultPerformAction render
render :: Render {} (Record props) Void
render :: Render {} (Record props) Void
render _ props _ children = [scuff $ R.createElement cpt props (buff <$> children)]
render _ props _ children = [scuff $ R.createElement cpt props (buff <$> children)]
createElement' :: forall required given
. ReactPropFields required given
=> ReactClass { children :: Children | required }
-> Record given -> Array R.Element -> R.Element
createElement' reactClass props children =
buff $ React.createElement reactClass props $ scuff <$> children
{-
instance isComponentReactClass
:: R.IsComponent (ReactClass { children :: Children
| props
}) props (Array R.Element) where
createElement reactClass props children =
React.createElement reactClass props children
-}
mousePosition :: RE.SyntheticEvent DE.MouseEvent -> Point
mousePosition :: RE.SyntheticEvent DE.MouseEvent -> Point
mousePosition e = Point { x: RE.clientX e, y: RE.clientY e }
mousePosition e = Point { x: RE.clientX e, y: RE.clientY e }
...
...
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