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
152
Issues
152
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
gargantext
purescript-gargantext
Commits
a339e7d9
Commit
a339e7d9
authored
Feb 28, 2022
by
arturo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
>>> continue
parent
388f48fc
Pipeline
#2521
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
227 additions
and
63 deletions
+227
-63
API.purs
src/Gargantext/Components/PhyloExplorer/API.purs
+42
-10
ConfigForm.purs
src/Gargantext/Components/PhyloExplorer/ConfigForm.purs
+185
-52
Unboxed.purs
src/Gargantext/Hooks/StateRecord/Unboxed.purs
+0
-1
No files found.
src/Gargantext/Components/PhyloExplorer/API.purs
View file @
a339e7d9
...
...
@@ -3,6 +3,8 @@ module Gargantext.Components.PhyloExplorer.API
, UpdateData(..)
, TimeUnit(..), ReflexiveTimeUnit(..), TimeUnitCriteria(..)
, Clique(..), ReflexiveClique(..), CliqueFilter(..)
, toReflexiveTimeUnit, fromReflexiveTimeUnit, extractCriteria
, toReflexiveClique
, update, updateProgress
) where
...
...
@@ -11,6 +13,7 @@ import Gargantext.Prelude
import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
import Data.Show.Generic (genericShow)
import Data.Symbol (SProxy(..))
import Gargantext.Components.PhyloExplorer.JSON (PhyloJSONSet)
...
...
@@ -170,12 +173,12 @@ instance Show ReflexiveTimeUnit where show = genericShow
instance Read ReflexiveTimeUnit where
read :: String -> Maybe ReflexiveTimeUnit
read = case _ of
"Epoch" -> Just Epoch_
"Year" -> Just Year_
"Month" -> Just Month_
"Week" -> Just Week_
"Day" -> Just Day_
_ -> Nothing
"Epoch
_
" -> Just Epoch_
"Year
_
" -> Just Year_
"Month
_
" -> Just Month_
"Week
_
" -> Just Week_
"Day
_
" -> Just Day_
_
-> Nothing
newtype TimeUnitCriteria = TimeUnitCriteria
...
...
@@ -186,6 +189,7 @@ newtype TimeUnitCriteria = TimeUnitCriteria
derive instance Generic TimeUnitCriteria _
derive instance Eq TimeUnitCriteria
derive instance Newtype TimeUnitCriteria _
instance Show TimeUnitCriteria where show = genericShow
derive newtype instance JSON.ReadForeign TimeUnitCriteria
...
...
@@ -245,9 +249,9 @@ instance Show ReflexiveClique where show = genericShow
instance Read ReflexiveClique where
read :: String -> Maybe ReflexiveClique
read = case _ of
"FIS" -> Just FIS_
"MaxClique" -> Just MaxClique_
_ -> Nothing
"FIS
_
" -> Just FIS_
"MaxClique
_
" -> Just MaxClique_
_
-> Nothing
data CliqueFilter = ByThreshold | ByNeighbours
...
...
@@ -260,11 +264,39 @@ instance JSON.WriteForeign CliqueFilter where writeImpl = JSON.writeImpl <<< sho
instance Read CliqueFilter where
read :: String -> Maybe CliqueFilter
read = case _ of
"ByT
reshold"
-> Just ByThreshold
"ByT
hreshold"
-> Just ByThreshold
"ByNeighbours" -> Just ByNeighbours
_ -> 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 ::
Session
-> NodeID
...
...
src/Gargantext/Components/PhyloExplorer/ConfigForm.purs
View file @
a339e7d9
...
...
@@ -8,13 +8,15 @@ import DOM.Simple.Console (log, log3)
import Data.Either (Either(..))
import Data.Foldable (foldl, intercalate)
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.Show.Generic (genericShow)
import Effect (Effect)
import Gargantext.Components.Bootstrap as B
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.Hooks.FormValidation (VForm, useFormValidation)
import Gargantext.Hooks.FormValidation.Unboxed as FV
...
...
@@ -23,7 +25,7 @@ import Gargantext.Hooks.StateRecord.Behaviors (setter)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, post, get)
import Gargantext.Types as GT
import Gargantext.Utils (nbsp, (?))
import Gargantext.Utils (
getter,
nbsp, (?))
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
...
...
@@ -53,7 +55,11 @@ component = R.hooksComponent "configForm" cpt where
cpt props _ = do
-- Hooks
{ state, bindStateKey, stateBox, setStateKey } <- useStateRecord (pick props :: Record FormData)
{ state
, bindStateKey
, stateBox
, setStateKey
} <- useStateRecord $ parseFormData (pick props :: Record FormData)
fv <- useFormValidation
R.useEffect1' state $ log state
...
...
@@ -68,7 +74,7 @@ component = R.hooksComponent "configForm" cpt where
result <- pure $ Right state
case result of
Left err -> log3 "configForm validation error" state err
Right _ -> props.callback state
Right _ -> props.callback
$ parseRawData
state
-- Render
...
...
@@ -98,11 +104,7 @@ component = R.hooksComponent "configForm" cpt where
[
B.formInput $
{ type: "number"
, value: show state.proximity
, callback: Number.fromString >>> case _ of
Nothing -> pure unit
Just v -> setter stateBox "proximity" v
}
} `merge` bindStateKey "proximity"
,
R2.if' (fv.hasError' "proximity") $
H.div
...
...
@@ -133,7 +135,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "synchrony"
{ type: "number"
} `merge` bindStateKey "synchrony"
,
R2.if' (fv.hasError' "synchrony") $
H.div
...
...
@@ -164,7 +167,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "quality"
{ type: "number"
} `merge` bindStateKey "quality"
,
R2.if' (fv.hasError' "quality") $
H.div
...
...
@@ -195,7 +199,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "exportFilter"
{ type: "number"
} `merge` bindStateKey "exportFilter"
,
R2.if' (fv.hasError' "exportFilter") $
H.div
...
...
@@ -227,12 +232,7 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formSelect
{ value: show state.granularity
, callback: read >>> case _ of
Nothing -> pure unit
Just (v :: ReflexiveTimeUnit) ->
setter stateBox "granularity" v
}
(bindStateKey "granularity")
[
H.option
{ value: show Year_ }
...
...
@@ -273,7 +273,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "period"
{ type: "number"
} `merge` bindStateKey "period"
,
R2.if' (fv.hasError' "period") $
H.div
...
...
@@ -304,7 +305,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "step"
{ type: "number"
} `merge` bindStateKey "step"
,
R2.if' (fv.hasError' "step") $
H.div
...
...
@@ -335,7 +337,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "matchingFrame"
{ type: "number"
} `merge` bindStateKey "matchingFrame"
,
R2.if' (fv.hasError' "matchingFrame") $
H.div
...
...
@@ -375,7 +378,7 @@ component = R.hooksComponent "configForm" cpt where
B.button
{ callback: \_ -> setter stateBox "cliqueType" FIS_
, variant: OutlinedButtonVariant Secondary
, className: state.cliqueType == FIS_ ?
, className: state.cliqueType ==
show
FIS_ ?
"active" $
""
}
...
...
@@ -386,7 +389,7 @@ component = R.hooksComponent "configForm" cpt where
B.button
{ callback: \_ -> setter stateBox "cliqueType" MaxClique_
, variant: OutlinedButtonVariant Secondary
, className: state.cliqueType == MaxClique_ ?
, className: state.cliqueType ==
show
MaxClique_ ?
"active" $
""
}
...
...
@@ -398,7 +401,7 @@ component = R.hooksComponent "configForm" cpt where
]
,
-- TYPE::FIS_
R2.if' (state.cliqueType == FIS_) $R.fragment
R2.if' (state.cliqueType ==
show
FIS_) $R.fragment
[
-- Support
H.div
...
...
@@ -464,7 +467,7 @@ component = R.hooksComponent "configForm" cpt where
]
,
-- TYPE::MaxClique_
R2.if' (state.cliqueType == MaxClique_) $R.fragment
R2.if' (state.cliqueType ==
show
MaxClique_) $R.fragment
[
-- Size
H.div
...
...
@@ -486,7 +489,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "size"
{ type: "number"
} `merge` bindStateKey "size"
,
R2.if' (fv.hasError' "sjze") $
H.div
...
...
@@ -517,7 +521,8 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formInput $
bindStateKey "threshold"
{ type: "number"
} `merge` bindStateKey "threshold"
,
R2.if' (fv.hasError' "threshold") $
H.div
...
...
@@ -545,12 +550,7 @@ component = R.hooksComponent "configForm" cpt where
{ className: "form-group__field" }
[
B.formSelect
{ value: show state.cliqueFilter
, callback: read >>> case _ of
Nothing -> pure unit
Just (v :: CliqueFilter) ->
setter stateBox "cliqueFilter" v
}
( bindStateKey "cliqueFilter" )
[
H.option
{ value: show ByThreshold }
...
...
@@ -585,16 +585,16 @@ type FormData =
, quality :: Number
, exportFilter :: Number
-- TimeUnit
, granularity :: ReflexiveTimeUnit
, period :: Int
, step :: Int
, matchingFrame :: Int
, timeUnit :: TimeUnit
-- Clique
, cliqueType :: ReflexiveClique
, support :: Int
, size :: Int
, threshold :: Number
, cliqueFilter :: CliqueFilter
-- , cliqueType :: ReflexiveClique
-- , support :: Int
-- , size :: Int
-- , threshold :: Number
-- , cliqueFilter :: CliqueFilter
, clique :: Clique
)
defaultData :: Record FormData
...
...
@@ -604,18 +604,151 @@ defaultData =
, quality: 0.1
, exportFilter: 0.1
-- TimeUnit
, granularity: Year_
, period: 3
, step: 1
, matchingFrame: 5
, timeUnit: Year $ TimeUnitCriteria
{ period: 3
, step: 1
, matchingFrame: 5
}
-- Clique
, cliqueType: FIS_
, support: 1
, size: 1
, threshold: 0.5
, cliqueFilter: ByThreshold
-- , cliqueType: FIS_
-- , support: 1
-- , size: 1
-- , threshold: 0.5
-- , cliqueFilter: ByThreshold
, clique: FIS
{ support: 1
, size: 1
}
}
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)
}
-- formValidation :: Record FormData -> Effect VForm
-- formValidation r = foldl append mempty rules
...
...
src/Gargantext/Hooks/StateRecord/Unboxed.purs
View file @
a339e7d9
...
...
@@ -13,7 +13,6 @@ import Prim.RowList (class RowToList)
import Reactix as R
import Toestand as T
-- @TODO: /!\ `bindStateKey` + `setStateKey` not working together
type Methods r a =
-- | Every provided props will be available within the `formFields` proxy
...
...
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