NgramsTable,Document,Annotations: refactoring

parent f5c6e917
...@@ -14,22 +14,18 @@ module Gargantext.Components.Annotation.AnnotatedField where ...@@ -14,22 +14,18 @@ module Gargantext.Components.Annotation.AnnotatedField where
import Prelude import Prelude
import Data.Map as Map import Data.Map as Map
import Data.Maybe ( Maybe(..), maybe, maybe' ) import Data.Maybe ( Maybe(..), maybe, maybe' )
import Data.Lens ( Lens', lens )
import Data.Traversable ( traverse_ )
import Data.Tuple ( Tuple(..) ) import Data.Tuple ( Tuple(..) )
import Data.Tuple.Nested ( (/\) ) import Data.Tuple.Nested ( (/\) )
import DOM.Simple.Console
import DOM.Simple.Event as DE import DOM.Simple.Event as DE
import Effect ( Effect ) import Effect ( Effect )
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried ( mkEffectFn1 )
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as HTML import Reactix.DOM.HTML as HTML
import Reactix.SyntheticEvent as E import Reactix.SyntheticEvent as E
import Gargantext.Types ( TermList(..) ) import Gargantext.Types ( TermList )
import Gargantext.Components.Annotation.Utils ( termClass ) import Gargantext.Components.Annotation.Utils ( termClass )
import Gargantext.Components.NgramsTable ( NgramsTable(..), highlightNgrams ) import Gargantext.Components.NgramsTable.Core ( NgramsTable(..), highlightNgrams )
import Gargantext.Components.ContextMenu.ContextMenu as CM
import Gargantext.Components.Annotation.Menu ( AnnotationMenu, annotationMenu ) import Gargantext.Components.Annotation.Menu ( AnnotationMenu, annotationMenu )
import Gargantext.Utils.Selection as Sel import Gargantext.Utils.Selection as Sel
...@@ -68,8 +64,7 @@ compile props = runs props.text ...@@ -68,8 +64,7 @@ compile props = runs props.text
where runs = maybe [] (highlightNgrams props.ngrams) where runs = maybe [] (highlightNgrams props.ngrams)
maybeShowMenu maybeShowMenu
:: forall t :: (Maybe AnnotationMenu -> Effect Unit)
. (Maybe AnnotationMenu -> Effect Unit)
-> NgramsTable -> NgramsTable
-> E.SyntheticEvent DE.MouseEvent -> E.SyntheticEvent DE.MouseEvent
-> Effect Unit -> Effect Unit
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Gargantext.Components.Annotation.Menu where module Gargantext.Components.Annotation.Menu where
import Prelude ( Unit, (==), ($), (<>), unit, pure ) import Prelude ( Unit, (==), ($), (<>), unit, pure, otherwise )
import Data.Array as A import Data.Array as A
import Data.Maybe ( Maybe(..), maybe' ) import Data.Maybe ( Maybe(..), maybe' )
import Effect ( Effect ) import Effect ( Effect )
...@@ -18,7 +18,7 @@ import Gargantext.Components.ContextMenu.ContextMenu as CM ...@@ -18,7 +18,7 @@ import Gargantext.Components.ContextMenu.ContextMenu as CM
type Props = ( list :: Maybe TermList ) type Props = ( list :: Maybe TermList )
type AnnotationMenu = { x :: Number, y :: Number, list :: Maybe TermList } type AnnotationMenu = { x :: Number, y :: Number | Props }
-- | An Annotation Menu is parameterised by a Maybe Termlist of the -- | An Annotation Menu is parameterised by a Maybe Termlist of the
-- | TermList the currently selected text belongs to -- | TermList the currently selected text belongs to
...@@ -29,21 +29,20 @@ annotationMenu setMenu { x,y,list } = ...@@ -29,21 +29,20 @@ annotationMenu setMenu { x,y,list } =
annotationMenuCpt :: R.Component Props annotationMenuCpt :: R.Component Props
annotationMenuCpt = R.hooksComponent "Annotation.Menu" cpt annotationMenuCpt = R.hooksComponent "Annotation.Menu" cpt
where where
cpt { list } _ = pure $ R.fragment $ children list cpt props _ = pure $ R.fragment $ children props
children l = A.mapMaybe (\l' -> addToList l' l) [ GraphTerm, CandidateTerm, StopTerm ] children props = A.mapMaybe (addToList props) [ GraphTerm, CandidateTerm, StopTerm ]
-- | Given the TermList to render the item for zand the Maybe TermList the item may belong to, possibly render the menuItem -- | Given the TermList to render the item for zand the Maybe TermList the item may belong to, possibly render the menuItem
addToList :: TermList -> Maybe TermList -> Maybe R.Element addToList :: Record Props -> TermList -> Maybe R.Element
addToList t (Just t') addToList {list: Just t'} t
| t == t' = Nothing | t == t' = Nothing
| true = addToList t Nothing addToList props t = Just $ CM.contextMenuItem [ link ]
addToList t _ = Just $ CM.contextMenuItem [ link ]
where link = HTML.a { onClick: click, className: className } [ HTML.text label ] where link = HTML.a { onClick: click, className: className } [ HTML.text label ]
label = "Add to " <> termListName t label = "Add to " <> termListName t
className = termClass t className = termClass t
click = mkEffectFn1 $ \_ -> addToTermList t click = mkEffectFn1 $ \_ -> addToTermList props t
-- TODO: what happens when we add to a term list? -- TODO: what happens when we add to a term list?
addToTermList :: TermList -> Effect Unit addToTermList :: Record Props -> TermList -> Effect Unit
addToTermList _ = pure unit addToTermList _ _ = pure unit
This diff is collapsed.
This diff is collapsed.
...@@ -21,7 +21,7 @@ import Gargantext.Prelude ...@@ -21,7 +21,7 @@ import Gargantext.Prelude
import Gargantext.Config (toUrl, NodeType(..), End(..), TabSubType(..), TabType(..), CTabNgramType(..)) import Gargantext.Config (toUrl, NodeType(..), End(..), TabSubType(..), TabType(..), CTabNgramType(..))
import Gargantext.Config.REST (get) import Gargantext.Config.REST (get)
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.NgramsTable (NgramsTable(..), NgramsElement(..), loadNgramsTable, Versioned(..)) import Gargantext.Components.NgramsTable.Core (NgramsTable(..), NgramsElement(..), loadNgramsTable, Versioned(..))
import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField import Gargantext.Components.Annotation.AnnotatedField as AnnotatedField
import Gargantext.Types (TermList(..)) import Gargantext.Types (TermList(..))
import Gargantext.Utils.Reactix ( scuff ) import Gargantext.Utils.Reactix ( scuff )
......
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