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