Commit fa04a893 authored by arturo's avatar arturo

[phylo] Change ngram for selected terms

parent 6345d0d4
Pipeline #3012 failed with stage
in 0 seconds
...@@ -17,6 +17,7 @@ import Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms (updateTerms) ...@@ -17,6 +17,7 @@ import Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms (updateTerms)
import Gargantext.Components.PhyloExplorer.Store as PhyloStore import Gargantext.Components.PhyloExplorer.Store as PhyloStore
import Gargantext.Components.PhyloExplorer.Types (ExtractedCount(..), ExtractedTerm(..), defaultCacheParams) import Gargantext.Components.PhyloExplorer.Types (ExtractedCount(..), ExtractedTerm(..), defaultCacheParams)
import Gargantext.Hooks.FirstEffect (useFirstEffect') import Gargantext.Hooks.FirstEffect (useFirstEffect')
import Gargantext.Types (CTabNgramType(..))
import Gargantext.Utils (nbsp, setter, (?)) import Gargantext.Utils (nbsp, setter, (?))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
...@@ -230,7 +231,9 @@ component = here.component "main" cpt where ...@@ -230,7 +231,9 @@ component = here.component "main" cpt where
{ className: "phylo-selection-tab__highlight__actions" } { className: "phylo-selection-tab__highlight__actions" }
[ [
updateTerms updateTerms
{} { selectedTerm: s
, ngramType: CTabTerms
}
] ]
] ]
] ]
......
...@@ -2,45 +2,90 @@ module Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms where ...@@ -2,45 +2,90 @@ module Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms where
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array as A
import Data.Either (Either(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store as AppStore import Gargantext.Components.App.Store as AppStore
import Gargantext.Components.Bootstrap as B import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), ComponentStatus(..), Variant(..)) import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), ComponentStatus(..), Variant(..))
import Gargantext.Components.PhyloExplorer.Store as PhyloStore import Gargantext.Components.PhyloExplorer.Store as PhyloStore
import Gargantext.Components.PhyloExplorer.Types (ListId, CorpusId)
import Gargantext.Config.REST (AffRESTError)
import Gargantext.Core.NgramsTable.Functions as NTC
import Gargantext.Core.NgramsTable.Types as CNT
import Gargantext.Hooks.Session (useSession)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, FrontendError(..), TabSubType(..), TabType(..), TermList(..))
import Gargantext.Utils ((?))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms" here = R2.here "Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms"
type Props =
( selectedTerm :: String
, ngramType :: CTabNgramType
)
-- | @NOTE #408: only dealing with single Term selection -- | @NOTE #408: only dealing with single Term selection
-- | (hence not dealing with multiple selection, nor Branch, -- | (hence not dealing with multiple selection, nor Branch,
-- | nor Source → if so, please change the source code accordingly) -- | nor Source → if so, please change the source code accordingly)
updateTerms :: R2.Leaf () updateTerms :: R2.Leaf Props
updateTerms = R2.leaf updateTermsCpt updateTerms = R2.leaf updateTermsCpt
updateTermsCpt :: R.Component () updateTermsCpt :: R.Component Props
updateTermsCpt = here.component "main" cpt where updateTermsCpt = here.component "main" cpt where
cpt {} _ = do cpt { selectedTerm
, ngramType
} _ = do
-- | States -- | States
-- | -- |
session <- useSession
{ errors { errors
, reloadForest , reloadForest
} <- AppStore.use } <- AppStore.use
{ selectedTerm store <- PhyloStore.use
, phyloId
} <- PhyloStore.use
selectedTerm' <- R2.useLive' selectedTerm corpusId <- R2.useLive' store.corpusId
phyloId' <- R2.useLive' phyloId listId <- R2.useLive' store.listId
onPending' /\ onPending <- R2.useBox' false
-- | Behaviors -- | Behaviors
-- | -- |
let let
callback :: Unit -> Effect Unit onClick :: TermList -> Effect Unit
callback _ = pure unit onClick termList = launchAff_ do
liftEffect do
T.write_ true onPending
res <- sendPatch
termList
session
corpusId
listId
ngramType
selectedTerm
case res of
Left err -> liftEffect do
T.modify_ (A.cons $ FRESTError { error: err }) errors
here.warn2 "[sendPatches] RESTError" err
Right _ -> liftEffect do
T2.reload reloadForest
liftEffect do
T.write_ false onPending
-- | Render -- | Render
-- | -- |
...@@ -51,8 +96,10 @@ updateTermsCpt = here.component "main" cpt where ...@@ -51,8 +96,10 @@ updateTermsCpt = here.component "main" cpt where
[ [
B.button B.button
{ variant: ButtonVariant Light { variant: ButtonVariant Light
, status: Disabled , status: onPending' ?
, callback Disabled $
Enabled
, callback: const $ onClick CandidateTerm
} }
[ [
B.icon B.icon
...@@ -65,8 +112,10 @@ updateTermsCpt = here.component "main" cpt where ...@@ -65,8 +112,10 @@ updateTermsCpt = here.component "main" cpt where
, ,
B.button B.button
{ variant: ButtonVariant Light { variant: ButtonVariant Light
, status: Disabled , status: onPending' ?
, callback Disabled $
Enabled
, callback: const $ onClick StopTerm
} }
[ [
B.icon B.icon
...@@ -77,3 +126,52 @@ updateTermsCpt = here.component "main" cpt where ...@@ -77,3 +126,52 @@ updateTermsCpt = here.component "main" cpt where
H.text "Move as stop" H.text "Move as stop"
] ]
] ]
sendPatch ::
TermList
-> Session
-> CorpusId
-> ListId
-> CTabNgramType
-> String
-> AffRESTError CNT.VersionedNgramsPatches
sendPatch termList session corpusId listId tabNgramType label
= NTC.putNgramsPatches coreParams versioned
-- (!) in the future, as the like of Graph update terms, handling task
-- >>= case _ of
-- Left err -> pure $ Left err
-- Right ret -> do
-- _task <- NTC.postNgramsChartsAsync coreParams
-- pure $ Right ret
where
-- @NOTE #408: currently no versioning for Phylo
versioned :: CNT.VersionedNgramsPatches
versioned
= CNT.Versioned
{ version: 1
, data: np
}
coreParams :: CNT.CoreParams ()
coreParams
= { session
, nodeId: corpusId
, listIds: [ listId ]
, tabType: TabCorpus (TabNgramType tabNgramType)
}
term :: CNT.NgramsTerm
term = NTC.normNgram tabNgramType label
np :: CNT.NgramsPatches
np = NTC.singletonPatchMap term $ CNT.NgramsPatch
{ patch_children: mempty
, patch_list
}
patch_list :: CNT.Replace TermList
patch_list
= CNT.Replace
{ new: termList
, old: MapTerm
}
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