Commit a339e7d9 authored by arturo's avatar arturo

>>> continue

parent 388f48fc
Pipeline #2521 failed with stage
in 0 seconds
...@@ -3,6 +3,8 @@ module Gargantext.Components.PhyloExplorer.API ...@@ -3,6 +3,8 @@ module Gargantext.Components.PhyloExplorer.API
, UpdateData(..) , UpdateData(..)
, TimeUnit(..), ReflexiveTimeUnit(..), TimeUnitCriteria(..) , TimeUnit(..), ReflexiveTimeUnit(..), TimeUnitCriteria(..)
, Clique(..), ReflexiveClique(..), CliqueFilter(..) , Clique(..), ReflexiveClique(..), CliqueFilter(..)
, toReflexiveTimeUnit, fromReflexiveTimeUnit, extractCriteria
, toReflexiveClique
, update, updateProgress , update, updateProgress
) where ) where
...@@ -11,6 +13,7 @@ import Gargantext.Prelude ...@@ -11,6 +13,7 @@ import Gargantext.Prelude
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
import Data.Show.Generic (genericShow) import Data.Show.Generic (genericShow)
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Gargantext.Components.PhyloExplorer.JSON (PhyloJSONSet) import Gargantext.Components.PhyloExplorer.JSON (PhyloJSONSet)
...@@ -170,11 +173,11 @@ instance Show ReflexiveTimeUnit where show = genericShow ...@@ -170,11 +173,11 @@ instance Show ReflexiveTimeUnit where show = genericShow
instance Read ReflexiveTimeUnit where instance Read ReflexiveTimeUnit where
read :: String -> Maybe ReflexiveTimeUnit read :: String -> Maybe ReflexiveTimeUnit
read = case _ of read = case _ of
"Epoch" -> Just Epoch_ "Epoch_" -> Just Epoch_
"Year" -> Just Year_ "Year_" -> Just Year_
"Month" -> Just Month_ "Month_" -> Just Month_
"Week" -> Just Week_ "Week_" -> Just Week_
"Day" -> Just Day_ "Day_" -> Just Day_
_ -> Nothing _ -> Nothing
...@@ -186,6 +189,7 @@ newtype TimeUnitCriteria = TimeUnitCriteria ...@@ -186,6 +189,7 @@ newtype TimeUnitCriteria = TimeUnitCriteria
derive instance Generic TimeUnitCriteria _ derive instance Generic TimeUnitCriteria _
derive instance Eq TimeUnitCriteria derive instance Eq TimeUnitCriteria
derive instance Newtype TimeUnitCriteria _
instance Show TimeUnitCriteria where show = genericShow instance Show TimeUnitCriteria where show = genericShow
derive newtype instance JSON.ReadForeign TimeUnitCriteria derive newtype instance JSON.ReadForeign TimeUnitCriteria
...@@ -245,8 +249,8 @@ instance Show ReflexiveClique where show = genericShow ...@@ -245,8 +249,8 @@ instance Show ReflexiveClique where show = genericShow
instance Read ReflexiveClique where instance Read ReflexiveClique where
read :: String -> Maybe ReflexiveClique read :: String -> Maybe ReflexiveClique
read = case _ of read = case _ of
"FIS" -> Just FIS_ "FIS_" -> Just FIS_
"MaxClique" -> Just MaxClique_ "MaxClique_" -> Just MaxClique_
_ -> Nothing _ -> Nothing
...@@ -260,11 +264,39 @@ instance JSON.WriteForeign CliqueFilter where writeImpl = JSON.writeImpl <<< sho ...@@ -260,11 +264,39 @@ instance JSON.WriteForeign CliqueFilter where writeImpl = JSON.writeImpl <<< sho
instance Read CliqueFilter where instance Read CliqueFilter where
read :: String -> Maybe CliqueFilter read :: String -> Maybe CliqueFilter
read = case _ of read = case _ of
"ByTreshold" -> Just ByThreshold "ByThreshold" -> Just ByThreshold
"ByNeighbours" -> Just ByNeighbours "ByNeighbours" -> Just ByNeighbours
_ -> Nothing _ -> Nothing
toReflexiveTimeUnit :: TimeUnit -> ReflexiveTimeUnit
toReflexiveTimeUnit (Epoch _) = Epoch_
toReflexiveTimeUnit (Year _) = Year_
toReflexiveTimeUnit (Month _) = Month_
toReflexiveTimeUnit (Week _) = Week_
toReflexiveTimeUnit (Day _) = Day_
fromReflexiveTimeUnit :: ReflexiveTimeUnit -> TimeUnitCriteria -> TimeUnit
fromReflexiveTimeUnit Epoch_ c = Epoch c
fromReflexiveTimeUnit Year_ c = Year c
fromReflexiveTimeUnit Month_ c = Month c
fromReflexiveTimeUnit Week_ c = Week c
fromReflexiveTimeUnit Day_ c = Day c
extractCriteria :: TimeUnit -> TimeUnitCriteria
extractCriteria (Epoch (o :: TimeUnitCriteria)) = o
extractCriteria (Year (o :: TimeUnitCriteria)) = o
extractCriteria (Month (o :: TimeUnitCriteria)) = o
extractCriteria (Week (o :: TimeUnitCriteria)) = o
extractCriteria (Day (o :: TimeUnitCriteria)) = o
toReflexiveClique :: Clique -> ReflexiveClique
toReflexiveClique (FIS _) = FIS_
toReflexiveClique (MaxClique _) = MaxClique_
update :: update ::
Session Session
-> NodeID -> NodeID
......
...@@ -8,13 +8,15 @@ import DOM.Simple.Console (log, log3) ...@@ -8,13 +8,15 @@ import DOM.Simple.Console (log, log3)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Foldable (foldl, intercalate) import Data.Foldable (foldl, intercalate)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..)) import Data.Int as Int
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Newtype (unwrap)
import Data.Number as Number import Data.Number as Number
import Data.Show.Generic (genericShow) import Data.Show.Generic (genericShow)
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.Bootstrap as B import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), ComponentStatus(..), Variant(..)) import Gargantext.Components.Bootstrap.Types (ButtonVariant(..), ComponentStatus(..), Variant(..))
import Gargantext.Components.PhyloExplorer.API (Clique(..), CliqueFilter(..), ReflexiveClique(..), ReflexiveTimeUnit(..), TimeUnit(..), TimeUnitCriteria(..), UpdateData(..)) import Gargantext.Components.PhyloExplorer.API (Clique(..), CliqueFilter(..), ReflexiveClique(..), ReflexiveTimeUnit(..), TimeUnit(..), TimeUnitCriteria(..), UpdateData(..), extractCriteria, fromReflexiveTimeUnit, toReflexiveTimeUnit)
import Gargantext.Config.REST (AffRESTError) import Gargantext.Config.REST (AffRESTError)
import Gargantext.Hooks.FormValidation (VForm, useFormValidation) import Gargantext.Hooks.FormValidation (VForm, useFormValidation)
import Gargantext.Hooks.FormValidation.Unboxed as FV import Gargantext.Hooks.FormValidation.Unboxed as FV
...@@ -23,7 +25,7 @@ import Gargantext.Hooks.StateRecord.Behaviors (setter) ...@@ -23,7 +25,7 @@ import Gargantext.Hooks.StateRecord.Behaviors (setter)
import Gargantext.Routes as GR import Gargantext.Routes as GR
import Gargantext.Sessions (Session, post, get) import Gargantext.Sessions (Session, post, get)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils (nbsp, (?)) import Gargantext.Utils (getter, nbsp, (?))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
...@@ -53,7 +55,11 @@ component = R.hooksComponent "configForm" cpt where ...@@ -53,7 +55,11 @@ component = R.hooksComponent "configForm" cpt where
cpt props _ = do cpt props _ = do
-- Hooks -- Hooks
{ state, bindStateKey, stateBox, setStateKey } <- useStateRecord (pick props :: Record FormData) { state
, bindStateKey
, stateBox
, setStateKey
} <- useStateRecord $ parseFormData (pick props :: Record FormData)
fv <- useFormValidation fv <- useFormValidation
R.useEffect1' state $ log state R.useEffect1' state $ log state
...@@ -68,7 +74,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -68,7 +74,7 @@ component = R.hooksComponent "configForm" cpt where
result <- pure $ Right state result <- pure $ Right state
case result of case result of
Left err -> log3 "configForm validation error" state err Left err -> log3 "configForm validation error" state err
Right _ -> props.callback state Right _ -> props.callback $ parseRawData state
-- Render -- Render
...@@ -98,11 +104,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -98,11 +104,7 @@ component = R.hooksComponent "configForm" cpt where
[ [
B.formInput $ B.formInput $
{ type: "number" { type: "number"
, value: show state.proximity } `merge` bindStateKey "proximity"
, callback: Number.fromString >>> case _ of
Nothing -> pure unit
Just v -> setter stateBox "proximity" v
}
, ,
R2.if' (fv.hasError' "proximity") $ R2.if' (fv.hasError' "proximity") $
H.div H.div
...@@ -133,7 +135,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -133,7 +135,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "synchrony" { type: "number"
} `merge` bindStateKey "synchrony"
, ,
R2.if' (fv.hasError' "synchrony") $ R2.if' (fv.hasError' "synchrony") $
H.div H.div
...@@ -164,7 +167,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -164,7 +167,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "quality" { type: "number"
} `merge` bindStateKey "quality"
, ,
R2.if' (fv.hasError' "quality") $ R2.if' (fv.hasError' "quality") $
H.div H.div
...@@ -195,7 +199,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -195,7 +199,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "exportFilter" { type: "number"
} `merge` bindStateKey "exportFilter"
, ,
R2.if' (fv.hasError' "exportFilter") $ R2.if' (fv.hasError' "exportFilter") $
H.div H.div
...@@ -227,12 +232,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -227,12 +232,7 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formSelect B.formSelect
{ value: show state.granularity (bindStateKey "granularity")
, callback: read >>> case _ of
Nothing -> pure unit
Just (v :: ReflexiveTimeUnit) ->
setter stateBox "granularity" v
}
[ [
H.option H.option
{ value: show Year_ } { value: show Year_ }
...@@ -273,7 +273,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -273,7 +273,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "period" { type: "number"
} `merge` bindStateKey "period"
, ,
R2.if' (fv.hasError' "period") $ R2.if' (fv.hasError' "period") $
H.div H.div
...@@ -304,7 +305,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -304,7 +305,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "step" { type: "number"
} `merge` bindStateKey "step"
, ,
R2.if' (fv.hasError' "step") $ R2.if' (fv.hasError' "step") $
H.div H.div
...@@ -335,7 +337,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -335,7 +337,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "matchingFrame" { type: "number"
} `merge` bindStateKey "matchingFrame"
, ,
R2.if' (fv.hasError' "matchingFrame") $ R2.if' (fv.hasError' "matchingFrame") $
H.div H.div
...@@ -375,7 +378,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -375,7 +378,7 @@ component = R.hooksComponent "configForm" cpt where
B.button B.button
{ callback: \_ -> setter stateBox "cliqueType" FIS_ { callback: \_ -> setter stateBox "cliqueType" FIS_
, variant: OutlinedButtonVariant Secondary , variant: OutlinedButtonVariant Secondary
, className: state.cliqueType == FIS_ ? , className: state.cliqueType == show FIS_ ?
"active" $ "active" $
"" ""
} }
...@@ -386,7 +389,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -386,7 +389,7 @@ component = R.hooksComponent "configForm" cpt where
B.button B.button
{ callback: \_ -> setter stateBox "cliqueType" MaxClique_ { callback: \_ -> setter stateBox "cliqueType" MaxClique_
, variant: OutlinedButtonVariant Secondary , variant: OutlinedButtonVariant Secondary
, className: state.cliqueType == MaxClique_ ? , className: state.cliqueType == show MaxClique_ ?
"active" $ "active" $
"" ""
} }
...@@ -398,7 +401,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -398,7 +401,7 @@ component = R.hooksComponent "configForm" cpt where
] ]
, ,
-- TYPE::FIS_ -- TYPE::FIS_
R2.if' (state.cliqueType == FIS_) $R.fragment R2.if' (state.cliqueType == show FIS_) $R.fragment
[ [
-- Support -- Support
H.div H.div
...@@ -464,7 +467,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -464,7 +467,7 @@ component = R.hooksComponent "configForm" cpt where
] ]
, ,
-- TYPE::MaxClique_ -- TYPE::MaxClique_
R2.if' (state.cliqueType == MaxClique_) $R.fragment R2.if' (state.cliqueType == show MaxClique_) $R.fragment
[ [
-- Size -- Size
H.div H.div
...@@ -486,7 +489,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -486,7 +489,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "size" { type: "number"
} `merge` bindStateKey "size"
, ,
R2.if' (fv.hasError' "sjze") $ R2.if' (fv.hasError' "sjze") $
H.div H.div
...@@ -517,7 +521,8 @@ component = R.hooksComponent "configForm" cpt where ...@@ -517,7 +521,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formInput $ B.formInput $
bindStateKey "threshold" { type: "number"
} `merge` bindStateKey "threshold"
, ,
R2.if' (fv.hasError' "threshold") $ R2.if' (fv.hasError' "threshold") $
H.div H.div
...@@ -545,12 +550,7 @@ component = R.hooksComponent "configForm" cpt where ...@@ -545,12 +550,7 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" } { className: "form-group__field" }
[ [
B.formSelect B.formSelect
{ value: show state.cliqueFilter ( bindStateKey "cliqueFilter" )
, callback: read >>> case _ of
Nothing -> pure unit
Just (v :: CliqueFilter) ->
setter stateBox "cliqueFilter" v
}
[ [
H.option H.option
{ value: show ByThreshold } { value: show ByThreshold }
...@@ -585,16 +585,16 @@ type FormData = ...@@ -585,16 +585,16 @@ type FormData =
, quality :: Number , quality :: Number
, exportFilter :: Number , exportFilter :: Number
-- TimeUnit -- TimeUnit
, granularity :: ReflexiveTimeUnit , timeUnit :: TimeUnit
, period :: Int
, step :: Int
, matchingFrame :: Int
-- Clique -- Clique
, cliqueType :: ReflexiveClique
, support :: Int
, size :: Int -- , cliqueType :: ReflexiveClique
, threshold :: Number -- , support :: Int
, cliqueFilter :: CliqueFilter -- , size :: Int
-- , threshold :: Number
-- , cliqueFilter :: CliqueFilter
, clique :: Clique
) )
defaultData :: Record FormData defaultData :: Record FormData
...@@ -604,16 +604,149 @@ defaultData = ...@@ -604,16 +604,149 @@ defaultData =
, quality: 0.1 , quality: 0.1
, exportFilter: 0.1 , exportFilter: 0.1
-- TimeUnit -- TimeUnit
, granularity: Year_ , timeUnit: Year $ TimeUnitCriteria
, period: 3 { period: 3
, step: 1 , step: 1
, matchingFrame: 5 , matchingFrame: 5
}
-- Clique -- Clique
, cliqueType: FIS_ -- , cliqueType: FIS_
, support: 1 -- , support: 1
-- , size: 1
-- , threshold: 0.5
-- , cliqueFilter: ByThreshold
, clique: FIS
{ support: 1
, size: 1 , size: 1
, threshold: 0.5 }
, cliqueFilter: ByThreshold }
type RawData =
( proximity :: String
, synchrony :: String
, quality :: String
, exportFilter :: String
-- TimeUnit
, granularity :: String
, period :: String
, step :: String
, matchingFrame :: String
-- Clique
, cliqueType :: String
, support :: String
, size :: String
, threshold :: String
, cliqueFilter :: String
)
-- (?) due to `Clique` multi constructors nature, we have to relying on a
-- set of default data for every constructor property
defaultCliqueData ::
{ cliqueType :: String
, support :: String
, size :: String
, threshold :: String
, cliqueFilter :: String
}
defaultCliqueData =
{ cliqueType: "FIS_"
, support: "1"
, size: "1"
, threshold: "0.5"
, cliqueFilter: "ByThreshold"
}
parseFormData :: Record FormData -> Record RawData
parseFormData { proximity
, synchrony
, quality
, exportFilter
, timeUnit
, clique
}
= { proximity: show proximity
, synchrony: show synchrony
, quality: show quality
, exportFilter: show exportFilter
-- Time unit
, granularity: timeUnit #
(show <<< toReflexiveTimeUnit)
, period: timeUnit #
(show <<< getter _.period <<< extractCriteria)
, step: timeUnit #
(show <<< getter _.step <<< extractCriteria)
, matchingFrame: timeUnit #
(show <<< getter _.matchingFrame <<< extractCriteria)
-- Clique
} `merge` (parseClique clique)
where
parseClique :: Clique ->
{ cliqueType :: String
, support :: String
, size :: String
, threshold :: String
, cliqueFilter :: String
}
parseClique (FIS o) =
{ support: show o.support
, size: show o.size
} `merge` defaultCliqueData
parseClique (MaxClique o) =
{ size: show o.size
, threshold: show o.threshold
, cliqueFilter: show o.filter
} `merge` defaultCliqueData
parseRawData :: Record RawData -> Record FormData
parseRawData raw@{ proximity
, synchrony
, quality
, exportFilter
, granularity
, period
, step
, matchingFrame
}
= { proximity: fromMaybe 0.0 (Number.fromString proximity)
, synchrony: fromMaybe 0.0 (Number.fromString synchrony)
, quality: fromMaybe 0.0 (Number.fromString quality)
, exportFilter: fromMaybe 0.0 (Number.fromString exportFilter)
-- Time unit
, timeUnit: parseTimeUnit
(parseCriteria period step matchingFrame)
granularity
-- Clique
, clique: parseClique raw raw.cliqueType
}
where
parseCriteria :: String -> String -> String -> TimeUnitCriteria
parseCriteria a b c = TimeUnitCriteria
{ period : fromMaybe 0 (Int.fromString a)
, step : fromMaybe 0 (Int.fromString b)
, matchingFrame: fromMaybe 0 (Int.fromString c)
}
parseTimeUnit :: TimeUnitCriteria -> String -> TimeUnit
parseTimeUnit criteria = read >>> case _ of
Nothing -> Year criteria
Just (r :: ReflexiveTimeUnit) -> fromReflexiveTimeUnit r criteria
parseClique :: Record RawData -> String -> Clique
parseClique o = read >>> case _ of
Nothing -> FIS
{ support: 1
, size: 1
}
Just (r :: ReflexiveClique) -> case r of
FIS_ -> FIS
{ support: fromMaybe 0 (Int.fromString o.support)
, size: fromMaybe 0 (Int.fromString o.size)
}
MaxClique_ -> MaxClique
{ size: fromMaybe 0 (Int.fromString o.support)
, threshold: fromMaybe 0.0 (Number.fromString o.threshold)
, filter: fromMaybe ByThreshold (read o.cliqueFilter)
} }
......
...@@ -13,7 +13,6 @@ import Prim.RowList (class RowToList) ...@@ -13,7 +13,6 @@ import Prim.RowList (class RowToList)
import Reactix as R import Reactix as R
import Toestand as T import Toestand as T
-- @TODO: /!\ `bindStateKey` + `setStateKey` not working together
type Methods r a = type Methods r a =
-- | Every provided props will be available within the `formFields` proxy -- | Every provided props will be available within the `formFields` proxy
......
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