[nlp] add more languages to web search

parent 2c0fd49f
......@@ -71,9 +71,9 @@ component = R.hooksComponent componentName cpt where
,
H.div
{ className: intercalate " "
[ "progress-text"
[ "progress-text"
, props.waitingTextClass
]
}
}
[ H.text "Waiting task..." ]
]
......@@ -6,10 +6,13 @@ module Gargantext.Components.Bootstrap.FormSelect
import Gargantext.Prelude
import Data.Foldable (elem, intercalate)
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), Sizing(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Show as GUS
import Reactix as R
import Reactix.DOM.HTML as H
import Unsafe.Coerce (unsafeCoerce)
......@@ -140,14 +143,12 @@ type AnyTypeProps a =
-- | to the provided `list` prop. You can add additional HTML option within
-- | the `children` prop
formSelect' :: forall r a.
Read a
=> Show a
Show a
=> R2.OptComponent Options (AnyTypeProps a) r
formSelect' = R2.optComponent component' options
component' :: forall a.
Read a
=> Show a
Show a
=> R.Component (AnyTypeProps a)
component' = R.hooksComponent (componentName <> "__helper") cpt where
cpt props@{ callback
......@@ -170,7 +171,7 @@ component' = R.hooksComponent (componentName <> "__helper") cpt where
-- Behaviors
let
change = onChange' status callback
change = onChange' status reader callback
-- Render
pure $
......@@ -190,21 +191,23 @@ component' = R.hooksComponent (componentName <> "__helper") cpt where
{ value: show raw }
[ H.text $ show raw ]
)
where
reader = GUS.reader list
-- | * Change event will effectively be triggered according to the
-- | component status props
-- | * Also directly returns the newly input value
-- | (usage not so different from `targetValue` of ReactBasic)
onChange' :: forall event a.
Read a
=> Show a
Show a
=> ComponentStatus
-> (String -> Maybe a)
-> (a -> Effect Unit)
-> event
-> Effect Unit
onChange' status callback event = do
onChange' status reader callback event = do
if status == Enabled
then event # unsafeCoerce >>> _.target.value >>> read >>> case _ of
then event # unsafeCoerce >>> _.target.value >>> reader >>> case _ of
Nothing -> R.nothing
Just v -> callback v
else R.nothing
......@@ -23,7 +23,7 @@ import Gargantext.Components.Forest.Tree.Node.Action (Props)
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileFormat(..), FileType(..), UploadFileBlob(..), readUFBAsBase64, readUFBAsText)
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, formChoiceSafe, panel)
import Gargantext.Components.Lang (Lang(..))
import Gargantext.Components.Lang (Lang(..), langReader)
import Gargantext.Components.ListSelection as ListSelection
import Gargantext.Components.ListSelection.Types (Selection(..))
import Gargantext.Components.ListSelection.Types as ListSelection
......@@ -147,7 +147,7 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
]
, R2.row
[ H.div {className:"col-6 flex-space-around"}
[ formChoiceSafe { items: [EN, FR, No_extraction]
[ formChoiceSafe { items: [EN, FR, DE, ES, IT, PL, CN, No_extraction]
, default: EN
, callback: setLang'
, print: show
......@@ -487,7 +487,7 @@ fileTypeViewCpt = here.component "fileTypeView" cpt
onChange e l =
T.write_ (Just $ DroppedFile $ { blob
, fileType: read $ R.unsafeEventValue e
, lang : fromMaybe EN $ read $ R.unsafeEventValue l
, lang : fromMaybe EN $ langReader $ R.unsafeEventValue l
}) droppedFile
renderOption opt = H.option {} [ H.text $ show opt ]
......
......@@ -16,6 +16,7 @@ import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Types as GT
import Gargantext.Utils (toggleSet)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Show as GUS
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
......@@ -179,11 +180,10 @@ type FormChoiceSafeProps item m =
-- | Form Choice input
-- if the list of options is not big enough, a button is used instead
formChoiceSafe :: forall item m
. Read item
=> Show item
. Show item
=> R2.Component (FormChoiceSafeProps item m)
formChoiceSafe = R.createElement formChoiceSafeCpt
formChoiceSafeCpt :: forall item m. Read item => Show item => R.Component (FormChoiceSafeProps item m)
formChoiceSafeCpt :: forall item m. Show item => R.Component (FormChoiceSafeProps item m)
formChoiceSafeCpt = here.component "formChoiceSafe" cpt where
cpt { items, default, callback, print } _ = do
pure $ case items of
......@@ -199,11 +199,10 @@ type FormChoiceProps item m =
-- | List Form
formChoice :: forall item m
. Read item
=> Show item
. Show item
=> R2.Component (FormChoiceProps item m)
formChoice = R.createElement formChoiceCpt
formChoiceCpt :: forall item m. Read item => Show item => R.Component (FormChoiceProps item m)
formChoiceCpt :: forall item m. Show item => R.Component (FormChoiceProps item m)
formChoiceCpt = here.component "formChoice" cpt where
cpt { items, callback, default, print } _ = do
pure $ H.div { className: "form-group"}
......@@ -216,10 +215,12 @@ formChoiceCpt = here.component "formChoice" cpt where
]
where
change e = callback $ fromMaybe default $ read $ R.unsafeEventValue e
change e = callback $ fromMaybe default $ reader $ R.unsafeEventValue e
option opt = H.option { value: show opt } [ H.text $ print opt ]
reader = GUS.reader items
type FormButtonProps item m =
( item :: item
, callback :: item -> Effect m
......@@ -263,7 +264,7 @@ type Href = String
submitButtonHref :: Action -> Href -> R.Element
submitButtonHref action href =
H.a { className, href, target: "_blank" }
H.a { className, href, target: "_blank" }
[ H.span {className: "font-family-theme mx-1"} [ H.text $ " " <> text action ] ]
where
className = "btn btn-primary fa fa-" <> icon action
......
......@@ -8,7 +8,9 @@ import Data.Generic.Rep (class Generic)
import Data.Lens.Lens.Product (_1)
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
import Data.Show.Generic (genericShow)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Show as GUS
import Reactix as R
import Reactix.DOM.HTML as H
import Simple.JSON as JSON
......@@ -21,27 +23,27 @@ here = R2.here "Gargantext.Components.Lang"
allLangs :: Array Lang
allLangs = [ EN
, FR
, DE
, ES
, IT
, PL
, CN
, Universal
, No_extraction
]
data Lang = FR | EN | Universal | No_extraction
data Lang = FR | EN | DE | ES | IT | PL | CN | Universal | No_extraction
derive instance Generic Lang _
instance Show Lang where
show FR = "FR"
show EN = "EN"
show Universal = "All"
show No_extraction = "Nothing"
show s = genericShow s
derive instance Eq Lang
instance Read Lang where
read "FR" = Just FR
read "EN" = Just EN
read "All" = Just Universal
read "Nothing" = Just No_extraction
read _ = Nothing
langReader :: String -> Maybe Lang
langReader = GUS.reader allLangs
derive instance Eq Lang
instance EncodeJson Lang where
encodeJson a = encodeJson (show a)
......
......@@ -33,7 +33,6 @@ type AsyncProps =
asyncProgress :: R2.Component AsyncProps
asyncProgress = R2.component component
component :: R.Component AsyncProps
component = R.hooksComponent "asyncProgressContext" cpt where
cpt props@{ errors
......
module Gargantext.Utils.Show where
import Data.Map as Map
import Data.Maybe (Maybe)
import Data.Tuple (Tuple(..))
import Gargantext.Prelude
-- | Derive a generic reader from items for which a `Show` class is
-- | implemented. The `Read` type class is not present in PureScript
-- | and is generally discouraged.
-- | https://discourse.purescript.org/t/read-type-class/1434/5
reader :: forall item. Show item => Array item -> (String -> Maybe item)
reader items = reader
where
strMap :: Map.Map String item
strMap = Map.fromFoldable $ (\i -> Tuple (show i) i) <$> items
reader k = Map.lookup k strMap
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