Commit fabbad07 authored by arturo's avatar arturo

[docs] UI/UX improvements

* #386
* #392
parent 3ac13e92
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
-- | A ContextMenU that allows you to add terms to a list module Gargantext.Components.Annotation.Menu
module Gargantext.Components.Annotation.Menu where ( annotationMenu
, AnnotationMenu
) where
import Gargantext.Prelude
import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Eq.Generic (genericEq)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.String (toLower)
import Effect (Effect) import Effect (Effect)
import Reactix as R import Gargantext.Components.Annotation.Types (MenuType(..), termClass)
import Reactix.DOM.HTML as HTML import Gargantext.Components.Bootstrap as B
import Toestand as T import Gargantext.Components.Bootstrap.Types (ComponentStatus(..))
import Gargantext.Prelude
import Gargantext.Types (TermList(..), termListName) import Gargantext.Types (TermList(..), termListName)
import Gargantext.Components.Annotation.Utils (termBootstrapClass)
import Gargantext.Components.ContextMenu.ContextMenu as CM
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Annotation.Menu" here = R2.here "Gargantext.Components.Annotation.Menu"
data MenuType = NewNgram | SetTermListItem
derive instance Generic MenuType _
instance Eq MenuType where
eq = genericEq
type Props = type Props =
( list :: Maybe TermList ( menuRef :: R.Ref (Maybe (Record AnnotationMenu))
, menuType :: MenuType
, setList :: TermList -> Effect Unit -- not a state hook setter
) )
type AnnotationMenu = ( type AnnotationMenu =
onClose :: Effect Unit ( closeCallback :: Unit -> Effect Unit
, redrawMenu :: T.Box Boolean , redrawMenu :: T.Box Boolean
, x :: Number , x :: Number
, y :: Number , y :: Number
| Props , list :: Maybe TermList
, menuType :: MenuType
, setList :: TermList -> Effect Unit -- not a state hook setter
) )
type AnnotationMenuWrapper = annotationMenu :: R2.Leaf Props
( annotationMenu = R2.leaf annotationMenuCpt
menuRef :: R.Ref (Maybe (Record AnnotationMenu))
)
eqAnnotationMenu :: Record AnnotationMenu -> Record AnnotationMenu -> Boolean annotationMenuCpt :: R.Component Props
eqAnnotationMenu new old = new.list == old.list && annotationMenuCpt = here.component "main" cpt where
new.menuType == old.menuType &&
new.x == old.x &&
new.y == old.y
eqAnnotationMenuWrapper :: { new :: Maybe (Record AnnotationMenu)
, old :: Maybe (Record AnnotationMenu) } -> Effect Boolean
eqAnnotationMenuWrapper { new: Nothing, old: Nothing } = pure $ true
eqAnnotationMenuWrapper { new: Nothing, old: Just _ } = pure $ false
eqAnnotationMenuWrapper { new: Just _, old: Nothing } = pure $ false
eqAnnotationMenuWrapper { new: Just n, old: Just o } = pure $ eqAnnotationMenu n o
annotationMenuWrapper :: R2.Leaf AnnotationMenuWrapper
annotationMenuWrapper = R2.leafComponent annotationMenuWrapperCpt
annotationMenuWrapperCpt :: R.Component AnnotationMenuWrapper
annotationMenuWrapperCpt = here.component "annotationMenuWrapper" cpt where
cpt { menuRef } _ = do cpt { menuRef } _ = do
case R.readRef menuRef of -- Render
Nothing -> pure $ HTML.div {} [] pure $
Just menu -> pure $ annotationMenu menu
R2.fromMaybe (R.readRef menuRef) \props' ->
-- | An Annotation Menu is parameterised by a Maybe Termlist of the
-- | TermList the currently selected text belongs to B.contextMenu
annotationMenu :: R2.Leaf AnnotationMenu { x: props'.x
annotationMenu = R2.leafComponent annotationMenuCpt , y: props'.y
annotationMenuCpt :: R.Component AnnotationMenu , closeCallback: props'.closeCallback
annotationMenuCpt = here.component "annotationMenu" cpt where } $
cpt { x, y, list, menuType, onClose, redrawMenu, setList } _ = do (addToList props') <$> [ MapTerm, CandidateTerm, StopTerm ]
redrawMenu' <- T.useLive T.unequal redrawMenu
--------------------------------------------------------------------------
pure $ CM.contextMenu {x, y, onClose} [
annotationMenuInner { list, menuType, setList } -- addToList :: Record AnnotationMenu -> TermList -> Maybe R.Element
] -- addToList {list: Just t'} t
-- | t == t' = Nothing
annotationMenuInner :: R2.Leaf Props
annotationMenuInner = R2.leafComponent annotationMenuInnerCpt -- addToList {menuType, setList} t = Just $
annotationMenuInnerCpt :: R.Component Props -- B.contextMenuItem
annotationMenuInnerCpt = here.component "annotationMenuInner" cpt where -- { callback: click }
cpt props _ = pure $ R.fragment $ A.mapMaybe (addToList props) [ MapTerm, CandidateTerm, StopTerm ] -- [
-- B.icon
-- | Given the TermList to render the item for zand the Maybe TermList the item may belong to, possibly render the menuItem -- { name: "circle"
addToList :: Record Props -> TermList -> Maybe R.Element -- , className: "mr-2 " <> termClass t
addToList {list: Just t'} t -- }
| t == t' = Nothing -- ,
addToList {menuType, setList} t = Just $ CM.contextMenuItem {} [ link ] -- H.text (label menuType)
where -- ]
link = HTML.a { on: { click }, className: className } [ HTML.text (label menuType) ]
label NewNgram = "Add to " <> termListName t -- where
label SetTermListItem = "Change to " <> termListName t -- label NewNgram = "Add to " <> (toLower $ termListName t)
className = "list-group-item list-group-item-" <> (termBootstrapClass t) -- label SetTermListItem = "Change to " <> (toLower $ termListName t)
click _ = setList t -- click _ = setList t
addToList :: Record AnnotationMenu -> TermList -> R.Element
addToList {list: Just t', menuType} t
| t == t' =
B.contextMenuItem
{ callback: const R.nothing
, status: Disabled
}
[
B.icon
{ name: "circle"
, className: "mr-2 disabled-term"
}
,
H.text (label t menuType)
]
addToList {menuType, setList} t =
B.contextMenuItem
{ callback: const $ setList t }
[
B.icon
{ name: "circle"
, className: "mr-2 " <> termClass t
}
,
H.text (label t menuType)
]
label :: TermList -> MenuType -> String
label t NewNgram = "Add to " <> (toLower $ termListName t)
label t SetTermListItem = "Change to " <> (toLower $ termListName t)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
'use strict';
exports._add = add; exports._add = add;
exports._remove = remove; exports._remove = remove;
/** /**
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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