Commit b52dccca authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski Committed by Alexandre Delanoë

[ngrams] small refactoring

parent 15adf4ae
...@@ -11,19 +11,18 @@ import Data.Lens.Common (_Just) ...@@ -11,19 +11,18 @@ import Data.Lens.Common (_Just)
import Data.Lens.Fold (folded) import Data.Lens.Fold (folded)
import Data.Lens.Index (ix) import Data.Lens.Index (ix)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.List as L import Data.List (List, filter, length, null, toUnfoldable) as L
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), maybe, isJust, isNothing) import Data.Maybe (Maybe(..), maybe, isJust, isNothing)
import Data.Monoid.Additive (Additive(..)) import Data.Monoid.Additive (Additive(..))
import Data.Nullable (Nullable, toMaybe, null) import Data.Nullable (null, toMaybe)
import Data.Ord.Down (Down(..)) import Data.Ord.Down (Down(..))
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), fst, snd) import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect) import Effect (Effect)
import FFI.Simple (delay) import FFI.Simple (delay)
import Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, otherwise, pure, show, unit, (#), ($), (&&), (+), (/=), (<$>), (<<<), (<>), (=<<), (==), (||)) import Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, otherwise, pure, show, unit, (#), ($), (&&), (+), (/=), (<$>), (<<<), (<>), (=<<), (==), (||))
...@@ -42,7 +41,7 @@ import Gargantext.Components.Table as T ...@@ -42,7 +41,7 @@ import Gargantext.Components.Table as T
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), readTermList, readTermSize, termLists, termSizes) import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), readTermList, readTermSize, termLists, termSizes)
import Gargantext.Utils (queryMatchesLabel, toggleSet) import Gargantext.Utils (queryMatchesLabel, toggleSet)
import Gargantext.Utils.List as L import Gargantext.Utils.List (sortWith) as L
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
type State' = type State' =
...@@ -65,36 +64,36 @@ _ngramsSelection = prop (SProxy :: SProxy "ngramsSelection") ...@@ -65,36 +64,36 @@ _ngramsSelection = prop (SProxy :: SProxy "ngramsSelection")
initialState' :: VersionedNgramsTable -> State' initialState' :: VersionedNgramsTable -> State'
initialState' (Versioned {version}) = initialState' (Versioned {version}) =
{ ngramsLocalPatch: mempty { ngramsChildren: mempty
, ngramsLocalPatch: mempty
, ngramsParent: Nothing
, ngramsSelection: mempty
, ngramsStagePatch: mempty , ngramsStagePatch: mempty
, ngramsValidPatch: mempty , ngramsValidPatch: mempty
, ngramsVersion: version , ngramsVersion: version
, ngramsParent: Nothing
, ngramsChildren: mempty
, ngramsSelection: mempty
} }
type State = type State =
CoreState ( CoreState (
ngramsParent :: Maybe NgramsTerm -- Nothing means we are not currently grouping terms ngramsChildren :: Map NgramsTerm Boolean
, ngramsChildren :: Map NgramsTerm Boolean
-- ^ Used only when grouping. -- ^ Used only when grouping.
-- This updates the children of `ngramsParent`, -- This updates the children of `ngramsParent`,
-- ngrams set to `true` are to be added, and `false` to -- ngrams set to `true` are to be added, and `false` to
-- be removed. -- be removed.
, ngramsParent :: Maybe NgramsTerm -- Nothing means we are not currently grouping terms
, ngramsSelection :: Set NgramsTerm , ngramsSelection :: Set NgramsTerm
-- ^ The set of selected checkboxes of the first column. -- ^ The set of selected checkboxes of the first column.
) )
initialState :: VersionedNgramsTable -> State initialState :: VersionedNgramsTable -> State
initialState (Versioned {version}) = { initialState (Versioned {version}) = {
ngramsLocalPatch: mempty ngramsChildren: mempty
, ngramsLocalPatch: mempty
, ngramsParent: Nothing
, ngramsSelection: mempty
, ngramsStagePatch: mempty , ngramsStagePatch: mempty
, ngramsValidPatch: mempty , ngramsValidPatch: mempty
, ngramsVersion: version , ngramsVersion: version
, ngramsParent: Nothing
, ngramsChildren: mempty
, ngramsSelection: mempty
} }
data Action data Action
...@@ -249,13 +248,13 @@ tableContainerCpt { dispatch ...@@ -249,13 +248,13 @@ tableContainerCpt { dispatch
selectButtons true = selectButtons true =
H.li {className: " list-group-item"} [ H.li {className: " list-group-item"} [
H.button { className: "btn btn-primary" H.button { className: "btn btn-primary"
, on: {click: const $ setSelection GraphTerm } , on: { click: const $ setSelection GraphTerm }
} [ H.text "Map" ] } [ H.text "Map" ]
, H.button { className: "btn btn-primary" , H.button { className: "btn btn-primary"
, on: {click: const $ setSelection StopTerm } , on: { click: const $ setSelection StopTerm }
} [ H.text "Stop" ] } [ H.text "Stop" ]
, H.button { className: "btn btn-primary" , H.button { className: "btn btn-primary"
, on: {click: const $ setSelection CandidateTerm } , on: { click: const $ setSelection CandidateTerm }
} [ H.text "Candidate" ] } [ H.text "Candidate" ]
] ]
...@@ -389,7 +388,7 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt ...@@ -389,7 +388,7 @@ loadedNgramsTableSpecCpt = R.hooksComponent "G.C.NT.loadedNgramsTable" cpt
performAction ToggleSelectAll = performAction ToggleSelectAll =
setState toggler setState toggler
where where
toggler s@{ ngramsSelection } = toggler s =
if allNgramsSelected then if allNgramsSelected then
s { ngramsSelection = Set.empty :: Set NgramsTerm } s { ngramsSelection = Set.empty :: Set NgramsTerm }
else else
......
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