[nlp] add more languages to web search

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