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
864d6c9d
Commit
864d6c9d
authored
3 years ago
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[annotationMenu] some refactorings
parent
4eb2785d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
32 deletions
+33
-32
AnnotatedField.purs
src/Gargantext/Components/Annotation/AnnotatedField.purs
+8
-7
Menu.purs
src/Gargantext/Components/Annotation/Menu.purs
+21
-18
ContextMenu.purs
src/Gargantext/Components/ContextMenu/ContextMenu.purs
+4
-7
No files found.
src/Gargantext/Components/Annotation/AnnotatedField.purs
View file @
864d6c9d
...
@@ -12,12 +12,11 @@
...
@@ -12,12 +12,11 @@
module Gargantext.Components.Annotation.AnnotatedField where
module Gargantext.Components.Annotation.AnnotatedField where
import Data.Array as A
import Data.Array as A
import Data.List (
List(..), (:), length
)
import Data.List (
List(..), (:)
)
import Data.Maybe ( Maybe(..), maybe )
import Data.Maybe ( Maybe(..), maybe )
import Data.String.Common ( joinWith )
import Data.String.Common ( joinWith )
import Data.Tuple (Tuple(..), snd)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ( (/\) )
import Data.Tuple.Nested ( (/\) )
-- import DOM.Simple.Console (log2)
import DOM.Simple.Event as DE
import DOM.Simple.Event as DE
import Effect (Effect)
import Effect (Effect)
import Reactix as R
import Reactix as R
...
@@ -28,7 +27,7 @@ import Toestand as T
...
@@ -28,7 +27,7 @@ import Toestand as T
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Components.Annotation.Menu ( annotationMenu, AnnotationMenu, MenuType(..) )
import Gargantext.Components.Annotation.Menu ( annotationMenu, AnnotationMenu, MenuType(..) )
import Gargantext.Components.Annotation.Utils (
termBootstrapClass, termClass
)
import Gargantext.Components.Annotation.Utils (
termClass
)
import Gargantext.Components.NgramsTable.Core (NgramsTable, NgramsTerm, findNgramTermList, highlightNgrams, normNgram)
import Gargantext.Components.NgramsTable.Core (NgramsTable, NgramsTerm, findNgramTermList, highlightNgrams, normNgram)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Selection as Sel
import Gargantext.Utils.Selection as Sel
...
@@ -58,7 +57,7 @@ annotatedFieldComponent = here.component "annotatedField" cpt
...
@@ -58,7 +57,7 @@ annotatedFieldComponent = here.component "annotatedField" cpt
redrawMenu <- T.useBox false
redrawMenu <- T.useBox false
redrawMenu' <- T.useLive T.unequal redrawMenu
redrawMenu' <- T.useLive T.unequal redrawMenu
menuRef <- R.useRef (Nothing :: Maybe
AnnotationMenu
)
menuRef <- R.useRef (Nothing :: Maybe
(Record AnnotationMenu)
)
let wrapperProps = { className: "annotated-field-wrapper" }
let wrapperProps = { className: "annotated-field-wrapper" }
...
@@ -77,7 +76,7 @@ compile ngrams = maybe [] (highlightNgrams CTabTerms ngrams)
...
@@ -77,7 +76,7 @@ compile ngrams = maybe [] (highlightNgrams CTabTerms ngrams)
-- Runs
-- Runs
onAnnotationSelect :: forall e. DE.IsMouseEvent e => { menuRef :: R.Ref (Maybe
AnnotationMenu
)
onAnnotationSelect :: forall e. DE.IsMouseEvent e => { menuRef :: R.Ref (Maybe
(Record AnnotationMenu)
)
, ngrams :: NgramsTable
, ngrams :: NgramsTable
, redrawMenu :: T.Box Boolean
, redrawMenu :: T.Box Boolean
, setTermList :: NgramsTerm -> Maybe TermList -> TermList -> Effect Unit }
, setTermList :: NgramsTerm -> Maybe TermList -> TermList -> Effect Unit }
...
@@ -109,7 +108,7 @@ onAnnotationSelect { menuRef, ngrams, redrawMenu, setTermList } (Just (Tuple ngr
...
@@ -109,7 +108,7 @@ onAnnotationSelect { menuRef, ngrams, redrawMenu, setTermList } (Just (Tuple ngr
-- showMenu :: forall p e. DE.IsMouseEvent e => { event :: E.SyntheticEvent e | p } -> Effect Unit
-- showMenu :: forall p e. DE.IsMouseEvent e => { event :: E.SyntheticEvent e | p } -> Effect Unit
showMenu :: forall e. DE.IsMouseEvent e => { event :: E.SyntheticEvent e
showMenu :: forall e. DE.IsMouseEvent e => { event :: E.SyntheticEvent e
, getList :: NgramsTerm -> Maybe TermList
, getList :: NgramsTerm -> Maybe TermList
, menuRef :: R.Ref (Maybe
AnnotationMenu
)
, menuRef :: R.Ref (Maybe
(Record AnnotationMenu)
)
, menuType :: MenuType
, menuType :: MenuType
, ngram :: NgramsTerm
, ngram :: NgramsTerm
, redrawMenu :: T.Box Boolean
, redrawMenu :: T.Box Boolean
...
@@ -124,9 +123,11 @@ showMenu { event, getList, menuRef, menuType, ngram, redrawMenu, setTermList } =
...
@@ -124,9 +123,11 @@ showMenu { event, getList, menuRef, menuType, ngram, redrawMenu, setTermList } =
setList t = do
setList t = do
setTermList ngram list t
setTermList ngram list t
hideMenu { menuRef, redrawMenu }
hideMenu { menuRef, redrawMenu }
here.log2 "x" x
here.log2 "y" y
E.preventDefault event
E.preventDefault event
--range <- Sel.getRange sel 0
--range <- Sel.getRange sel 0
--
log2 "[showMenu]
selection range" $ Sel.rangeToTuple range
--
here.log2 "
selection range" $ Sel.rangeToTuple range
let menu = Just
let menu = Just
{ list
{ list
, onClose: hideMenu { menuRef, redrawMenu }
, onClose: hideMenu { menuRef, redrawMenu }
...
...
This diff is collapsed.
Click to expand it.
src/Gargantext/Components/Annotation/Menu.purs
View file @
864d6c9d
...
@@ -22,37 +22,40 @@ here = R2.here "Gargantext.Components.Annotation.Menu"
...
@@ -22,37 +22,40 @@ here = R2.here "Gargantext.Components.Annotation.Menu"
data MenuType = NewNgram | SetTermListItem
data MenuType = NewNgram | SetTermListItem
type Props =
type Props =
( list :: Maybe TermList
( list
:: Maybe TermList
, menuType :: MenuType
, menuType :: MenuType
, setList :: TermList -> Effect Unit -- not a state hook setter
, setList
:: TermList -> Effect Unit -- not a state hook setter
)
)
type AnnotationMenu =
{
type AnnotationMenu =
(
x :: Number
x
:: Number
, y :: Number
, y
:: Number
, onClose :: Effect Unit
, onClose :: Effect Unit
| Props
| 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
annotationMenu :: AnnotationMenu -> R.Element
annotationMenu :: R2.Leaf AnnotationMenu
annotationMenu {x, y, list, menuType, onClose, setList} =
annotationMenu p = R.createElement annotationMenuCpt p []
CM.contextMenu {x, y, onClose} [
annotationMenuCpt :: R.Component AnnotationMenu
R.createElement annotationMenuCpt {list, menuType, setList} []
annotationMenuCpt = here.component "annotationMenu" cpt where
]
cpt { x, y, list, menuType, onClose, setList } _ = do
pure $ CM.contextMenu {x, y, onClose} [
annotationMenuCpt :: R.Component Props
annotationMenuInner { list, menuType, setList }
annotationMenuCpt = here.component "annotationMenu" cpt
]
where
cpt props _ = pure $ R.fragment $ children props
annotationMenuInner :: R2.Leaf Props
children props = A.mapMaybe (addToList props) [ MapTerm, CandidateTerm, StopTerm ]
annotationMenuInner p = R.createElement annotationMenuInnerCpt p []
annotationMenuInnerCpt :: R.Component Props
annotationMenuInnerCpt = here.component "annotationMenuInner" cpt where
cpt props _ = pure $ R.fragment $ A.mapMaybe (addToList props) [ MapTerm, 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 :: Record Props -> TermList -> Maybe R.Element
addToList :: Record Props -> TermList -> Maybe R.Element
addToList {list: Just t'} t
addToList {list: Just t'} t
| t == t' = Nothing
| t == t' = Nothing
addToList {menuType, setList} t = Just $ CM.contextMenuItem [ link ]
addToList {menuType, setList} t = Just $ CM.contextMenuItem
{}
[ link ]
where
where
link = HTML.a { on: { click }, className: className } [ HTML.text (label menuType) ]
link = HTML.a { on: { click }, className: className } [ HTML.text (label menuType) ]
label NewNgram = "Add to " <> termListName t
label NewNgram = "Add to " <> termListName t
...
...
This diff is collapsed.
Click to expand it.
src/Gargantext/Components/ContextMenu/ContextMenu.purs
View file @
864d6c9d
...
@@ -4,7 +4,6 @@ module Gargantext.Components.ContextMenu.ContextMenu where
...
@@ -4,7 +4,6 @@ module Gargantext.Components.ContextMenu.ContextMenu where
import Data.Maybe ( Maybe(..) )
import Data.Maybe ( Maybe(..) )
import Data.Nullable ( Nullable, null, toMaybe )
import Data.Nullable ( Nullable, null, toMaybe )
import Data.Tuple.Nested ( (/\) )
import Data.Traversable ( traverse_ )
import Data.Traversable ( traverse_ )
import DOM.Simple as DOM
import DOM.Simple as DOM
import DOM.Simple.Event as DE
import DOM.Simple.Event as DE
...
@@ -34,7 +33,6 @@ type Props t = (
...
@@ -34,7 +33,6 @@ type Props t = (
contextMenu :: forall t. R2.Component (Props t)
contextMenu :: forall t. R2.Component (Props t)
contextMenu = R.createElement contextMenuCpt
contextMenu = R.createElement contextMenuCpt
contextMenuCpt :: forall t. R.Component (Props t)
contextMenuCpt :: forall t. R.Component (Props t)
contextMenuCpt = here.component "contextMenu" cpt
contextMenuCpt = here.component "contextMenu" cpt
where
where
...
@@ -64,13 +62,13 @@ contextMenuCpt = here.component "contextMenu" cpt
...
@@ -64,13 +62,13 @@ contextMenuCpt = here.component "contextMenu" cpt
, key: "context-menu"
, key: "context-menu"
, className: "context-menu"
, className: "context-menu"
, style: position menu rect
, style: position menu rect
, data: {
toggle: "popover", placement: "right"
}
, data: {
placement: "right", toggle: "popover"
}
}
}
elems ref _ _ = HTML.div
elems ref _ _ = HTML.div
{ ref
{ ref
, key: "context-menu"
, key: "context-menu"
, className: "context-menu"
, className: "context-menu"
, data: {
toggle: "popover", placement: "right"
}
, data: {
placement: "right", toggle: "popover"
}
}
}
contextMenuEffect
contextMenuEffect
...
@@ -108,9 +106,8 @@ position mouse {width: menuWidth, height: menuHeight} = {left, top}
...
@@ -108,9 +106,8 @@ position mouse {width: menuWidth, height: menuHeight} = {left, top}
screenWidth = window .. "innerWidth"
screenWidth = window .. "innerWidth"
screenHeight = window .. "innerHeight"
screenHeight = window .. "innerHeight"
contextMenuItem :: Array R.Element -> R.Element
contextMenuItem :: R2.Component ()
contextMenuItem = R.createElement contextMenuItemCpt {}
contextMenuItem = R.createElement contextMenuItemCpt
contextMenuItemCpt :: R.Component ()
contextMenuItemCpt :: R.Component ()
contextMenuItemCpt = here.component "contextMenuItem" cpt
contextMenuItemCpt = here.component "contextMenuItem" cpt
where
where
...
...
This diff is collapsed.
Click to expand it.
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