Commit 16364b1e authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[list] list charts refresh properly

parent e00d9477
module Gargantext.Components.Nodes.Corpus.Chart.Common where module Gargantext.Components.Nodes.Corpus.Chart.Common where
import Data.Tuple (fst, Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.Nodes.Corpus.Chart.Types (Path, Props, MetricsProps) import Gargantext.Components.Nodes.Corpus.Chart.Types
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
type MetricsLoadViewProps a = ( type MetricsLoadViewProps a = (
getMetrics :: Session -> Record Path -> Aff a getMetrics :: Session -> Tuple Reload (Record Path) -> Aff a
, loaded :: Session -> Record Path -> R.State Int -> a -> R.Element , loaded :: Session -> Record Path -> R.State Reload -> a -> R.Element
| MetricsProps | MetricsProps
) )
...@@ -22,5 +24,5 @@ metricsLoadViewCpt :: forall a. R.Component (MetricsLoadViewProps a) ...@@ -22,5 +24,5 @@ metricsLoadViewCpt :: forall a. R.Component (MetricsLoadViewProps a)
metricsLoadViewCpt = R.hooksComponent "G.C.N.C.C.metricsLoadView" cpt metricsLoadViewCpt = R.hooksComponent "G.C.N.C.C.metricsLoadView" cpt
where where
cpt {getMetrics, loaded, path, reload, session} _ = do cpt {getMetrics, loaded, path, reload, session} _ = do
useLoader path (getMetrics session) $ \l -> useLoader (fst reload /\ path) (getMetrics session) $ \l ->
loaded session path reload l loaded session path reload l
module Gargantext.Components.Nodes.Corpus.Chart.Histo where module Gargantext.Components.Nodes.Corpus.Chart.Histo where
import Prelude (bind, map, pure, ($))
import Data.Argonaut (class DecodeJson, decodeJson, (.:)) import Data.Argonaut (class DecodeJson, decodeJson, (.:))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis') import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis')
import Gargantext.Components.Charts.Options.Series (seriesBarD1) import Gargantext.Components.Charts.Options.Series (seriesBarD1)
import Gargantext.Components.Charts.Options.Color (grey) import Gargantext.Components.Charts.Options.Color (grey)
import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter) import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter)
import Gargantext.Components.Charts.Options.Data (dataSerie) import Gargantext.Components.Charts.Options.Data (dataSerie)
import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView) import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView)
import Gargantext.Components.Nodes.Corpus.Chart.Types (Path, Props) import Gargantext.Components.Nodes.Corpus.Chart.Types
import Gargantext.Components.Nodes.Corpus.Chart.Utils as U import Gargantext.Components.Nodes.Corpus.Chart.Utils as U
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
...@@ -49,8 +52,8 @@ chartOptions (HistoMetrics { dates: dates', count: count'}) = Options ...@@ -49,8 +52,8 @@ chartOptions (HistoMetrics { dates: dates', count: count'}) = Options
, series : [seriesBarD1 {name: "Number of publication / year"} $ , series : [seriesBarD1 {name: "Number of publication / year"} $
map (\n -> dataSerie {value: n, itemStyle : itemStyle {color:grey}}) count'] } map (\n -> dataSerie {value: n, itemStyle : itemStyle {color:grey}}) count'] }
getMetrics :: Session -> Record Path -> Aff HistoMetrics getMetrics :: Session -> Tuple Reload (Record Path) -> Aff HistoMetrics
getMetrics session {corpusId, limit, listId, tabType} = do getMetrics session (_ /\ { corpusId, limit, listId, tabType }) = do
ChartMetrics ms <- get session chart ChartMetrics ms <- get session chart
pure ms."data" pure ms."data"
where where
...@@ -66,7 +69,7 @@ histoCpt = R.hooksComponent "G.C.N.C.C.H.histo" cpt ...@@ -66,7 +69,7 @@ histoCpt = R.hooksComponent "G.C.N.C.C.H.histo" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded, path, reload, session} pure $ metricsLoadView {getMetrics, loaded, path, reload, session}
loaded :: Session -> Record Path -> R.State Int -> HistoMetrics -> R.Element loaded :: Session -> Record Path -> R.State Reload -> HistoMetrics -> R.Element
loaded session path reload loaded = loaded session path reload loaded =
H.div {} [ H.div {} [
U.reloadButton reload U.reloadButton reload
......
...@@ -6,6 +6,7 @@ import Data.Map as Map ...@@ -6,6 +6,7 @@ import Data.Map as Map
import Data.Map (Map) import Data.Map (Map)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -17,7 +18,7 @@ import Gargantext.Components.Charts.Options.Color (green, grey, red) ...@@ -17,7 +18,7 @@ import Gargantext.Components.Charts.Options.Color (green, grey, red)
import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter) import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter)
import Gargantext.Components.Charts.Options.Data (dataSerie) import Gargantext.Components.Charts.Options.Data (dataSerie)
import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView) import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView)
import Gargantext.Components.Nodes.Corpus.Chart.Types (Path, Props) import Gargantext.Components.Nodes.Corpus.Chart.Types
import Gargantext.Components.Nodes.Corpus.Chart.Utils as U import Gargantext.Components.Nodes.Corpus.Chart.Utils as U
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
...@@ -85,8 +86,8 @@ scatterOptions metrics' = Options ...@@ -85,8 +86,8 @@ scatterOptions metrics' = Options
} }
--} --}
getMetrics :: Session -> Record Path -> Aff Loaded getMetrics :: Session -> Tuple Reload (Record Path) -> Aff Loaded
getMetrics session {corpusId, limit, listId, tabType} = do getMetrics session (_ /\ { corpusId, limit, listId, tabType }) = do
Metrics ms <- get session metrics' Metrics ms <- get session metrics'
pure ms."data" pure ms."data"
where where
...@@ -102,7 +103,7 @@ metricsCpt = R.hooksComponent "G.C.N.C.C.M.metrics" cpt ...@@ -102,7 +103,7 @@ metricsCpt = R.hooksComponent "G.C.N.C.C.M.metrics" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded, path, reload, session} pure $ metricsLoadView {getMetrics, loaded, path, reload, session}
loaded :: Session -> Record Path -> R.State Int -> Loaded -> R.Element loaded :: Session -> Record Path -> R.State Reload -> Loaded -> R.Element
loaded session path reload loaded = loaded session path reload loaded =
H.div {} [ H.div {} [
U.reloadButton reload U.reloadButton reload
......
...@@ -7,6 +7,7 @@ import Data.Array as A ...@@ -7,6 +7,7 @@ import Data.Array as A
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.String (take, joinWith, Pattern(..), split, length) import Data.String (take, joinWith, Pattern(..), split, length)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -17,7 +18,7 @@ import Gargantext.Components.Charts.Options.Color (blue) ...@@ -17,7 +18,7 @@ import Gargantext.Components.Charts.Options.Color (blue)
import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter) import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter)
import Gargantext.Components.Charts.Options.Data (dataSerie) import Gargantext.Components.Charts.Options.Data (dataSerie)
import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView) import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView)
import Gargantext.Components.Nodes.Corpus.Chart.Types (Path, Props) import Gargantext.Components.Nodes.Corpus.Chart.Types
import Gargantext.Components.Nodes.Corpus.Chart.Utils as U import Gargantext.Components.Nodes.Corpus.Chart.Utils as U
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
...@@ -71,8 +72,8 @@ chartOptionsPie (HistoMetrics { dates: dates', count: count'}) = Options ...@@ -71,8 +72,8 @@ chartOptionsPie (HistoMetrics { dates: dates', count: count'}) = Options
} }
getMetrics :: Session -> Record Path -> Aff HistoMetrics getMetrics :: Session -> Tuple Reload (Record Path) -> Aff HistoMetrics
getMetrics session {corpusId, limit, listId, tabType} = do getMetrics session (_ /\ { corpusId, limit, listId, tabType }) = do
ChartMetrics ms <- get session chart ChartMetrics ms <- get session chart
pure ms."data" pure ms."data"
where chart = Chart {chartType: ChartPie, limit, listId, tabType} (Just corpusId) where chart = Chart {chartType: ChartPie, limit, listId, tabType} (Just corpusId)
...@@ -87,7 +88,7 @@ pieCpt = R.hooksComponent "G.C.N.C.C.P.pie" cpt ...@@ -87,7 +88,7 @@ pieCpt = R.hooksComponent "G.C.N.C.C.P.pie" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded: loadedPie, path, reload, session} pure $ metricsLoadView {getMetrics, loaded: loadedPie, path, reload, session}
loadedPie :: Session -> Record Path -> R.State Int -> HistoMetrics -> R.Element loadedPie :: Session -> Record Path -> R.State Reload -> HistoMetrics -> R.Element
loadedPie session path reload loaded = loadedPie session path reload loaded =
H.div {} [ H.div {} [
U.reloadButton reload U.reloadButton reload
...@@ -106,7 +107,7 @@ barCpt = R.hooksComponent "LoadedMetricsBar" cpt ...@@ -106,7 +107,7 @@ barCpt = R.hooksComponent "LoadedMetricsBar" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded: loadedBar, path, reload, session} pure $ metricsLoadView {getMetrics, loaded: loadedBar, path, reload, session}
loadedBar :: Session -> Record Path -> R.State Int -> Loaded -> R.Element loadedBar :: Session -> Record Path -> R.State Reload -> Loaded -> R.Element
loadedBar session path reload loaded = loadedBar session path reload loaded =
H.div {} [ H.div {} [
U.reloadButton reload U.reloadButton reload
......
...@@ -2,6 +2,8 @@ module Gargantext.Components.Nodes.Corpus.Chart.Tree where ...@@ -2,6 +2,8 @@ module Gargantext.Components.Nodes.Corpus.Chart.Tree where
import Data.Argonaut (class DecodeJson, decodeJson, (.:)) import Data.Argonaut (class DecodeJson, decodeJson, (.:))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -13,7 +15,7 @@ import Gargantext.Components.Charts.Options.Series (TreeNode, Trees(..), mkTree) ...@@ -13,7 +15,7 @@ import Gargantext.Components.Charts.Options.Series (TreeNode, Trees(..), mkTree)
import Gargantext.Components.Charts.Options.Font (mkTooltip, templateFormatter) import Gargantext.Components.Charts.Options.Font (mkTooltip, templateFormatter)
import Gargantext.Components.Nodes.Corpus.Chart.Utils as U import Gargantext.Components.Nodes.Corpus.Chart.Utils as U
import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView) import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsLoadView)
import Gargantext.Components.Nodes.Corpus.Chart.Types (Path, Props) import Gargantext.Components.Nodes.Corpus.Chart.Types
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
import Gargantext.Types (ChartType(..), TabType) import Gargantext.Types (ChartType(..), TabType)
...@@ -44,8 +46,8 @@ scatterOptions nodes = Options ...@@ -44,8 +46,8 @@ scatterOptions nodes = Options
} }
getMetrics :: Session -> Record Path -> Aff Loaded getMetrics :: Session -> Tuple Reload (Record Path) -> Aff Loaded
getMetrics session {corpusId, limit, listId, tabType} = do getMetrics session (_ /\ { corpusId, limit, listId, tabType }) = do
Metrics ms <- get session chart Metrics ms <- get session chart
pure ms."data" pure ms."data"
where where
...@@ -61,7 +63,7 @@ treeCpt = R.hooksComponent "G.C.N.C.C.T.tree" cpt ...@@ -61,7 +63,7 @@ treeCpt = R.hooksComponent "G.C.N.C.C.T.tree" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded, path, reload, session} pure $ metricsLoadView {getMetrics, loaded, path, reload, session}
loaded :: Session -> Record Path -> R.State Int -> Loaded -> R.Element loaded :: Session -> Record Path -> R.State Reload -> Loaded -> R.Element
loaded session path reload loaded = loaded session path reload loaded =
H.div {} [ H.div {} [
U.reloadButton reload U.reloadButton reload
......
...@@ -6,6 +6,8 @@ import Reactix as R ...@@ -6,6 +6,8 @@ import Reactix as R
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (TabType) import Gargantext.Types (TabType)
type Reload = Int
type Path = ( type Path = (
corpusId :: Int corpusId :: Int
, limit :: Maybe Int , limit :: Maybe Int
......
...@@ -2,7 +2,6 @@ module Gargantext.Components.Nodes.Corpus.Chart.Utils where ...@@ -2,7 +2,6 @@ module Gargantext.Components.Nodes.Corpus.Chart.Utils where
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
...@@ -47,8 +46,6 @@ chartUpdateButtonCpt = R.hooksComponent "G.C.N.C.C.U.chartUpdateButton" cpt ...@@ -47,8 +46,6 @@ chartUpdateButtonCpt = R.hooksComponent "G.C.N.C.C.U.chartUpdateButton" cpt
cpt { chartType cpt { chartType
, path: { corpusId, listId, tabType } , path: { corpusId, listId, tabType }
, reload: (_ /\ setReload), session } _ = do , reload: (_ /\ setReload), session } _ = do
R.useEffect' $ do
log2 "[chartUpdateButton] tabType" tabType
pure $ H.a { className: "chart-update-button fa fa-database" pure $ H.a { className: "chart-update-button fa fa-database"
, on: { click: onClick } , on: { click: onClick }
......
...@@ -2,7 +2,6 @@ module Gargantext.Components.Nodes.Lists.Tabs where ...@@ -2,7 +2,6 @@ module Gargantext.Components.Nodes.Lists.Tabs where
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -52,10 +51,6 @@ ngramsViewCpt = R.hooksComponent "G.C.N.L.T.ngramsView" cpt ...@@ -52,10 +51,6 @@ ngramsViewCpt = R.hooksComponent "G.C.N.L.T.ngramsView" cpt
, corpusId , corpusId
, mode , mode
, session } _ = do , session } _ = do
R.useEffect' $ do
log2 "[ngramsViewCpt] corpusId" corpusId
log2 "[ngramsViewCpt] defaultListId" defaultListId
chartType <- R.useState' Histo chartType <- R.useState' Histo
pure $ R.fragment pure $ R.fragment
......
...@@ -179,7 +179,7 @@ sessionPath (R.Search {listId, limit, offset, orderBy} (Just corpusId)) = ...@@ -179,7 +179,7 @@ sessionPath (R.Search {listId, limit, offset, orderBy} (Just corpusId)) =
-- <> offsetUrl offset -- <> offsetUrl offset
-- <> limitUrl limit -- <> limitUrl limit
-- <> orderUrl orderBy -- <> orderUrl orderBy
sessionPath (R.CorpusMetrics {tabType, listId, limit} i) = sessionPath (R.CorpusMetrics { listId, limit, tabType} i) =
sessionPath $ R.NodeAPI Corpus i sessionPath $ R.NodeAPI Corpus i
$ "metrics" $ "metrics"
<> "?ngrams=" <> show listId <> "?ngrams=" <> show listId
......
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