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
e6ae3530
Verified
Commit
e6ae3530
authored
Jan 11, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[nodeContext] GraphQL mutation for category, implemented in rating
parent
0c077116
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
18 deletions
+76
-18
Category.purs
src/Gargantext/Components/Category.purs
+50
-13
GraphQL.purs
src/Gargantext/Components/GraphQL.purs
+2
-1
Context.purs
src/Gargantext/Components/GraphQL/Context.purs
+8
-1
Endpoints.purs
src/Gargantext/Components/GraphQL/Endpoints.purs
+14
-1
Team.purs
src/Gargantext/Components/GraphQL/Team.purs
+2
-2
No files found.
src/Gargantext/Components/Category.purs
View file @
e6ae3530
...
@@ -6,7 +6,7 @@ import Gargantext.Prelude
...
@@ -6,7 +6,7 @@ import Gargantext.Prelude
import Data.Array as A
import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep (class Generic)
import Data.Map as Map
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..)
, fromMaybe
)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Effect.Aff (launchAff_)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
...
@@ -15,7 +15,7 @@ import Gargantext.Components.Bootstrap.Types (Variant(..))
...
@@ -15,7 +15,7 @@ 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, NodeContext')
import Gargantext.Components.GraphQL.Endpoints (getNodeContext)
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)
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Routes (SessionRoute(NodeAPI))
...
@@ -27,6 +27,7 @@ import Gargantext.Utils.Toestand as T2
...
@@ -27,6 +27,7 @@ import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Simple.JSON as JSON
import Simple.JSON as JSON
import Toestand as T
here :: R2.Here
here :: R2.Here
here = R2.here "Gargantext.Components.Category"
here = R2.here "Gargantext.Components.Category"
...
@@ -112,7 +113,10 @@ ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where
...
@@ -112,7 +113,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 nc [] }
, render: \nc -> renderRatingSimple { docId
, corpusId
, context: nc
, session } [] }
where
where
errorHandler err = do
errorHandler err = do
here.warn2 "[pageLayout] RESTError" err
here.warn2 "[pageLayout] RESTError" err
...
@@ -127,35 +131,68 @@ type ContextParams =
...
@@ -127,35 +131,68 @@ type ContextParams =
loadDocumentContext :: Session -> Record ContextParams -> AffRESTError NodeContext
loadDocumentContext :: Session -> Record ContextParams -> AffRESTError NodeContext
loadDocumentContext session { docId, corpusId } = getNodeContext session docId corpusId
loadDocumentContext session { docId, corpusId } = getNodeContext session docId corpusId
renderRatingSimple :: R2.Component NodeContext'
type RenderRatingSimpleProps =
( docId :: NodeID
, corpusId :: NodeID
, context :: NodeContext
, session :: Session )
renderRatingSimple :: R2.Component RenderRatingSimpleProps
renderRatingSimple = R.createElement renderRatingSimpleCpt
renderRatingSimple = R.createElement renderRatingSimpleCpt
renderRatingSimpleCpt :: R.Component
NodeContext'
renderRatingSimpleCpt :: R.Component
RenderRatingSimpleProps
renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where
renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where
cpt { nc_category
cpt { docId
, corpusId
, context: { nc_category }
, session
} _ = do
} _ = do
score <- T.useBox $ decodeStar $ fromMaybe 0 nc_category
pure $ case nc_category of
pure $ case nc_category of
Nothing -> H.div {} []
Nothing -> H.div {} []
Just category -> ratingSimple { score: decodeStar category } []
Just category -> do
ratingSimple { docId
, corpusId
, score
, session } []
type RatingSimpleProps =
type RatingSimpleProps =
( score :: Star )
( docId :: NodeID
, corpusId :: NodeID
, score :: T.Box Star
, session :: Session )
ratingSimple :: R2.Component RatingSimpleProps
ratingSimple :: R2.Component RatingSimpleProps
ratingSimple = R.createElement ratingSimpleCpt
ratingSimple = R.createElement ratingSimpleCpt
ratingSimpleCpt :: R.Component RatingSimpleProps
ratingSimpleCpt :: R.Component RatingSimpleProps
ratingSimpleCpt = here.component "ratingSimple" cpt where
ratingSimpleCpt = here.component "ratingSimple" cpt where
cpt { score
cpt { docId
, corpusId
, score
, session
} _ = do
} _ = do
score' <- T.useLive T.unequal score
let
onClick c _ = do
let c' = score' == c ? clickAgain c $ c
-- setLocalCategories $ Map.insert r._id c'
launchAff_ do
_ <- updateNodeContextCategory session docId corpusId $ star2score c'
liftEffect $ T.write_ c' score
pure unit
pure $
pure $
H.div
H.div
{ className: "rating-group" } $
{ className: "rating-group" } $
stars <#> \s ->
stars <#> \s ->
B.iconButton
B.iconButton
{ name: ratingIcon score s
{ name: ratingIcon score
'
s
, callback:
\_ -> pure unit --
onClick s
, callback: onClick s
, overlay: false
, overlay: false
, variant: ratingVariant score s
, variant: ratingVariant score
'
s
, className: ratingClassName score s
, className: ratingClassName score
'
s
}
}
...
...
src/Gargantext/Components/GraphQL.purs
View file @
e6ae3530
...
@@ -85,4 +85,5 @@ type Schema
...
@@ -85,4 +85,5 @@ type Schema
type Mutation
type Mutation
= { update_user_info :: UserInfoM ==> Int
= { update_user_info :: UserInfoM ==> Int
, delete_team_membership :: TeamDeleteM ==> Array Int }
, delete_team_membership :: TeamDeleteM ==> Array Int
, update_node_context_category :: GQLCTX.NodeContextCategoryM ==> Array Int }
src/Gargantext/Components/GraphQL/Context.purs
View file @
e6ae3530
...
@@ -2,13 +2,14 @@ module Gargantext.Components.GraphQL.Context
...
@@ -2,13 +2,14 @@ module Gargantext.Components.GraphQL.Context
( NodeContext
( NodeContext
, NodeContext'
, NodeContext'
, nodeContextQuery
, nodeContextQuery
, NodeContextCategoryM
) where
) where
import Gargantext.Prelude
import Gargantext.Prelude
import Data.Lens (Lens', lens)
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,
NotNull,
(=>>))
import GraphQL.Client.Variable (Var(..))
import GraphQL.Client.Variable (Var(..))
import Data.Array as A
import Data.Array as A
...
@@ -47,3 +48,9 @@ nodeContextQuery
...
@@ -47,3 +48,9 @@ nodeContextQuery
}
}
------------------------------------------------------------------------
------------------------------------------------------------------------
type NodeContextCategoryM
= { context_id :: NotNull Int
, node_id :: NotNull Int
, category :: Int
}
src/Gargantext/Components/GraphQL/Endpoints.purs
View file @
e6ae3530
...
@@ -102,7 +102,20 @@ deleteTeamMembership session sharedFolderId teamNodeId = do
...
@@ -102,7 +102,20 @@ deleteTeamMembership session sharedFolderId teamNodeId = do
getNodeContext :: Session -> Int -> Int -> AffRESTError GQLCTX.NodeContext
getNodeContext :: Session -> Int -> Int -> AffRESTError GQLCTX.NodeContext
getNodeContext session context_id node_id = do
getNodeContext session context_id node_id = do
{ contexts } <- queryGql session "get node context" $ GQLCTX.nodeContextQuery `withVars` { context_id, node_id }
{ contexts } <- queryGql session "get node context" $ GQLCTX.nodeContextQuery `withVars` { context_id, node_id }
liftEffect $ here.log2 "[getNodeContext] node context" contexts
--
liftEffect $ here.log2 "[getNodeContext] node context" contexts
case A.head contexts of
case A.head contexts of
Nothing -> pure $ Left $ CustomError "no node context found"
Nothing -> pure $ Left $ CustomError "no node context found"
Just context -> pure $ Right context -- TODO: error handling
Just context -> pure $ Right context -- TODO: error handling
updateNodeContextCategory :: Session -> Int -> Int -> Int -> AffRESTError Int
updateNodeContextCategory session context_id node_id category = do
client <- liftEffect $ getClient session
{ update_node_context_category } <- mutation
client
"update_node_context_category"
{ update_node_context_category: onlyArgs { context_id
, node_id
, category } }
pure $ case A.head update_node_context_category of
Nothing -> Left (CustomError $ "Failed to update node category")
Just _ -> Right context_id
src/Gargantext/Components/GraphQL/Team.purs
View file @
e6ae3530
...
@@ -24,7 +24,7 @@ type TeamDeleteM
...
@@ -24,7 +24,7 @@ type TeamDeleteM
teamQuery = { team: { team_node_id: Var :: _ "id" Int } =>>
teamQuery = { team: { team_node_id: Var :: _ "id" Int } =>>
{ team_owner_username: unit
{ team_owner_username: unit
, team_members: { username: unit
, team_members: { username: unit
, shared_folder_id: unit
, shared_folder_id: unit
}
}
}
}
}
}
\ No newline at end of file
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