Tabs.purs 1.52 KB
Newer Older
1
module Gargantext.Components.Nodes.Corpus.Graph.Tabs where
2 3

import Prelude hiding (div)
4 5
import Data.Array (fromFoldable)
import Data.Tuple (Tuple(..), fst)
6
import Reactix as R
7
import Gargantext.Components.GraphExplorer.Types (GraphSideCorpus(..))
8
import Gargantext.Components.FacetsTable (docView)
9
import Gargantext.Components.Search (SearchQuery)
10
import Gargantext.Components.Table as T
11
import Gargantext.Components.Tab as Tab
12
import Gargantext.Ends (Frontends)
13
import Gargantext.Sessions (Session)
14 15
import Gargantext.Utils.Reactix as R2

16
here :: R2.Here
17
here = R2.here "Gargantext.Components.Nodes.Corpus.Graph.Tabs"
18

19 20
type Props =
  ( frontends :: Frontends
21
  , query     :: SearchQuery
22 23
  , session   :: Session
  , sides     :: Array GraphSideCorpus
24
  )
25

26 27
tabs :: Record Props -> R.Element
tabs props = R.createElement tabsCpt props []
28 29

-- TODO no need for Children here
30
tabsCpt :: R.Component Props
31
tabsCpt = here.component "tabs" cpt
32
  where
33
    cpt {frontends, query, session, sides} _ = do
34 35 36
      active <- R.useState' 0
      pure $ Tab.tabs {tabs: tabs', selected: fst active}
      where
37
        tabs' = fromFoldable $ tab frontends session query <$> sides
38

39
tab :: Frontends -> Session -> SearchQuery -> GraphSideCorpus -> Tuple String R.Element
40
tab frontends session query (GraphSideCorpus {corpusId: nodeId, corpusLabel, listId}) =
41
  Tuple corpusLabel (docView dvProps)
42
  where
43 44
    dvProps   = {frontends, session, nodeId, listId, query, chart, totalRecords: 0, container}
    chart     = mempty
45
    container = T.graphContainer {title: corpusLabel}
46