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
fb4c948f
Commit
fb4c948f
authored
Aug 22, 2022
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/396-dev-list-persons-in-team' into dev-merge
parents
ff2130a2
9b5b433a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
195 additions
and
7 deletions
+195
-7
ManageTeam.purs
...antext/Components/Forest/Tree/Node/Action/ManageTeam.purs
+129
-0
Box.purs
src/Gargantext/Components/Forest/Tree/Node/Box.purs
+2
-0
Settings.purs
src/Gargantext/Components/Forest/Tree/Node/Settings.purs
+5
-0
GraphQL.purs
src/Gargantext/Components/GraphQL.purs
+4
-1
Endpoints.purs
src/Gargantext/Components/GraphQL/Endpoints.purs
+33
-6
Team.purs
src/Gargantext/Components/GraphQL/Team.purs
+22
-0
No files found.
src/Gargantext/Components/Forest/Tree/Node/Action/ManageTeam.purs
0 → 100644
View file @
fb4c948f
module Gargantext.Components.Forest.Tree.Node.Action.ManageTeam where
import Gargantext.Prelude
import Data.Array (filter)
import Data.Either (Either(..))
import Effect.Aff (runAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
import Gargantext.Components.GraphQL.Endpoints (deleteTeamMembership, getTeam)
import Gargantext.Components.GraphQL.Team (TeamMember)
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session)
import Gargantext.Types (ID, NodeType)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.ManageTeam"
type ActionManageTeam = (
id :: ID
, nodeType :: NodeType
, session :: Session
)
actionManageTeam :: R2.Component ActionManageTeam
actionManageTeam = R.createElement actionManageTeamCpt
actionManageTeamCpt :: R.Component ActionManageTeam
actionManageTeamCpt = here.component "actionManageTeam" cpt where
cpt {id, session} _ = do
useLoader { errorHandler
, loader: loadTeam
, path: { nodeId: id, session }
, render: \team -> teamLayoutWrapper { team
, nodeId: id
, session
} []
}
where
errorHandler = logRESTError here "teamLayout"
type TeamProps =
( nodeId :: ID
, session :: Session
, team :: (Array TeamMember)
)
teamLayoutWrapper :: R2.Component TeamProps
teamLayoutWrapper = R.createElement teamLayoutWrapperCpt
teamLayoutWrapperCpt :: R.Component TeamProps
teamLayoutWrapperCpt = here.component "teamLayoutWrapper" cpt where
cpt {nodeId, session, team} _ = do
teamS <- T.useBox team
team' <- T.useLive T.unequal teamS
error <- T.useBox ""
error' <- T.useLive T.unequal error
pure $ teamLayoutRows {nodeId, session, team: teamS, team', error, error'}
type TeamRowProps =
( nodeId :: ID
, session :: Session
, team :: T.Box (Array TeamMember)
, error :: T.Box String
, team' :: Array TeamMember
, error' :: String
)
teamLayoutRows :: R2.Leaf TeamRowProps
teamLayoutRows = R2.leafComponent teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamRowProps
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
cpt { team, nodeId, session, error, team', error' } _ = do
pure $ Tools.panel (map makeTeam team') (H.div {} [H.text error'])
where
makeTeam :: TeamMember -> R.Element
makeTeam { username, shared_folder_id } = H.div {className: "from-group row"} [ H.div { className: "col-8" } [ H.text username ]
, H.a { className: "text-danger col-2 fa fa-times"
, title: "Remove user from team"
, type: "button"
, on: {click: submit shared_folder_id }
} []
]
submit sharedFolderId _ = do
runAff_ callback $ saveDeleteTeam { session, nodeId, sharedFolderId }
callback res =
case res of
Left _ -> do
_ <- liftEffect $ T.write "Only the Team owner can remove users" error
pure unit
Right val ->
case val of
Left _ -> do
pure unit
Right r -> do
T.write_ (filter (\tm -> tm.shared_folder_id /= r) team') team
-------------------------------------------------------------
type LoadProps =
(
session :: Session,
nodeId :: Int
)
loadTeam :: Record LoadProps -> AffRESTError (Array TeamMember)
loadTeam { session, nodeId } = getTeam session nodeId
type DeleteProps =
(
session :: Session,
nodeId :: Int,
sharedFolderId :: Int
)
saveDeleteTeam ∷ Record DeleteProps -> AffRESTError Int
saveDeleteTeam { session, nodeId, sharedFolderId } = deleteTeamMembership session sharedFolderId nodeId
src/Gargantext/Components/Forest/Tree/Node/Box.purs
View file @
fb4c948f
...
...
@@ -22,6 +22,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Types (Action)
import Gargantext.Components.Forest.Tree.Node.Action.Update (update)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (actionUpload)
import Gargantext.Components.Forest.Tree.Node.Action.WriteNodesDocuments (actionWriteNodesDocuments)
import Gargantext.Components.Forest.Tree.Node.Action.ManageTeam (actionManageTeam)
import Gargantext.Components.Forest.Tree.Node.Box.Types (NodePopupProps, NodePopupS)
import Gargantext.Components.Forest.Tree.Node.Settings (NodeAction(..), SettingsBox(..), glyphiconNodeAction, settingsBox)
import Gargantext.Components.Forest.Tree.Node.Status (Status(..), hasStatus)
...
...
@@ -189,6 +190,7 @@ panelActionCpt = here.component "panelAction" cpt
cpt { action: Download, id, nodeType, session} _ = pure $ actionDownload { id, nodeType, session } []
cpt { action: Upload, dispatch, id, nodeType, session} _ = pure $ actionUpload { dispatch, id, nodeType, session } []
cpt { action: Delete, nodeType, dispatch} _ = pure $ actionDelete { dispatch, nodeType } []
cpt { action: ManageTeam, nodeType, id, session} _ = pure $ actionManageTeam { id, nodeType, session } []
cpt { action: Add xs, dispatch, id, name, nodeType} _ =
pure $ addNodeView {dispatch, id, name, nodeType, nodeTypes: xs} []
cpt { action: Refresh , dispatch, nodeType } _ = pure $ update { dispatch, nodeType } []
...
...
src/Gargantext/Components/Forest/Tree/Node/Settings.purs
View file @
fb4c948f
...
...
@@ -16,6 +16,7 @@ data NodeAction = Documentation NodeType
| Download | Upload | Refresh | Config
| Delete
| Share
| ManageTeam
| Publish { subTreeParams :: SubTreeParams }
| Add (Array NodeType)
| Merge { subTreeParams :: SubTreeParams }
...
...
@@ -37,6 +38,7 @@ instance Eq NodeAction where
eq Clone Clone = true
eq Delete Delete = true
eq Share Share = true
eq ManageTeam ManageTeam = true
eq (Link x) (Link y) = x == y
eq (Add x) (Add y) = x == y
eq (Merge x) (Merge y) = x == y
...
...
@@ -57,6 +59,7 @@ instance Show NodeAction where
show Clone = "Clone"
show Delete = "Delete"
show Share = "Share"
show ManageTeam = "Team"
show Config = "Config"
show (Link _) = "Link to " -- <> show x
show (Add _) = "Add Child" -- foldl (\a b -> a <> show b) "Add " xs
...
...
@@ -78,6 +81,7 @@ glyphiconNodeAction (Merge _) = "random"
glyphiconNodeAction Refresh = "refresh"
glyphiconNodeAction Config = "wrench"
glyphiconNodeAction Share = "user-plus"
glyphiconNodeAction ManageTeam = "users"
glyphiconNodeAction AddingContact = "user-plus"
glyphiconNodeAction (Move _) = "share-square-o"
glyphiconNodeAction (Publish _) = fldr FolderPublic true
...
...
@@ -137,6 +141,7 @@ settingsBox Team =
, NodeFrameVisio
]
, Share
, ManageTeam
, Delete
]
}
...
...
src/Gargantext/Components/GraphQL.purs
View file @
fb4c948f
...
...
@@ -14,6 +14,7 @@ import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.Team (TeamMember, TeamDeleteM)
import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..))
import Gargantext.Utils.Reactix as R2
...
...
@@ -77,7 +78,9 @@ type Schema
, users :: { user_id :: Int } ==> Array User
, tree :: { root_id :: Int } ==> TreeFirstLevel
, annuaire_contacts :: { contact_id :: Int } ==> Array AnnuaireContact
, team :: { team_node_id :: Int } ==> Array TeamMember
}
type Mutation
= { update_user_info :: UserInfoM ==> Int }
= { update_user_info :: UserInfoM ==> Int
, delete_team_membership :: TeamDeleteM ==> Array Int }
src/Gargantext/Components/GraphQL/Endpoints.purs
View file @
fb4c948f
...
...
@@ -2,22 +2,24 @@ module Gargantext.Components.GraphQL.Endpoints where
import Gargantext.Prelude
import Gargantext.Components.GraphQL.Node (Node, nodeParentQuery, nodesQuery)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
import Data.Array as A
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL (queryGql)
import Gargantext.Components.GraphQL (
getClient,
queryGql)
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node, nodeParentQuery, nodesQuery)
import Gargantext.Components.GraphQL.Team (TeamMember, teamQuery)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
import Gargantext.Config.REST (RESTError(..), AffRESTError)
import Gargantext.Sessions (Session)
import Gargantext.Sessions (Session
(..)
)
import Gargantext.Types (NodeType)
import Gargantext.Utils.Reactix as R2
import Gargnatext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Query (mutation)
import GraphQL.Client.Variables (withVars)
here :: R2.Here
...
...
@@ -70,3 +72,28 @@ getTreeFirstLevel session id = do
{ tree } <- queryGql session "get tree first level" $ treeFirstLevelQuery `withVars` { id }
liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree
pure $ Right tree -- TODO: error handling
getTeam :: Session -> Int -> AffRESTError (Array TeamMember)
getTeam session id = do
{ team } <- queryGql session "get team" $ teamQuery `withVars` { id }
liftEffect $ here.log2 "[getTree] data" team
pure $ Right team
type SharedFolderId = Int
type TeamNodeId = Int
deleteTeamMembership :: Session -> SharedFolderId -> TeamNodeId -> AffRESTError Int
deleteTeamMembership session sharedFolderId teamNodeId = do
let token = getToken session
client <- liftEffect $ getClient session
{ delete_team_membership } <- mutation
client
"delete_team_membership"
{ delete_team_membership: onlyArgs { token: token
, shared_folder_id: sharedFolderId
, team_node_id: teamNodeId } }
pure $ case A.head delete_team_membership of
Nothing -> Left (CustomError $ "Failed to delete team membership. team node id=" <> show teamNodeId <> " shared folder id=" <> show sharedFolderId)
Just _ -> Right sharedFolderId
where
getToken (Session { token }) = token
src/Gargantext/Components/GraphQL/Team.purs
0 → 100644
View file @
fb4c948f
module Gargantext.Components.GraphQL.Team where
import Gargantext.Prelude
import GraphQL.Client.Args (NotNull, (=>>))
import GraphQL.Client.Variable (Var(..))
type TeamMember
= { username :: String
, shared_folder_id :: Int
}
type TeamDeleteM
= { token :: NotNull String
, shared_folder_id :: Int
, team_node_id :: Int
}
teamQuery = { team: { team_node_id: Var :: _ "id" Int } =>>
{ username: 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