[graphql] some refactoring to make for less typing

parent e6ae3530
Pipeline #3577 failed with stage
in 0 seconds
...@@ -44,6 +44,7 @@ to generate this file without the comments in this block. ...@@ -44,6 +44,7 @@ to generate this file without the comments in this block.
, "formula" , "formula"
, "functions" , "functions"
, "graphql-client" , "graphql-client"
, "heterogeneous"
, "http-methods" , "http-methods"
, "integers" , "integers"
, "js-timers" , "js-timers"
......
...@@ -14,7 +14,7 @@ import Gargantext.Components.Bootstrap as B ...@@ -14,7 +14,7 @@ import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Variant(..)) import Gargantext.Components.Bootstrap.Types (Variant(..))
import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, categories, clickAgain, decodeStar, star2score, stars) import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, categories, clickAgain, decodeStar, star2score, stars)
import Gargantext.Components.DocsTable.Types (DocumentsView(..), LocalCategories, LocalUserScore) import Gargantext.Components.DocsTable.Types (DocumentsView(..), LocalCategories, LocalUserScore)
import Gargantext.Components.GraphQL.Context (NodeContext, NodeContext') import Gargantext.Components.GraphQL.Context (NodeContext)
import Gargantext.Components.GraphQL.Endpoints (getNodeContext, updateNodeContextCategory) import Gargantext.Components.GraphQL.Endpoints (getNodeContext, updateNodeContextCategory)
import Gargantext.Config.REST (AffRESTError, RESTError(..)) import Gargantext.Config.REST (AffRESTError, RESTError(..))
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
...@@ -52,34 +52,39 @@ ratingCpt = here.component "rating" cpt where ...@@ -52,34 +52,39 @@ ratingCpt = here.component "rating" cpt where
, session , session
, setLocalCategories , setLocalCategories
} _ = do } _ = do
-- | Behaviors pure $ renderRatingSimple { docId: nodeId
-- | , corpusId: r._id
let , category: star2score score
onClick c _ = do , session } []
let c' = score == c ? clickAgain c $ c
-- -- | Behaviors
setLocalCategories $ Map.insert r._id c' -- -- |
launchAff_ do -- let
_ <- putRating session nodeId $ RatingQuery -- onClick c _ = do
{ nodeIds: [r._id] -- let c' = score == c ? clickAgain c $ c
, rating: c'
} -- setLocalCategories $ Map.insert r._id c'
liftEffect $ T2.reload chartReload -- launchAff_ do
-- _ <- putRating session nodeId $ RatingQuery
-- | Render -- { nodeIds: [r._id]
-- | -- , rating: c'
pure $ -- }
-- liftEffect $ T2.reload chartReload
H.div
{ className: "rating-group" } $ -- -- | Render
stars <#> \s -> -- -- |
B.iconButton -- pure $
{ name: ratingIcon score s
, callback: onClick s -- H.div
, overlay: false -- { className: "rating-group" } $
, variant: ratingVariant score s -- stars <#> \s ->
, className: ratingClassName score s -- B.iconButton
} -- { name: ratingIcon score s
-- , callback: onClick s
-- , overlay: false
-- , variant: ratingVariant score s
-- , className: ratingClassName score s
-- }
ratingIcon Star_0 Star_0 = "times-circle" ratingIcon Star_0 Star_0 = "times-circle"
ratingIcon _ Star_0 = "times" ratingIcon _ Star_0 = "times"
...@@ -113,10 +118,10 @@ ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where ...@@ -113,10 +118,10 @@ ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where
useLoader { errorHandler useLoader { errorHandler
, loader: loadDocumentContext session , loader: loadDocumentContext session
, path: { docId, corpusId } , path: { docId, corpusId }
, render: \nc -> renderRatingSimple { docId , render: \{ nc_category } -> renderRatingSimple { docId
, corpusId , corpusId
, context: nc , category: fromMaybe 0 nc_category
, session } [] } , session } [] }
where where
errorHandler err = do errorHandler err = do
here.warn2 "[pageLayout] RESTError" err here.warn2 "[pageLayout] RESTError" err
...@@ -134,7 +139,7 @@ loadDocumentContext session { docId, corpusId } = getNodeContext session docId c ...@@ -134,7 +139,7 @@ loadDocumentContext session { docId, corpusId } = getNodeContext session docId c
type RenderRatingSimpleProps = type RenderRatingSimpleProps =
( docId :: NodeID ( docId :: NodeID
, corpusId :: NodeID , corpusId :: NodeID
, context :: NodeContext , category :: Int
, session :: Session ) , session :: Session )
renderRatingSimple :: R2.Component RenderRatingSimpleProps renderRatingSimple :: R2.Component RenderRatingSimpleProps
...@@ -143,18 +148,15 @@ renderRatingSimpleCpt :: R.Component RenderRatingSimpleProps ...@@ -143,18 +148,15 @@ renderRatingSimpleCpt :: R.Component RenderRatingSimpleProps
renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where
cpt { docId cpt { docId
, corpusId , corpusId
, context: { nc_category } , category
, session , session
} _ = do } _ = do
score <- T.useBox $ decodeStar $ fromMaybe 0 nc_category score <- T.useBox $ decodeStar category
pure $ case nc_category of pure $ ratingSimple { docId
Nothing -> H.div {} [] , corpusId
Just category -> do , score
ratingSimple { docId , session } []
, corpusId
, score
, session } []
type RatingSimpleProps = type RatingSimpleProps =
( docId :: NodeID ( docId :: NodeID
......
...@@ -25,6 +25,8 @@ import Data.Lens (Lens', lens) ...@@ -25,6 +25,8 @@ import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import GraphQL.Client.Args (Args, (=>>)) import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Variable (Var(..)) import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
import Data.Array as A import Data.Array as A
...@@ -68,21 +70,7 @@ annuaireContactQuery :: AnnuaireContactQuery ...@@ -68,21 +70,7 @@ annuaireContactQuery :: AnnuaireContactQuery
annuaireContactQuery annuaireContactQuery
= { annuaire_contacts: = { annuaire_contacts:
{ contact_id: Var :: _ "id" Int } =>> { contact_id: Var :: _ "id" Int } =>>
{ ac_title: unit GGQL.getFieldsStandard (Proxy :: _ AnnuaireContact)
, ac_source: unit
, ac_id: unit
, ac_firstName: unit
, ac_lastName: unit
, ac_labTeamDepts: unit
, ac_organization: unit
, ac_role: unit
, ac_office: unit
, ac_country: unit
, ac_city: unit
, ac_touchMail: unit
, ac_touchPhone: unit
, ac_touchUrl: unit
}
} }
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
module Gargantext.Components.GraphQL.Context module Gargantext.Components.GraphQL.Context
( NodeContext ( NodeContext
, NodeContext' , NodeContext_
, nodeContextQuery , nodeContextQuery
, NodeContextCategoryM , NodeContextCategoryM
) where ) where
...@@ -11,17 +11,19 @@ import Data.Lens (Lens', lens) ...@@ -11,17 +11,19 @@ import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import GraphQL.Client.Args (Args, NotNull, (=>>)) import GraphQL.Client.Args (Args, NotNull, (=>>))
import GraphQL.Client.Variable (Var(..)) import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
import Data.Array as A import Data.Array as A
type NodeContext' type NodeContext_
= ( nc_id :: Maybe Int = ( nc_id :: Maybe Int
, nc_node_id :: Int , nc_node_id :: Int
, nc_context_id :: Int , nc_context_id :: Int
, nc_score :: Maybe Number , nc_score :: Maybe Number
, nc_category :: Maybe Int , nc_category :: Maybe Int
) )
type NodeContext = Record NodeContext' type NodeContext = Record NodeContext_
type NodeContextQuery type NodeContextQuery
= { contexts :: Args = { contexts :: Args
...@@ -39,12 +41,7 @@ nodeContextQuery ...@@ -39,12 +41,7 @@ nodeContextQuery
= { contexts: = { contexts:
{ context_id: Var :: _ "context_id" Int { context_id: Var :: _ "context_id" Int
, node_id: Var :: _ "node_id" Int } =>> , node_id: Var :: _ "node_id" Int } =>>
{ nc_id: unit GGQL.getFieldsStandard (Proxy :: _ NodeContext)
, nc_node_id: unit
, nc_context_id: unit
, nc_score: unit
, nc_category: unit
}
} }
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
...@@ -8,6 +8,8 @@ import Data.Lens (Lens', lens) ...@@ -8,6 +8,8 @@ import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe, maybe) import Data.Maybe (Maybe(..), fromMaybe, maybe)
import GraphQL.Client.Args (NotNull, (=>>)) import GraphQL.Client.Args (NotNull, (=>>))
import GraphQL.Client.Variable (Var(..)) import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
type School type School
...@@ -16,9 +18,13 @@ type School ...@@ -16,9 +18,13 @@ type School
, school_shortName :: String , school_shortName :: String
} }
type SchoolsQuery
= { imt_schools ::
{ school_id :: Unit
, school_longName :: Unit
, school_shortName :: Unit } }
schoolsQuery :: SchoolsQuery
schoolsQuery = { imt_schools: schoolsQuery = { imt_schools:
{ school_id: unit GGQL.getFieldsStandard (Proxy :: _ School)
, school_longName: unit
, school_shortName: unit}
} }
...@@ -2,8 +2,10 @@ module Gargantext.Components.GraphQL.Node where ...@@ -2,8 +2,10 @@ module Gargantext.Components.GraphQL.Node where
import Gargantext.Prelude import Gargantext.Prelude
import GraphQL.Client.Args ((=>>)) import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Variable (Var(..)) import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
type Node type Node
...@@ -12,17 +14,20 @@ type Node ...@@ -12,17 +14,20 @@ type Node
, parent_id :: Int , parent_id :: Int
, type_id :: Int } , type_id :: Int }
type NodesQuery =
{ nodes :: Args
{ node_id :: Var "id" Int }
{ id :: Unit
, name :: Unit
, parent_id :: Unit
, type_id :: Unit } }
nodesQuery :: NodesQuery
nodesQuery = { nodes: { node_id: Var :: _ "id" Int } =>> nodesQuery = { nodes: { node_id: Var :: _ "id" Int } =>>
{ id: unit GGQL.getFieldsStandard (Proxy :: _ Node)
, name: unit
, parent_id: unit
, type_id: unit }
} }
nodeParentQuery = { node_parent: { node_id: Var :: _ "id" Int nodeParentQuery = { node_parent: { node_id: Var :: _ "id" Int
, parent_type: Var :: _ "parent_type" String } =>> -- TODO parent_type :: NodeType , parent_type: Var :: _ "parent_type" String } =>> -- TODO parent_type :: NodeType
{ id: unit GGQL.getFieldsStandard (Proxy :: _ Node)
, name: unit
, parent_id: unit
, type_id: unit }
} }
...@@ -2,8 +2,10 @@ module Gargantext.Components.GraphQL.Team where ...@@ -2,8 +2,10 @@ module Gargantext.Components.GraphQL.Team where
import Gargantext.Prelude import Gargantext.Prelude
import GraphQL.Client.Args (NotNull, (=>>)) import GraphQL.Client.Args (Args, NotNull, (=>>))
import GraphQL.Client.Variable (Var(..)) import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
type Team type Team
= { team_owner_username :: String = { team_owner_username :: String
...@@ -21,10 +23,16 @@ type TeamDeleteM ...@@ -21,10 +23,16 @@ type TeamDeleteM
, team_node_id :: Int , team_node_id :: Int
} }
type TeamQuery =
{ team :: Args
{ team_node_id :: Var "id" Int}
{ team_owner_username :: Unit
, team_members ::
{ username :: Unit
, shared_folder_id :: Unit } }
}
teamQuery :: TeamQuery
teamQuery = { team: { team_node_id: Var :: _ "id" Int } =>> teamQuery = { team: { team_node_id: Var :: _ "id" Int } =>>
{ team_owner_username: unit GGQL.getFieldsStandard (Proxy :: _ Team)
, team_members: { username: unit
, shared_folder_id: unit
}
}
} }
-- https://github.com/OxfordAbstracts/purescript-graphql-client/pull/68/files#diff-404493334c4108c2411bd1767059be2e94295df5742d14d58116667dc5e80dd7R16-R19
module Gargantext.Utils.GraphQL
-- | Get the graphql fields from a data type
(class GetFieldsStandard, PropGetFieldsStandard, getFieldsStandard) where
import Prelude
import Data.HeytingAlgebra (class HeytingAlgebraRecord, tt)
import Data.Maybe (Maybe)
import Heterogeneous.Mapping (class HMap, class Mapping, hmap)
import Prim.RowList (class RowToList)
import Type.Proxy (Proxy(..))
class GetFieldsStandard :: forall k. k -> Type -> Constraint
class GetFieldsStandard t fields | t -> fields where
getFieldsStandard :: Proxy t -> fields
data PropGetFieldsStandard
= PropGetFieldsStandard
data PropToProxy
= PropToProxy
instance getFieldsStandardRecord ::
( RowToList r t
, HeytingAlgebraRecord t r r
, HMap PropGetFieldsStandard { | r } fields
, HMap PropGetFieldsStandard { | input } { | r }
) =>
GetFieldsStandard { | input } fields where
getFieldsStandard _ = recordGetFieldsStandard (tt :: { | r })
else instance getFieldsStandardMaybe :: GetFieldsStandard a fields => GetFieldsStandard (Maybe a) fields where
getFieldsStandard _ = getFieldsStandard (Proxy :: _ a)
else instance getFieldsStandardArray :: GetFieldsStandard a fields => GetFieldsStandard (Array a) fields where
getFieldsStandard _ = getFieldsStandard (Proxy :: _ a)
else instance getFieldsStandardLeaf :: GetFieldsStandard a Unit where
getFieldsStandard _ = unit
instance propToProxy ::
Mapping PropToProxy t (Proxy t) where
mapping PropToProxy _ = Proxy
recordGetFieldsStandard ::
forall t fields.
HMap PropGetFieldsStandard ({ | t }) fields => { | t } -> fields
recordGetFieldsStandard = hmap PropGetFieldsStandard
instance propGetFieldsStandard ::
(GetFieldsStandard t fields) =>
Mapping PropGetFieldsStandard t fields where
mapping PropGetFieldsStandard _ = getFieldsStandard (Proxy :: _ t)
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