[NGRAMS-TABLE] refactor support for filtering

parent 733b0f61
module Gargantext.Components.NgramsTable module Gargantext.Components.NgramsTable
( Props ( PageParams
, PageParams
, PatchMap , PatchMap
, NgramsPatch , NgramsPatch
, NgramsTable , NgramsTable
...@@ -11,6 +10,11 @@ module Gargantext.Components.NgramsTable ...@@ -11,6 +10,11 @@ module Gargantext.Components.NgramsTable
, initialPageParams , initialPageParams
, initialState , initialState
, ngramsTableSpec , ngramsTableSpec
, ngramsLoaderClass
, ngramsLoader
, ngramsTableClass
, MainNgramsTableProps
, mainNgramsTableSpec
) )
where where
...@@ -45,22 +49,21 @@ import Effect (Effect) ...@@ -45,22 +49,21 @@ import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Foreign.Object as FO import Foreign.Object as FO
import React (ReactElement) import React (ReactElement)
import React as React
import React.DOM (a, button, div, h2, i, input, li, option, p, select, span, table, tbody, text, thead, ul) import React.DOM (a, button, div, h2, i, input, li, option, p, select, span, table, tbody, text, thead, ul)
import React.DOM.Props (_id, _type, checked, className, name, onChange, onClick, onInput, placeholder, style, value) import React.DOM.Props (_id, _type, checked, className, name, onChange, onClick, onInput, placeholder, style, value)
import React.DOM.Props as DOM import React.DOM.Props as DOM
import Thermite (PerformAction, Render, Spec, StateCoTransformer, modifyState_, simpleSpec) import Thermite (PerformAction, Render, Spec, StateCoTransformer, defaultPerformAction, modifyState_, simpleSpec, createClass)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (TermList(..), TermType, readTermList, readTermType, termLists, termTypes) import Gargantext.Types (TermList(..), TermType, readTermList, readTermType, termLists, termTypes)
import Gargantext.Config (toUrl, End(..), Path(..), TabType) import Gargantext.Config (toUrl, End(..), Path(..), TabType(..), OrderBy(..))
import Gargantext.Config.REST (put) import Gargantext.Config.REST (get, put)
import Gargantext.Components.AutoUpdate (autoUpdateElt) import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.Loader as Loader import Gargantext.Components.Loader as Loader
type Props a mode = Loader.InnerProps Int a ( mode :: mode )
type PageParams = type PageParams =
{ nodeId :: Int { nodeId :: Int
, listIds :: Array Int , listIds :: Array Int
...@@ -617,6 +620,42 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -617,6 +620,42 @@ ngramsTableSpec = simpleSpec performAction render
, delete: false , delete: false
} }
loadPage :: PageParams -> Aff VersionedNgramsTable
loadPage { nodeId, listIds, termListFilter, termTypeFilter
, searchQuery, tabType, params: {offset, limit, orderBy}} =
get $ toUrl Back
(GetNgrams { tabType, offset, limit, listIds
, orderBy: convOrderBy <$> orderBy
, termListFilter, termTypeFilter
, searchQuery
})
(Just nodeId)
where
convOrderBy _ = DateAsc -- TODO
ngramsLoaderClass :: Loader.LoaderClass PageParams VersionedNgramsTable
ngramsLoaderClass = Loader.createLoaderClass "NgramsTableLoader" loadPage
ngramsLoader :: Loader.Props' PageParams VersionedNgramsTable -> ReactElement
ngramsLoader props = React.createElement ngramsLoaderClass props []
ngramsTableClass :: Loader.InnerClass PageParams VersionedNgramsTable
ngramsTableClass = createClass "NgramsTable" ngramsTableSpec initialState
type MainNgramsTableProps =
Loader.InnerProps Int { defaultListId :: Int }
( tabType :: TabType )
mainNgramsTableSpec :: Spec {} MainNgramsTableProps Void
mainNgramsTableSpec = simpleSpec defaultPerformAction render
where
render :: Render {} MainNgramsTableProps Void
render _ {path: nodeId, loaded: {defaultListId}, tabType} _ _ =
[ ngramsLoader
{ path: initialPageParams nodeId [defaultListId] tabType
, component: ngramsTableClass
} ]
tree :: { ngramsTable :: NgramsTable tree :: { ngramsTable :: NgramsTable
, ngramsStyle :: Array DOM.Props , ngramsStyle :: Array DOM.Props
, ngramsClick :: NgramsTerm -> Maybe (Effect Unit) , ngramsClick :: NgramsTerm -> Maybe (Effect Unit)
......
...@@ -14,15 +14,17 @@ import Data.Unfoldable (class Unfoldable) ...@@ -14,15 +14,17 @@ import Data.Unfoldable (class Unfoldable)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap) import Data.Newtype (unwrap)
import Data.String (joinWith) import Data.String (joinWith)
import Effect.Aff (Aff) import Effect.Aff (Aff, throwError)
import Effect.Exception (error)
import Thermite (Render, Spec, defaultPerformAction, simpleSpec, createClass) import Thermite (Render, Spec, defaultPerformAction, simpleSpec, createClass)
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 Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Config (toUrl, End(..), NodeType(..)) 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.Loader as Loader import Gargantext.Components.Loader as Loader
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
...@@ -171,19 +173,26 @@ layoutUser' = simpleSpec defaultPerformAction render ...@@ -171,19 +173,26 @@ layoutUser' = simpleSpec defaultPerformAction render
<> Tabs.pureTabs <> Tabs.pureTabs
where where
render :: Render {} Props Void render :: Render {} Props Void
render dispatch {loaded: Contact {name, hyperdata}} _ _ = render dispatch {loaded: {contactNode: Contact {name, hyperdata}}} _ _ =
[ ul [className "col-md-12 list-group"] $ [ ul [className "col-md-12 list-group"] $
display (fromMaybe "no name" name) (contactInfos hyperdata) display (fromMaybe "no name" name) (contactInfos hyperdata)
] ]
-- | toUrl to get data -- | toUrl to get data
getContact :: Int -> Aff Contact getContact :: Int -> Aff ContactData
getContact id = get $ toUrl Back Node $ Just id getContact id = do
contactNode <- get $ toUrl Back Node $ Just id
defaultListIds <- get $ toUrl Back (Children NodeList 0 1 Nothing) $ Just id
case (head defaultListIds :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) ->
pure {contactNode, defaultListId}
Nothing ->
throwError $ error "Missing default list"
-- | Change name for you -- | Change name for you
contactLoaderClass :: ReactClass (Loader.Props Int Contact) contactLoaderClass :: ReactClass (Loader.Props Int ContactData)
contactLoaderClass = Loader.createLoaderClass "ContactLoader" getContact contactLoaderClass = Loader.createLoaderClass "ContactLoader" getContact
-- | Change type according to what has been loaded -- | Change type according to what has been loaded
contactLoader :: Loader.Props' Int Contact -> ReactElement contactLoader :: Loader.Props' Int ContactData -> ReactElement
contactLoader props = React.createElement contactLoaderClass props [] contactLoader props = React.createElement contactLoaderClass props []
-- TODO copy of Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable where
module Gargantext.Pages.Annuaire.User.Contacts.Tabs.Ngrams.NgramsTable
(Mode(..), ngramsTableSpec)
where
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import React (ReactElement)
import React as React
import Thermite (Render, Spec, createClass, defaultPerformAction, simpleSpec)
import Gargantext.Components.NgramsTable as NT
import Gargantext.Prelude
import Gargantext.Config (PTabNgramType(..), Offset, Limit, OrderBy(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Config.REST (get)
import Gargantext.Components.Loader as Loader
import Gargantext.Pages.Annuaire.User.Contacts.Types (Contact)
data Mode = Patents | Books | Communication
derive instance genericMode :: Generic Mode _
instance showMode :: Show Mode where
show = genericShow
derive instance eqMode :: Eq Mode
modeTabType :: Mode -> PTabNgramType
modeTabType Patents = PTabPatents
modeTabType Books = PTabBooks
modeTabType Communication = PTabCommunication
type Props = NT.Props Contact Mode
-- TODO: Move to Components.NgramsTable?
loadPage :: NT.PageParams -> Aff NT.VersionedNgramsTable
loadPage { nodeId, listIds, termListFilter, termTypeFilter
, searchQuery, tabType, params: {offset, limit, orderBy}} =
get $ toUrl Back
(GetNgrams { tabType, offset, limit, listIds
, orderBy: convOrderBy <$> orderBy
, termListFilter, termTypeFilter
, searchQuery
})
(Just nodeId)
where
convOrderBy _ = DateAsc -- TODO
-- TODO: Move to Components.NgramsTable?
ngramsLoaderClass :: Loader.LoaderClass NT.PageParams NT.VersionedNgramsTable
ngramsLoaderClass = Loader.createLoaderClass "ContactsNgramsLoader" loadPage
-- TODO: Move to Components.NgramsTable?
ngramsLoader :: Loader.Props' NT.PageParams NT.VersionedNgramsTable -> ReactElement
ngramsLoader props = React.createElement ngramsLoaderClass props []
-- TODO: Move to Components.NgramsTable?
ngramsTableClass :: Loader.InnerClass NT.PageParams NT.VersionedNgramsTable
ngramsTableClass = createClass "ContactsNgramsTable" NT.ngramsTableSpec NT.initialState
ngramsTableSpec :: Spec {} Props Void
ngramsTableSpec = simpleSpec defaultPerformAction render
where
render :: Render {} Props Void
render _ {path: nodeId, mode} _ _ =
-- TODO: ignored loaded
[ ngramsLoader { path: NT.initialPageParams nodeId [] tabType
, component: ngramsTableClass
} ]
where
tabType = TabPairing $ TabNgramType $ modeTabType mode
...@@ -3,16 +3,32 @@ module Gargantext.Pages.Annuaire.User.Contacts.Tabs.Specs where ...@@ -3,16 +3,32 @@ module Gargantext.Pages.Annuaire.User.Contacts.Tabs.Specs where
import Prelude hiding (div) import Prelude hiding (div)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.List (fromFoldable) import Data.List (fromFoldable)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Config (TabType(..), TabSubType(..)) 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.Tab as Tab import Gargantext.Components.Tab as Tab
import Gargantext.Pages.Annuaire.User.Contacts.Types (Props) import Gargantext.Pages.Annuaire.User.Contacts.Types (Props)
import Gargantext.Pages.Annuaire.User.Contacts.Tabs.Ngrams.NgramsTable as NV
import Thermite (Spec, focus, hideState, noState, cmapProps) import Thermite (Spec, focus, hideState, noState, cmapProps)
data Mode = Patents | Books | Communication
derive instance genericMode :: Generic Mode _
instance showMode :: Show Mode where
show = genericShow
derive instance eqMode :: Eq Mode
modeTabType :: Mode -> PTabNgramType
modeTabType Patents = PTabPatents
modeTabType Books = PTabBooks
modeTabType Communication = PTabCommunication
pureTabs :: Spec {} Props Void pureTabs :: Spec {} Props Void
pureTabs = hideState (const {activeTab: 0}) statefulTabs pureTabs = hideState (const {activeTab: 0}) statefulTabs
...@@ -20,9 +36,9 @@ statefulTabs :: Spec Tab.State Props Tab.Action ...@@ -20,9 +36,9 @@ statefulTabs :: Spec Tab.State Props Tab.Action
statefulTabs = statefulTabs =
Tab.tabs identity identity $ fromFoldable Tab.tabs identity identity $ fromFoldable
[ Tuple "Documents" $ docs [ Tuple "Documents" $ docs
, Tuple "Patents" $ ngramsViewSpec {mode: NV.Patents} , Tuple "Patents" $ ngramsViewSpec {mode: Patents}
, Tuple "Books" $ ngramsViewSpec {mode: NV.Books} , Tuple "Books" $ ngramsViewSpec {mode: Books}
, Tuple "Communication" $ ngramsViewSpec {mode: NV.Communication} , Tuple "Communication" $ ngramsViewSpec {mode: Communication}
, Tuple "Trash" $ docs -- TODO pass-in trash mode , Tuple "Trash" $ docs -- TODO pass-in trash mode
] ]
where where
...@@ -32,7 +48,10 @@ statefulTabs = ...@@ -32,7 +48,10 @@ statefulTabs =
{nodeId, chart, tabType: TabPairing TabDocs, totalRecords: 4736}) $ {nodeId, chart, tabType: TabPairing TabDocs, totalRecords: 4736}) $
noState DT.docViewSpec noState DT.docViewSpec
ngramsViewSpec :: {mode :: NV.Mode} -> Spec Tab.State Props Tab.Action ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
ngramsViewSpec {mode} = ngramsViewSpec {mode} =
cmapProps (\{loaded, path, dispatch} -> {mode,loaded,path, dispatch}) cmapProps (\{loaded: {defaultListId}, path, dispatch} ->
(noState NV.ngramsTableSpec) {loaded: {defaultListId}, path, dispatch, tabType})
(noState NT.mainNgramsTableSpec)
where
tabType = TabPairing $ TabNgramType $ modeTabType mode
...@@ -168,5 +168,7 @@ instance decodeUser :: DecodeJson Contact where ...@@ -168,5 +168,7 @@ instance decodeUser :: DecodeJson Contact where
, hyperdata , hyperdata
} }
type PropsRow = Loader.InnerPropsRow Int Contact () type ContactData = {contactNode :: Contact, defaultListId :: Int}
type PropsRow = Loader.InnerPropsRow Int ContactData ()
type Props = Record PropsRow type Props = Record PropsRow
module Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable
(Mode(..), ngramsTableSpec)
where
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import React (ReactElement)
import React as React
import Thermite (Render, Spec, createClass, defaultPerformAction, simpleSpec)
import Gargantext.Components.Node (NodePoly)
import Gargantext.Components.NgramsTable as NT
import Gargantext.Prelude
import Gargantext.Config (CTabNgramType(..), End(..), Offset, Limit, OrderBy(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Config.REST (get)
import Gargantext.Components.Loader as Loader
import Gargantext.Pages.Corpus.Tabs.Types (CorpusData)
data Mode = Authors | Sources | Institutes | Terms
derive instance genericMode :: Generic Mode _
instance showMode :: Show Mode where
show = genericShow
derive instance eqMode :: Eq Mode
type Props = NT.Props CorpusData Mode
modeTabType :: Mode -> CTabNgramType
modeTabType Authors = CTabAuthors
modeTabType Sources = CTabSources
modeTabType Institutes = CTabInstitutes
modeTabType Terms = CTabTerms
-- TODO: Move to Components.NgramsTable?
loadPage :: NT.PageParams -> Aff NT.VersionedNgramsTable
loadPage { nodeId, listIds, termListFilter, termTypeFilter
, searchQuery, tabType, params: {offset, limit, orderBy}} =
get $ toUrl Back
(GetNgrams { tabType, offset, limit, listIds
, orderBy: convOrderBy <$> orderBy
, termListFilter, termTypeFilter
, searchQuery
})
(Just nodeId)
where
convOrderBy _ = DateAsc -- TODO
-- TODO: Move to Components.NgramsTable?
ngramsLoaderClass :: Loader.LoaderClass NT.PageParams NT.VersionedNgramsTable
ngramsLoaderClass = Loader.createLoaderClass "CorpusNgramsLoader" loadPage
-- TODO: Move to Components.NgramsTable?
ngramsLoader :: Loader.Props' NT.PageParams NT.VersionedNgramsTable -> ReactElement
ngramsLoader props = React.createElement ngramsLoaderClass props []
-- TODO: Move to Components.NgramsTable?
ngramsTableClass :: Loader.InnerClass NT.PageParams NT.VersionedNgramsTable
ngramsTableClass = createClass "CorpusNgramsTable" NT.ngramsTableSpec NT.initialState
ngramsTableSpec :: Spec {} Props Void
ngramsTableSpec = simpleSpec defaultPerformAction render
where
render :: Render {} Props Void
render _ {path: nodeId, loaded: {defaultListId}, mode} _ _ =
[ ngramsLoader { path: NT.initialPageParams nodeId [defaultListId] tabType
, component: ngramsTableClass
} ]
where
tabType = TabCorpus $ TabNgramType $ modeTabType mode
...@@ -2,19 +2,37 @@ module Gargantext.Pages.Corpus.Tabs.Specs where ...@@ -2,19 +2,37 @@ module Gargantext.Pages.Corpus.Tabs.Specs where
import Prelude hiding (div) import Prelude hiding (div)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.List (fromFoldable) import Data.List (fromFoldable)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Config (TabType(..), TabSubType(..)) import Gargantext.Config (TabType(..), TabSubType(..))
import Gargantext.Config (CTabNgramType(..), End(..), Path(..), TabSubType(..), TabType(..), toUrl)
import Gargantext.Pages.Corpus.Tabs.Types (Props) import Gargantext.Pages.Corpus.Tabs.Types (Props)
import Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable as NV
import Gargantext.Pages.Corpus.Dashboard (globalPublis) import Gargantext.Pages.Corpus.Dashboard (globalPublis)
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 Thermite (Spec, hideState, noState, cmapProps) import Thermite (Spec, hideState, noState, cmapProps)
data Mode = Authors | Sources | Institutes | Terms
derive instance genericMode :: Generic Mode _
instance showMode :: Show Mode where
show = genericShow
derive instance eqMode :: Eq Mode
modeTabType :: Mode -> CTabNgramType
modeTabType Authors = CTabAuthors
modeTabType Sources = CTabSources
modeTabType Institutes = CTabInstitutes
modeTabType Terms = CTabTerms
pureTabs :: Spec {} Props Void pureTabs :: Spec {} Props Void
pureTabs = hideState (const {activeTab: 0}) statefulTabs pureTabs = hideState (const {activeTab: 0}) statefulTabs
...@@ -22,10 +40,10 @@ statefulTabs :: Spec Tab.State Props Tab.Action ...@@ -22,10 +40,10 @@ statefulTabs :: Spec Tab.State Props Tab.Action
statefulTabs = statefulTabs =
Tab.tabs identity identity $ fromFoldable Tab.tabs identity identity $ fromFoldable
[ Tuple "Documents" $ docs [ Tuple "Documents" $ docs
, Tuple "Authors" $ ngramsViewSpec {mode: NV.Authors} , Tuple "Authors" $ ngramsViewSpec {mode: Authors}
, Tuple "Sources" $ ngramsViewSpec {mode: NV.Sources} , Tuple "Sources" $ ngramsViewSpec {mode: Sources}
, Tuple "Institutes" $ ngramsViewSpec {mode: NV.Institutes} , Tuple "Institutes" $ ngramsViewSpec {mode: Institutes}
, Tuple "Terms" $ ngramsViewSpec {mode: NV.Terms} , Tuple "Terms" $ ngramsViewSpec {mode: Terms}
, Tuple "Trash" $ docs -- TODO pass-in trash mode , Tuple "Trash" $ docs -- TODO pass-in trash mode
] ]
where where
...@@ -35,7 +53,10 @@ statefulTabs = ...@@ -35,7 +53,10 @@ statefulTabs =
{nodeId, chart, tabType: TabCorpus TabDocs, totalRecords: 4736}) $ {nodeId, chart, tabType: TabCorpus TabDocs, totalRecords: 4736}) $
noState DT.docViewSpec noState DT.docViewSpec
ngramsViewSpec :: {mode :: NV.Mode} -> Spec Tab.State Props Tab.Action ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
ngramsViewSpec {mode} = ngramsViewSpec {mode} =
cmapProps (\{loaded, path, dispatch} -> {mode,loaded,path, dispatch}) cmapProps (\{loaded: {defaultListId}, path, dispatch} ->
(noState NV.ngramsTableSpec) {loaded: {defaultListId}, path, dispatch, tabType})
(noState NT.mainNgramsTableSpec)
where
tabType = TabCorpus $ TabNgramType $ modeTabType mode
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