Tabs.purs 2.18 KB
Newer Older
1
module Gargantext.Components.Nodes.Lists.Tabs where
2

3
import Prelude
4 5 6 7 8
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Reactix as R
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Tab as Tab
9
import Gargantext.Components.Nodes.Corpus.Types (CorpusData)
10 11 12
import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
import Gargantext.Components.Nodes.Corpus.Chart.Pie  (pie, bar)
import Gargantext.Components.Nodes.Corpus.Chart.Tree (tree)
13
import Gargantext.Sessions (Session)
14
import Gargantext.Types (Mode(..), TabSubType(..), TabType(..), modeTabType)
15 16

type Props =
17
  ( session :: Session
18 19 20 21 22 23 24 25 26
  , corpusId :: Int
  , corpusData :: CorpusData )

tabs :: Record Props -> R.Element
tabs props = R.createElement tabsCpt props []

tabsCpt :: R.Component Props
tabsCpt = R.hooksComponent "CorpusTabs" cpt
  where
27
    cpt {session, corpusId, corpusData: corpusData@{defaultListId}} _ = do
28
      (selected /\ setSelected) <- R.useState' 0
29
      pure $ Tab.tabs { tabs: tabs', selected }
30
      where
31 32 33 34 35
        tabs' = [ "Sources"    /\ view Sources
                , "Authors"    /\ view Authors
                , "Institutes" /\ view Institutes
                , "Terms"      /\ view Terms ]
        view mode = ngramsView {mode, session, corpusId, corpusData}
36 37 38 39 40 41 42 43 44

type NgramsViewProps = ( mode :: Mode | Props )

ngramsView :: Record NgramsViewProps -> R.Element
ngramsView props = R.createElement ngramsViewCpt props []

ngramsViewCpt :: R.Component NgramsViewProps
ngramsViewCpt = R.staticComponent "ListsNgramsView" cpt
  where
45
    cpt {mode, session, corpusId, corpusData: {defaultListId}} _ =
46 47 48 49 50
      R.fragment
        [ chart mode
        , NT.mainNgramsTable
            {session, defaultListId, nodeId: corpusId, tabType, tabNgramType}
        ]
51 52 53 54 55 56
      where
        tabNgramType = modeTabType mode
        tabType = TabCorpus (TabNgramType tabNgramType)
        listId = 0 -- TODO!
        path = {corpusId, tabType}
        path2 = {corpusId, listId, tabType, limit: (Just 1000)} -- todo
57 58 59
        chart Authors = pie {session, path}
        chart Sources = bar {session, path}
        chart Institutes = tree {session, path: path2}
60
        chart Terms      = metrics {session, path: path2}