Commit ba56cd7f authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

WIP [graphql] endpoints for annuaire contacts and contact user

NOTE This doesn't compile. The User page and Annuaire contacts need to
be split as they use completely different endpoints (getUserInfo and
getAnnuaireContact). Even though the returned data looks
similar (HyperdataContact).
parent 8377dbf5
Pipeline #2777 failed with stage
in 0 seconds
...@@ -10,6 +10,7 @@ import Effect (Effect) ...@@ -10,6 +10,7 @@ import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError) import Foreign (unsafeToForeign, ForeignError)
import Gargantext.Components.GraphQL.Annuaire as GQLA
import Gargantext.Components.GraphQL.IMT as GQLIMT import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node) import Gargantext.Components.GraphQL.Node (Node)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel) import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
...@@ -69,7 +70,8 @@ queryGql session name q = do ...@@ -69,7 +70,8 @@ queryGql session name q = do
-- Schema -- Schema
type Schema type Schema
= { imt_schools :: {} ==> Array GQLIMT.School = { annuaire_contacts :: { contact_id :: Int } ==> Array GQLA.AnnuaireContact
, imt_schools :: {} ==> Array GQLIMT.School
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType , node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType
, user_infos :: { user_id :: Int } ==> Array UserInfo , user_infos :: { user_id :: Int } ==> Array UserInfo
, users :: { user_id :: Int } ==> Array User , users :: { user_id :: Int } ==> Array User
......
module Gargantext.Components.GraphQL.Annuaire where
import Gargantext.Prelude
import Data.Array as A
import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import GraphQL.Client.Args (NotNull, (=>>))
import GraphQL.Client.Variable (Var(..))
type AnnuaireContact
= { ac_id :: Int
, ac_firstName :: Maybe String
, ac_lastName :: Maybe String }
annuaireContactQuery =
{ annuaire_contacts: { contact_id: Var :: _ "id" Int } =>>
{ ac_id: unit
, ac_firstName: unit
, ac_lastName: unit
}
}
_ac_firstName :: Lens' AnnuaireContact String
_ac_firstName = lens getter setter
where
getter ({ ac_firstName: val }) = fromMaybe "" val
setter ui val = ui { ac_firstName = Just val }
_ac_lastName :: Lens' AnnuaireContact String
_ac_lastName = lens getter setter
where
getter ({ ac_lastName: val }) = fromMaybe "" val
setter ui val = ui { ac_lastName = Just val }
module Gargantext.Components.GraphQL.Endpoints where module Gargantext.Components.GraphQL.Endpoints where
import Gargantext.Components.GraphQL.Annuaire
import Gargantext.Components.GraphQL.Node import Gargantext.Components.GraphQL.Node
import Gargantext.Components.GraphQL.User import Gargantext.Components.GraphQL.User
import Gargantext.Components.GraphQL.Tree import Gargantext.Components.GraphQL.Tree
...@@ -41,6 +42,15 @@ getNodeParent session nodeId parentType = do ...@@ -41,6 +42,15 @@ getNodeParent session nodeId parentType = do
liftEffect $ here.log2 "[getNodeParent] node_parent" node_parent liftEffect $ here.log2 "[getNodeParent] node_parent" node_parent
pure node_parent pure node_parent
getAnnuaireContact :: Session -> Int -> AffRESTError AnnuaireContact
getAnnuaireContact session id = do
{ annuaire_contacts } <- queryGql session "get annuaire contacts" $ annuaireContactQuery `withVars` { id }
liftEffect $ here.log2 "[getAnnuaireContact] annuaire_contacts" annuaire_contacts
pure $ case A.head annuaire_contacts of
Nothing -> Left (CustomError $ "contact with id " <> show id <> " not found")
-- NOTE Contact is at G.C.N.A.U.C.Types
Just ui -> Right ui
getUserInfo :: Session -> Int -> AffRESTError UserInfo getUserInfo :: Session -> Int -> AffRESTError UserInfo
getUserInfo session id = do getUserInfo session id = do
{ user_infos } <- queryGql session "get user infos" $ userInfoQuery `withVars` { id } { user_infos } <- queryGql session "get user infos" $ userInfoQuery `withVars` { id }
......
...@@ -66,7 +66,7 @@ displayCpt = here.component "display" cpt ...@@ -66,7 +66,7 @@ displayCpt = here.component "display" cpt
] ]
-- | TODO format data in better design (UI) shape -- | TODO format data in better design (UI) shape
contactInfos :: UserInfo -> (UserInfo -> Effect Unit) -> Array R.Element contactInfos :: AnnuaireContact -> (AnnuaireContact -> Effect Unit) -> Array R.Element
contactInfos userInfo onUpdateUserInfo = item <$> contactInfoItems where contactInfos userInfo onUpdateUserInfo = item <$> contactInfoItems where
item { label, lens, defaultVal } = item { label, lens, defaultVal } =
contactInfoItem { defaultVal, label, lens, onUpdateUserInfo, userInfo } contactInfoItem { defaultVal, label, lens, onUpdateUserInfo, userInfo }
...@@ -250,12 +250,12 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where ...@@ -250,12 +250,12 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where
cacheState <- T.useBox LT.CacheOn cacheState <- T.useBox LT.CacheOn
useLoader { errorHandler useLoader { errorHandler
--, loader: getAnnuaireContact session annuaireId --, loader: getAnnuaireContact session annuaireId
, loader: getUserInfo session , loader: getAnnuaireContact session
, path: nodeId , path: nodeId
, render: \userInfo@{ ui_username } -> , render: \annuaireContact@{ ac_id } ->
H.ul { className: "col-md-12 list-group" } H.ul { className: "col-md-12 list-group" }
[ display { title: fromMaybe "no name" (Just ui_username) } [ display { title: show ac_id }
(contactInfos userInfo (onUpdateUserInfo reload)) (contactInfos userInfo (onUpdateAnnuaireContact reload))
, Tabs.tabs , Tabs.tabs
{ boxes { boxes
, cacheState , cacheState
...@@ -269,11 +269,12 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where ...@@ -269,11 +269,12 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where
} }
where where
errorHandler = logRESTError here "[contactLayoutWithKey]" errorHandler = logRESTError here "[contactLayoutWithKey]"
onUpdateUserInfo :: T2.ReloadS -> UserInfo -> Effect Unit onUpdateAnnuaireContact :: T2.ReloadS -> AnnuaireContact -> Effect Unit
onUpdateUserInfo reload ui = do onUpdateAnnuaireContact _ _ = pure unit
launchAff_ $ do -- onUpdateAnnuaireContact reload ui = do
_ <- saveUserInfo session nodeId ui -- launchAff_ $ do
liftEffect (T2.reload reload) -- _ <- saveAnnuaireContact session nodeId ui
-- liftEffect (T2.reload reload)
getAnnuaireContact :: Session -> Int -> Int -> AffRESTError ContactData' getAnnuaireContact :: Session -> Int -> Int -> AffRESTError ContactData'
getAnnuaireContact session annuaireId id = do getAnnuaireContact session annuaireId id = do
......
This diff is collapsed.
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