Commit 1eae92d9 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Dashboard] chart selection works now

parent d0a94fc1
module Gargantext.Components.Nodes.Corpus.Dashboard where module Gargantext.Components.Nodes.Corpus.Dashboard where
import Data.Array as A import Data.Array as A
import Data.String.Common as DSC
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -33,12 +32,7 @@ dashboardLayoutCpt :: R.Component Props ...@@ -33,12 +32,7 @@ dashboardLayoutCpt :: R.Component Props
dashboardLayoutCpt = R.hooksComponent "G.P.C.D.dashboardLayout" cpt dashboardLayoutCpt = R.hooksComponent "G.P.C.D.dashboardLayout" cpt
where where
cpt params@{nodeId, session} _ = do cpt params@{nodeId, session} _ = do
predefinedCharts <- R.useState' [ predefinedCharts <- R.useState' []
-- P.CDocsHistogram
-- , P.CAuthorsPie
-- , P.CTermsMetrics
-- , P.CInstitutesTree
]
useLoader params loadCorpusWithChild $ useLoader params loadCorpusWithChild $
\corpusData@{corpusId, defaultListId, corpusNode: NodePoly poly} -> do \corpusData@{corpusId, defaultListId, corpusNode: NodePoly poly} -> do
let { name, date, hyperdata : Hyperdata h} = poly let { name, date, hyperdata : Hyperdata h} = poly
...@@ -67,16 +61,18 @@ dashboardLayoutLoadedCpt = R.hooksComponent "G.C.N.C.D.dashboardLayoutLoaded" cp ...@@ -67,16 +61,18 @@ dashboardLayoutLoadedCpt = R.hooksComponent "G.C.N.C.D.dashboardLayoutLoaded" cp
where where
addNew = H.div { className: "row" } [ addNew = H.div { className: "row" } [
H.span { className: "btn btn-default" H.span { className: "btn btn-default"
, on: { click: onClick }} [ H.span { className: "fa fa-plus" } [] ] , on: { click: onClickAdd }} [ H.span { className: "fa fa-plus" } [] ]
] ]
where where
onClick _ = setPredefinedCharts $ A.cons P.CDocsHistogram onClickAdd _ = setPredefinedCharts $ A.cons P.CDocsHistogram
charts = A.mapWithIndex chartIdx predefinedCharts charts = A.mapWithIndex chartIdx predefinedCharts
chartIdx idx chart = chartIdx idx chart =
renderChart { chart, corpusId, defaultListId, onChange, onRemove, session } renderChart { chart, corpusId, defaultListId, onChange, onRemove, session }
where where
onChange c = setPredefinedCharts $ onChange c = do
\cs -> fromMaybe cs (A.modifyAt idx (\_ -> c) cs) log2 "[dashboardLayout] idx" idx
log2 "[dashboardLayout] new chart" c
setPredefinedCharts $ \cs -> fromMaybe cs (A.modifyAt idx (\_ -> c) cs)
onRemove _ = setPredefinedCharts $ onRemove _ = setPredefinedCharts $
\cs -> fromMaybe cs $ A.deleteAt idx cs \cs -> fromMaybe cs $ A.deleteAt idx cs
...@@ -112,7 +108,7 @@ renderChartCpt = R.hooksComponent "G.C.N.C.D.renderChart" cpt ...@@ -112,7 +108,7 @@ renderChartCpt = R.hooksComponent "G.C.N.C.D.renderChart" cpt
where where
option pc = option pc =
H.option { value: show pc } [ H.text $ show pc ] H.option { value: show pc } [ H.text $ show pc ]
onSelectChange e = onChange $ P.readChart' e onSelectChange e = onChange $ P.readChart' value
where where
value = R2.unsafeEventValue e value = R2.unsafeEventValue e
onRemoveClick _ = onRemove unit onRemoveClick _ = onRemove unit
......
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