Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
fa04a893
Commit
fa04a893
authored
Jul 08, 2022
by
arturo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[phylo] Change ngram for selected terms
parent
6345d0d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
15 deletions
+116
-15
SelectionTab.purs
...antext/Components/PhyloExplorer/Sidebar/SelectionTab.purs
+4
-1
UpdateTerms.purs
...gantext/Components/PhyloExplorer/Sidebar/UpdateTerms.purs
+112
-14
No files found.
src/Gargantext/Components/PhyloExplorer/Sidebar/SelectionTab.purs
View file @
fa04a893
...
...
@@ -17,6 +17,7 @@ import Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms (updateTerms)
import Gargantext.Components.PhyloExplorer.Store as PhyloStore
import Gargantext.Components.PhyloExplorer.Types (ExtractedCount(..), ExtractedTerm(..), defaultCacheParams)
import Gargantext.Hooks.FirstEffect (useFirstEffect')
import Gargantext.Types (CTabNgramType(..))
import Gargantext.Utils (nbsp, setter, (?))
import Gargantext.Utils.Reactix as R2
import Reactix as R
...
...
@@ -230,7 +231,9 @@ component = here.component "main" cpt where
{ className: "phylo-selection-tab__highlight__actions" }
[
updateTerms
{}
{ selectedTerm: s
, ngramType: CTabTerms
}
]
]
]
...
...
src/Gargantext/Components/PhyloExplorer/Sidebar/UpdateTerms.purs
View file @
fa04a893
...
...
@@ -2,45 +2,90 @@ module Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms where
import Gargantext.Prelude
import Data.Array as A
import Data.Either (Either(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store as AppStore
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), ComponentStatus(..), Variant(..))
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.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.PhyloExplorer.Sidebar.UpdateTerms"
type Props =
( selectedTerm :: String
, ngramType :: CTabNgramType
)
-- | @NOTE #408: only dealing with single Term selection
-- | (hence not dealing with multiple selection, nor Branch,
-- | nor Source → if so, please change the source code accordingly)
updateTerms :: R2.Leaf
()
updateTerms :: R2.Leaf
Props
updateTerms = R2.leaf updateTermsCpt
updateTermsCpt :: R.Component
()
updateTermsCpt :: R.Component
Props
updateTermsCpt = here.component "main" cpt where
cpt {} _ = do
cpt { selectedTerm
, ngramType
} _ = do
-- | States
-- |
session <- useSession
{ errors
, reloadForest
} <- AppStore.use
{ selectedTerm
, phyloId
} <- PhyloStore.use
store <- PhyloStore.use
selectedTerm' <- R2.useLive' selectedTerm
phyloId' <- R2.useLive' phyloId
corpusId <- R2.useLive' store.corpusId
listId <- R2.useLive' store.listId
onPending' /\ onPending <- R2.useBox' false
-- | Behaviors
-- |
let
callback :: Unit -> Effect Unit
callback _ = pure unit
onClick :: TermList -> Effect 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
-- |
...
...
@@ -51,8 +96,10 @@ updateTermsCpt = here.component "main" cpt where
[
B.button
{ variant: ButtonVariant Light
, status: Disabled
, callback
, status: onPending' ?
Disabled $
Enabled
, callback: const $ onClick CandidateTerm
}
[
B.icon
...
...
@@ -65,8 +112,10 @@ updateTermsCpt = here.component "main" cpt where
,
B.button
{ variant: ButtonVariant Light
, status: Disabled
, callback
, status: onPending' ?
Disabled $
Enabled
, callback: const $ onClick StopTerm
}
[
B.icon
...
...
@@ -77,3 +126,52 @@ updateTermsCpt = here.component "main" cpt where
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment