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

3
import Data.Maybe (Maybe(..), fromMaybe)
4 5
import Data.Tuple.Nested ((/\))
import Reactix as R
6 7 8 9
import Reactix.DOM.HTML as H

import Gargantext.Prelude

10 11
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Tab as Tab
12
import Gargantext.Components.Nodes.Corpus.Types (CorpusData)
13 14 15
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)
16
import Gargantext.Components.Nodes.Corpus.Chart (getChartFunction)
17
import Gargantext.Sessions (Session)
18 19
import Gargantext.Types (ChartType(..), CTabNgramType(..), Mode(..), TabSubType(..), TabType(..), chartTypeFromString, modeTabType)
import Gargantext.Utils.Reactix as R2
20 21

type Props =
22
  ( session :: Session
23 24 25 26 27 28 29
  , corpusId :: Int
  , corpusData :: CorpusData )

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

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

type NgramsViewProps = ( mode :: Mode | Props )

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

ngramsViewCpt :: R.Component NgramsViewProps
48
ngramsViewCpt = R.hooksComponent "G.C.N.L.T.ngramsView" cpt
49
  where
50 51 52 53 54
    cpt { corpusData: {defaultListId}
        , corpusId
        , mode
        , session } _ = do
      chartType <- R.useState' Histo
55 56 57 58 59

      pure $ R.fragment
        ( charts tabNgramType chartType
        <> [
          NT.mainNgramsTable
60
            {session, defaultListId, nodeId: corpusId, tabType, tabNgramType, withAutoUpdate: false}
61
        ]
62
        )
63 64 65
      where
        tabNgramType = modeTabType mode
        tabType = TabCorpus (TabNgramType tabNgramType)
66
        listId = defaultListId
67
        path = {corpusId, listId, tabType, limit: (Just 1000)}
68 69

        charts CTabTerms (chartType /\ setChartType) = [
70
          H.div { className: "row chart-type-selector" } [
71 72 73
            H.div { className: "col-md-3" } [

              R2.select { className: "form-control"
74
                        ,  on: { change: \e -> setChartType $ const $ fromMaybe Histo $ chartTypeFromString $ R2.unsafeEventValue e }
75 76 77 78 79 80 81
                        , defaultValue: show chartType } [
                H.option { value: show Histo } [ H.text $ show Histo ]
              , H.option { value: show Scatter } [ H.text $ show Scatter ]
              , H.option { value: show ChartBar } [ H.text $ show ChartBar ]
              , H.option { value: show ChartTree } [ H.text $ show ChartTree ]
              ]
            ]
82
          ]
83
        , getChartFunction chartType $ { session, path }
84 85 86
        ]
        charts _ _ = [ chart mode ]

87 88 89 90
        chart Authors = pie { session, path }
        chart Sources = bar { session, path }
        chart Institutes = tree { session, path }
        chart Terms      = metrics { session, path }