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
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Grégoire Locqueville
purescript-gargantext
Commits
8d73c0c4
Verified
Commit
8d73c0c4
authored
Jan 12, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graphql] some refactoring to make for less typing
parent
e6ae3530
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
148 additions
and
87 deletions
+148
-87
spago.dhall
spago.dhall
+1
-0
Category.purs
src/Gargantext/Components/Category.purs
+46
-44
Contact.purs
src/Gargantext/Components/GraphQL/Contact.purs
+3
-15
Context.purs
src/Gargantext/Components/GraphQL/Context.purs
+6
-9
IMT.purs
src/Gargantext/Components/GraphQL/IMT.purs
+10
-4
Node.purs
src/Gargantext/Components/GraphQL/Node.purs
+14
-9
Team.purs
src/Gargantext/Components/GraphQL/Team.purs
+14
-6
GraphQL.purs
src/Gargantext/Utils/GraphQL.purs
+54
-0
No files found.
spago.dhall
View file @
8d73c0c4
...
...
@@ -44,6 +44,7 @@ to generate this file without the comments in this block.
, "formula"
, "functions"
, "graphql-client"
, "heterogeneous"
, "http-methods"
, "integers"
, "js-timers"
...
...
src/Gargantext/Components/Category.purs
View file @
8d73c0c4
...
...
@@ -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
, c
ontext :: NodeContex
t
, c
ategory :: In
t
, session :: Session )
renderRatingSimple :: R2.Component RenderRatingSimpleProps
...
...
@@ -143,18 +148,15 @@ renderRatingSimpleCpt :: R.Component RenderRatingSimpleProps
renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where
cpt { docId
, corpusId
, c
ontext: { nc_category }
, c
ategory
, 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
...
...
src/Gargantext/Components/GraphQL/Contact.purs
View file @
8d73c0c4
...
...
@@ -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)
}
------------------------------------------------------------------------
...
...
src/Gargantext/Components/GraphQL/Context.purs
View file @
8d73c0c4
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)
}
------------------------------------------------------------------------
...
...
src/Gargantext/Components/GraphQL/IMT.purs
View file @
8d73c0c4
...
...
@@ -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)
}
src/Gargantext/Components/GraphQL/Node.purs
View file @
8d73c0c4
...
...
@@ -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)
}
src/Gargantext/Components/GraphQL/Team.purs
View file @
8d73c0c4
...
...
@@ -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)
}
src/Gargantext/Utils/GraphQL.purs
0 → 100644
View file @
8d73c0c4
-- 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)
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