Commit 260a2fd1 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graphql] some user work

parent a554c2bd
Pipeline #1984 failed with stage
module Gargantext.Components.GraphQL where
import Gargantext.Prelude
import Affjax.RequestBody (RequestBody(..))
import Data.Argonaut.Decode (class DecodeJson)
import Data.Maybe (Maybe(..), maybe)
import Effect (Effect)
import Data.Array as A
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL.User
import Gargantext.Prelude
import Gargantext.Utils.Reactix as R2
import GraphQL.Client.Args (type (==>), (=>>))
import GraphQL.Client.Query (query_)
import GraphQL.Client.Types (class GqlQuery)
import GraphQL.Client.BaseClients.Urql
import GraphQL.Client.Query (query, query_)
import GraphQL.Client.Types (class GqlQuery, Client)
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
......@@ -32,14 +32,17 @@ graphQLTestCpt = here.component "graphQLTest" cpt where
user' <- T.useLive T.unequal userBox
R.useEffect' do
launchAff_ $ do
{ user } <-
{ users } <-
queryGql "get user"
{ user: { user_id: 1 } =>> { userLight_id
, userLight_username
, userLight_password
, userLight_email } }
liftEffect $ here.log2 "[graphQLTest] user" user
liftEffect $ T.write_ (Just user) userBox
{ users: { user_id: 1 } =>> { userLight_id
, userLight_username
, userLight_password
, userLight_email } }
liftEffect $ do
here.log2 "[graphQLTest] users" users
case A.head users of
Nothing -> here.log2 "[graphQLTest] user not found with id" 1
Just u -> T.write_ (Just u) userBox
pure $ R2.row
--[ H.div { className: "col-12 d-flex justify-content-center" }
......@@ -62,31 +65,12 @@ queryGql ::
GqlQuery Schema query returns =>
DecodeJson returns =>
String -> query -> Aff returns
queryGql = query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema)
queryGql name q = do
client <- liftEffect $ createClient { headers: [], url: "http://localhost:8008/gql" }
query (client :: Client UrqlClient Schema _ _) name q
--query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema)
-- Schema
type Schema
= { user :: { user_id :: Int } ==> User
= { users :: { user_id :: Int } ==> Array User
}
type User
= { userLight_id :: Int
, userLight_username :: String
, userLight_password :: String
, userLight_email :: String
}
showUser { userLight_id
, userLight_username
, userLight_password
, userLight_email } = "[" <> show userLight_id <> "] " <> userLight_username <> " :: " <> userLight_email
showMUser u = maybe "" showUser u
-- Symbols
userLight_id :: Proxy "userLight_id"
userLight_id = Proxy
userLight_username :: Proxy "userLight_username"
userLight_username = Proxy
userLight_password :: Proxy "userLight_password"
userLight_password = Proxy
userLight_email :: Proxy "userLight_email"
userLight_email = Proxy
module Gargantext.Components.GraphQL.User where
import Data.Maybe (Maybe(..), maybe)
import Gargantext.Prelude
import Type.Proxy (Proxy(..))
type User
= { userLight_id :: Int
, userLight_username :: String
, userLight_password :: String
, userLight_email :: String
}
showUser { userLight_id
, userLight_username
, userLight_password
, userLight_email } = "[" <> show userLight_id <> "] " <> userLight_username <> " :: " <> userLight_email
showMUser u = maybe "" showUser u
-- Symbols
userLight_id :: Proxy "userLight_id"
userLight_id = Proxy
userLight_username :: Proxy "userLight_username"
userLight_username = Proxy
userLight_password :: Proxy "userLight_password"
userLight_password = Proxy
userLight_email :: Proxy "userLight_email"
userLight_email = Proxy
......@@ -6,18 +6,21 @@ module Gargantext.Components.Nodes.Annuaire.User
import Gargantext.Prelude
import Data.Either (Either)
import Data.Array as A
import Data.Either (Either(..))
import Data.Lens as L
import Data.Maybe (Maybe(..), fromMaybe)
import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Data (Boxes)
import Gargantext.Components.GraphQL (queryGql)
import Gargantext.Components.GraphQL.User
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Nodes.Annuaire.Tabs as Tabs
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (Contact(..), ContactData, ContactTouch(..), ContactWhere(..), ContactWho(..), HyperdataContact(..), HyperdataUser(..), _city, _country, _firstName, _labTeamDeptsJoinComma, _lastName, _mail, _office, _organizationJoinComma, _ouFirst, _phone, _role, _shared, _touch, _who, defaultContactTouch, defaultContactWhere, defaultContactWho, defaultHyperdataContact, defaultHyperdataUser)
import Gargantext.Components.Nodes.Lists.Types as LT
import Gargantext.Config.REST (RESTError, logRESTError)
import Gargantext.Config.REST (RESTError(..), logRESTError)
import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as Routes
......@@ -25,6 +28,9 @@ import Gargantext.Sessions (WithSession, WithSessionContext, Session, get, put,
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import GraphQL.Client.Args (type (==>), (=>>))
import GraphQL.Client.Query (query_)
import GraphQL.Client.Types (class GqlQuery)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
......@@ -102,16 +108,16 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
let value = (L.view cLens hyperdata) :: String
valueRef <- R.useRef value
pure $ H.div { className: "form-group row" } [
H.span { className: "col-sm-2 col-form-label" } [ H.text label ]
, item isEditing' isEditing valueRef
]
pure $ H.div { className: "form-group row" }
[ H.span { className: "col-sm-2 col-form-label" } [ H.text label ]
, item isEditing' isEditing valueRef
]
where
cLens = L.cloneLens lens
item false isEditing valueRef =
H.div { className: "input-group col-sm-6" } [
H.input { className: "form-control"
H.div { className: "input-group col-sm-6" }
[ H.input { className: "form-control"
, defaultValue: placeholder'
, disabled: 1
, type: "text" }
......@@ -124,8 +130,8 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
placeholder' = R.readRef valueRef
onClick _ = T.write_ true isEditing
item true isEditing valueRef =
H.div { className: "input-group col-sm-6" } [
inputWithEnter {
H.div { className: "input-group col-sm-6" }
[ inputWithEnter {
autoFocus: true
, className: "form-control"
, defaultValue: R.readRef valueRef
......@@ -136,8 +142,8 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
, type: "text"
}
, H.div { className: "btn input-group-append"
, on: { click: onClick } } [
H.div { className: "input-group-text fa fa-floppy-o" } []
, on: { click: onClick } }
[ H.div { className: "input-group-text fa fa-floppy-o" } []
]
]
where
......@@ -232,7 +238,27 @@ getContact session id = do
getUserWithReload :: { nodeId :: Int
, reload :: T2.Reload
, session :: Session} -> Aff (Either RESTError ContactData)
getUserWithReload {nodeId, session} = getContact session nodeId
getUserWithReload {nodeId, session} = getUser session nodeId -- getContact session nodeId
getUser :: Session -> Int -> Aff (Either RESTError ContactData)
getUser session id = do
{ users } <- queryGql "get user"
{ users: { user_id: id } =>> { userLight_id
, userLight_username
, userLight_password
, userLight_email } }
liftEffect $ here.log2 "[getUser] users" users
pure $ case A.head users of
Nothing -> Left (CustomError $ "user with id " <> show id <> " not found")
Just u -> Right $ { contactNode: Contact
{ id: u.userLight_id
, date: Nothing
, hyperdata: HyperdataUser { shared: Nothing }
, name: Just u.userLight_username
, parentId: Nothing
, typename: Nothing
, userId: Just u.userLight_id }
, defaultListId: 424242 }
saveContactHyperdata :: Session -> Int -> HyperdataUser -> Aff (Either RESTError Int)
saveContactHyperdata session id h = do
......
......@@ -8,7 +8,6 @@ import Effect (Effect)
import Gargantext.Components.App.Data (Boxes)
import Gargantext.Components.Data.Landing (BlockText(..), BlockTexts(..), Button(..), LandingData(..))
import Gargantext.Components.FolderView as FV
import Gargantext.Components.GraphQL (graphQLTest)
import Gargantext.Components.Lang (LandingLang(..))
import Gargantext.Components.Lang.Landing.EnUS as En
import Gargantext.Components.Lang.Landing.FrFR as Fr
......@@ -82,8 +81,6 @@ homeLayoutCpt = here.component "homeLayout" cpt
, H.div { className: "home-landing-data container1" }
[ blocksRandomText' landingData ]
, license
, graphQLTest {} []
]
] where
click mBackend _ =
......
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