Specs.purs 2.75 KB
Newer Older
1
module Gargantext.Pages.Lists.Tabs.Specs where
2 3 4

import Prelude hiding (div)

5 6
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
7
import Data.List (fromFoldable)
8
import Data.Maybe (Maybe(..))
9 10
import Data.Tuple (Tuple(..))

11
import Gargantext.Config (CTabNgramType(..), TabSubType(..), TabType(..))
12
import Gargantext.Pages.Lists.Tabs.Types (Props, PropsRow)
13

14
import Gargantext.Pages.Corpus.Chart.Metrics (metricsSpec)
15
import Gargantext.Pages.Corpus.Chart.Pie  (pieSpec, barSpec)
16
import Gargantext.Pages.Corpus.Chart.Tree (treeSpec)
17

18
import Gargantext.Components.NgramsTable as NT
19
import Gargantext.Components.Tab as Tab
20

21 22
import React (ReactElement, ReactClass, createElement, Children)
import Thermite (Spec, hideState, noState, cmapProps, createClass)
23

24 25 26 27 28 29 30 31 32 33
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
34 35
modeTabType Authors    = CTabAuthors
modeTabType Sources    = CTabSources
36
modeTabType Institutes = CTabInstitutes
37
modeTabType Terms      = CTabTerms
38

39 40 41 42
elt :: Props -> ReactElement
elt props = createElement tabsClass props []

tabsClass :: ReactClass { children :: Children | PropsRow }
43
tabsClass = createClass "CorpusTabs" pureTabs $ const {}
44

45 46
pureTabs :: Spec {} Props Void
pureTabs = hideState (const {activeTab: 0}) statefulTabs
47

48
statefulTabs :: Spec Tab.State Props Tab.Action
49
statefulTabs =
50
  Tab.tabs identity identity $ fromFoldable
51
    [ Tuple "Sources"    $ ngramsViewSpec {mode: Sources   }
52
    , Tuple "Authors"    $ ngramsViewSpec {mode: Authors   }
53
    , Tuple "Institutes" $ ngramsViewSpec {mode: Institutes}
54
    , Tuple "Terms"      $ ngramsViewSpec {mode: Terms     }
55
    ]
56 57


58
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
59
ngramsViewSpec {mode} =
60 61 62
  noState $ chart mode <>
    cmapProps (\{corpusData: {defaultListId}, corpusId: nodeId} ->
                {defaultListId, nodeId, tabType})
63
              (NT.mainNgramsTableSpec (modeTabType mode))
64

65 66
  where
    tabType = TabCorpus $ TabNgramType $ modeTabType mode
67 68
    chart Authors    = cmapProps (\{corpusId} -> {corpusId, tabType}) pieSpec
    chart Sources    = cmapProps (\{corpusId} -> {corpusId, tabType}) barSpec
69

70
    chart Institutes = cmapProps (\{corpusData: {defaultListId}, corpusId} ->
71
                          {corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
72
                      treeSpec
73

74
    chart Terms      = cmapProps (\{corpusData: {defaultListId}, corpusId} ->
75
                          {corpusId, listId: defaultListId, tabType, limit: (Just 1000)})
76 77
                          -- TODO limit should be select in the chart by default it is 1000
                      metricsSpec