[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.
, "formula"
, "functions"
, "graphql-client"
, "heterogeneous"
, "http-methods"
, "integers"
, "js-timers"
......
......@@ -14,7 +14,7 @@ import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Variant(..))
import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, categories, clickAgain, decodeStar, star2score, stars)
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.Config.REST (AffRESTError, RESTError(..))
import Gargantext.Hooks.Loader (useLoader)
......@@ -52,34 +52,39 @@ ratingCpt = here.component "rating" cpt where
, session
, setLocalCategories
} _ = do
-- | Behaviors
-- |
let
onClick c _ = do
let c' = score == c ? clickAgain c $ c
setLocalCategories $ Map.insert r._id c'
launchAff_ do
_ <- putRating session nodeId $ RatingQuery
{ nodeIds: [r._id]
, rating: c'
}
liftEffect $ T2.reload chartReload
-- | Render
-- |
pure $
H.div
{ className: "rating-group" } $
stars <#> \s ->
B.iconButton
{ name: ratingIcon score s
, callback: onClick s
, overlay: false
, variant: ratingVariant score s
, className: ratingClassName score s
}
pure $ renderRatingSimple { docId: nodeId
, corpusId: r._id
, category: star2score score
, session } []
-- -- | Behaviors
-- -- |
-- let
-- onClick c _ = do
-- let c' = score == c ? clickAgain c $ c
-- setLocalCategories $ Map.insert r._id c'
-- launchAff_ do
-- _ <- putRating session nodeId $ RatingQuery
-- { nodeIds: [r._id]
-- , rating: c'
-- }
-- liftEffect $ T2.reload chartReload
-- -- | Render
-- -- |
-- pure $
-- H.div
-- { className: "rating-group" } $
-- stars <#> \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 = "times"
......@@ -113,10 +118,10 @@ ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where
useLoader { errorHandler
, loader: loadDocumentContext session
, path: { docId, corpusId }
, render: \nc -> renderRatingSimple { docId
, corpusId
, context: nc
, session } [] }
, render: \{ nc_category } -> renderRatingSimple { docId
, corpusId
, category: fromMaybe 0 nc_category
, session } [] }
where
errorHandler err = do
here.warn2 "[pageLayout] RESTError" err
......@@ -134,7 +139,7 @@ loadDocumentContext session { docId, corpusId } = getNodeContext session docId c
type RenderRatingSimpleProps =
( docId :: NodeID
, corpusId :: NodeID
, context :: NodeContext
, category :: Int
, session :: Session )
renderRatingSimple :: R2.Component RenderRatingSimpleProps
......@@ -143,18 +148,15 @@ renderRatingSimpleCpt :: R.Component RenderRatingSimpleProps
renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where
cpt { docId
, corpusId
, context: { nc_category }
, category
, session
} _ = do
score <- T.useBox $ decodeStar $ fromMaybe 0 nc_category
pure $ case nc_category of
Nothing -> H.div {} []
Just category -> do
ratingSimple { docId
, corpusId
, score
, session } []
score <- T.useBox $ decodeStar category
pure $ ratingSimple { docId
, corpusId
, score
, session } []
type RatingSimpleProps =
( docId :: NodeID
......
......@@ -25,6 +25,8 @@ import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe)
import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
import Data.Array as A
......@@ -68,21 +70,7 @@ annuaireContactQuery :: AnnuaireContactQuery
annuaireContactQuery
= { annuaire_contacts:
{ contact_id: Var :: _ "id" Int } =>>
{ ac_title: unit
, 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
}
GGQL.getFieldsStandard (Proxy :: _ AnnuaireContact)
}
------------------------------------------------------------------------
......
module Gargantext.Components.GraphQL.Context
( NodeContext
, NodeContext'
, NodeContext_
, nodeContextQuery
, NodeContextCategoryM
) where
......@@ -11,17 +11,19 @@ import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe)
import GraphQL.Client.Args (Args, NotNull, (=>>))
import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
import Data.Array as A
type NodeContext'
type NodeContext_
= ( nc_id :: Maybe Int
, nc_node_id :: Int
, nc_context_id :: Int
, nc_score :: Maybe Number
, nc_category :: Maybe Int
)
type NodeContext = Record NodeContext'
type NodeContext = Record NodeContext_
type NodeContextQuery
= { contexts :: Args
......@@ -39,12 +41,7 @@ nodeContextQuery
= { contexts:
{ context_id: Var :: _ "context_id" Int
, node_id: Var :: _ "node_id" Int } =>>
{ nc_id: unit
, nc_node_id: unit
, nc_context_id: unit
, nc_score: unit
, nc_category: unit
}
GGQL.getFieldsStandard (Proxy :: _ NodeContext)
}
------------------------------------------------------------------------
......
......@@ -8,6 +8,8 @@ import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import GraphQL.Client.Args (NotNull, (=>>))
import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
type School
......@@ -16,9 +18,13 @@ type School
, school_shortName :: String
}
type SchoolsQuery
= { imt_schools ::
{ school_id :: Unit
, school_longName :: Unit
, school_shortName :: Unit } }
schoolsQuery :: SchoolsQuery
schoolsQuery = { imt_schools:
{ school_id: unit
, school_longName: unit
, school_shortName: unit}
GGQL.getFieldsStandard (Proxy :: _ School)
}
......@@ -2,8 +2,10 @@ module Gargantext.Components.GraphQL.Node where
import Gargantext.Prelude
import GraphQL.Client.Args ((=>>))
import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
type Node
......@@ -12,17 +14,20 @@ type Node
, parent_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 } =>>
{ id: unit
, name: unit
, parent_id: unit
, type_id: unit }
GGQL.getFieldsStandard (Proxy :: _ Node)
}
nodeParentQuery = { node_parent: { node_id: Var :: _ "id" Int
, parent_type: Var :: _ "parent_type" String } =>> -- TODO parent_type :: NodeType
{ id: unit
, name: unit
, parent_id: unit
, type_id: unit }
GGQL.getFieldsStandard (Proxy :: _ Node)
}
......@@ -2,8 +2,10 @@ module Gargantext.Components.GraphQL.Team where
import Gargantext.Prelude
import GraphQL.Client.Args (NotNull, (=>>))
import GraphQL.Client.Args (Args, NotNull, (=>>))
import GraphQL.Client.Variable (Var(..))
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
type Team
= { team_owner_username :: String
......@@ -21,10 +23,16 @@ type TeamDeleteM
, 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 } =>>
{ team_owner_username: unit
, team_members: { username: unit
, shared_folder_id: unit
}
}
GGQL.getFieldsStandard (Proxy :: _ Team)
}
-- 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