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
0c2ecf5b
Commit
0c2ecf5b
authored
Mar 02, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[user] contacts page work with lenses
parent
86444f97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
24 deletions
+67
-24
Contacts.purs
src/Gargantext/Components/Nodes/Annuaire/User/Contacts.purs
+38
-18
Types.purs
...antext/Components/Nodes/Annuaire/User/Contacts/Types.purs
+29
-6
No files found.
src/Gargantext/Components/Nodes/Annuaire/User/Contacts.purs
View file @
0c2ecf5b
...
...
@@ -8,7 +8,7 @@ import Data.Array (head)
import Data.Lens as L
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested (
Tuple3,
(/\))
import Data.Newtype (unwrap)
import Data.String (joinWith)
import DOM.Simple.Console (log2)
...
...
@@ -99,17 +99,33 @@ getMail' :: ContactTouch -> String
getMail' = fromMaybe "Empty mail" <<< _.mail <<< unwrap
-- | TODO format data in better design (UI) shape
contactInfos :: HyperdataUser -> (HyperdataUser -> Effect Unit) -> Array R.Element
contactInfos h@(HyperdataUser { shared }) onUpdateHyperdata =
(item <$> contactInfoItems shared)
<> [ contactInfoItem {hyperdata: h, lens: _shared <<< _who <<< _lastName, onUpdateHyperdata} ]
contactInfos :: HyperdataUser -> (HyperdataUser -> Effect Unit) -> Array R.Element
contactInfos h onUpdateHyperdata = item <$> contactInfoItems
where
item (name /\ value) =
H.li { className: "list-group-item" }
(infoRender (name /\ (" " <> value)))
contactInfoItems :: Maybe HyperdataContact -> Array (Tuple String String)
contactInfoItems Nothing =
item (label /\ defaultVal /\ lens) =
contactInfoItem { hyperdata: h
, label
, lens
, onUpdateHyperdata }
-- item (name /\ value) =
-- H.li { className: "list-group-item" }
-- (infoRender (name /\ (" " <> value)))
contactInfoItems :: Array (Tuple3 String String HyperdataUserLens)
contactInfoItems =
[ "Last Name" /\ "Empty Last Name" /\ (_shared <<< _who <<< _lastName)
, "First Name" /\ "Empty First Name" /\ (_shared <<< _who <<< _firstName)
, "Organisation" /\ "Empty Organisation" /\ (_shared <<< _who <<< _lastName)
, "Lab/Team/Dept" /\ "Empty Lab/Team/Dept" /\ (_shared <<< _who <<< _lastName)
, "Office" /\ "Empty Office" /\ (_shared <<< _who <<< _lastName)
, "City" /\ "Empty City" /\ (_shared <<< _who <<< _lastName)
, "Country" /\ "Empty Country" /\ (_shared <<< _who <<< _lastName)
, "Role" /\ "Empty Role" /\ (_shared <<< _who <<< _lastName)
, "Phone" /\ "Empty Phone" /\ (_shared <<< _who <<< _lastName)
, "Mail" /\ "Empty Mail" /\ (_shared <<< _who <<< _lastName) ]
contactInfoItems' :: Maybe HyperdataContact -> Array (Tuple String String)
contactInfoItems' Nothing =
[ "Last Name" /\ "Empty Last Name"
, "First Name" /\ "Empty First Name"
, "Organisation" /\ "Empty Organisation"
...
...
@@ -120,7 +136,7 @@ contactInfoItems Nothing =
, "Role" /\ "Empty Role"
, "Phone" /\ "Empty Phone"
, "Mail" /\ "Empty Mail" ]
contactInfoItems (Just (HyperdataContact {who:who, ou:ou})) =
contactInfoItems
'
(Just (HyperdataContact {who:who, ou:ou})) =
[ "Last Name" /\ getLastName who
, "First Name" /\ getFirstName who
, "Organisation" /\ getOrga ou
...
...
@@ -132,11 +148,13 @@ contactInfoItems (Just (HyperdataContact {who:who, ou:ou})) =
, "Phone" /\ getPhone ou
, "Mail" /\ getMail ou ]
type HyperdataUserLens = L.Lens' HyperdataUser String
--type HyperdataUserLens = L.Lens' HyperdataUser String
type HyperdataUserLens = L.ALens' HyperdataUser String
type ContactInfoItemProps =
(
hyperdata :: HyperdataUser
, label :: String
, lens :: HyperdataUserLens
, onUpdateHyperdata :: HyperdataUser -> Effect Unit
)
...
...
@@ -148,15 +166,17 @@ contactInfoItemCpt :: R.Component ContactInfoItemProps
--contactInfoItemCpt :: forall r. R.Component ( lens :: L.Lens' HyperdataUser String | r )
contactInfoItemCpt = R.hooksComponent "G.C.N.A.U.C.contactInfoItem" cpt
where
cpt {hyperdata, lens, onUpdateHyperdata} _ = do
cpt {hyperdata, l
abel, l
ens, onUpdateHyperdata} _ = do
isEditing <- R.useState' false
let value = (L.view
l
ens hyperdata) :: String
let value = (L.view
cL
ens hyperdata) :: String
valueRef <- R.useRef value
pure $ H.li { className: "list-group-item" } [
item isEditing valueRef
H.span { className: "badge badge-default badge-pill"} [ H.text label ]
, item isEditing valueRef
]
where
cLens = L.cloneLens lens
item (false /\ setIsEditing) valueRef =
H.span {} [
H.text $ R.readRef valueRef
...
...
@@ -176,8 +196,8 @@ contactInfoItemCpt = R.hooksComponent "G.C.N.A.U.C.contactInfoItem" cpt
where
onClick _ = do
setIsEditing $ const false
-- let newHyperdata = (L.over l
ens (\_ -> R.readRef valueRef) hyperdata) :: HyperdataUser
--
onUpdateHyperdata newHyperdata
let newHyperdata = (L.over cL
ens (\_ -> R.readRef valueRef) hyperdata) :: HyperdataUser
onUpdateHyperdata newHyperdata
listInfo :: Tuple String String -> R.Element
listInfo s = listElement $ infoRender s
...
...
src/Gargantext/Components/Nodes/Annuaire/User/Contacts/Types.purs
View file @
0c2ecf5b
...
...
@@ -3,6 +3,7 @@ module Gargantext.Components.Nodes.Annuaire.User.Contacts.Types where
import Prelude
import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:!))
import Data.Array as A
import Data.Lens
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Map (Map)
...
...
@@ -96,6 +97,20 @@ instance decodeContactWhere :: DecodeJson ContactWhere
pure $ ContactWhere {organization:o, labTeamDepts:l, role, office, country, city, touch, entry, exit}
defaultContactWhere :: ContactWhere
defaultContactWhere =
ContactWhere {
organization: []
, labTeamDepts: []
, role: Nothing
, office: Nothing
, country: Nothing
, city: Nothing
, touch: Nothing
, entry: Nothing
, exit: Nothing
}
newtype ContactTouch =
ContactTouch
{ mail :: Maybe String
...
...
@@ -210,19 +225,27 @@ type ContactData = {contactNode :: Contact, defaultListId :: Int}
_shared :: Lens' HyperdataUser HyperdataContact
_shared = lens getter setter
where
getter (HyperdataUser h@{shared: Nothing}) = defaultHyperdataContact
getter (HyperdataUser h@{shared: Just shared'}) = shared'
getter (HyperdataUser h@{shared}) = fromMaybe defaultHyperdataContact shared
setter (HyperdataUser h) c = HyperdataUser $ h { shared = Just c }
_who :: Lens' HyperdataContact ContactWho
_who = lens getter setter
where
getter (HyperdataContact hc@{who: Nothing}) = defaultContactWho
getter (HyperdataContact hc@{who: Just who'}) = who'
getter (HyperdataContact hc@{who}) = fromMaybe defaultContactWho who
setter (HyperdataContact hc) w = HyperdataContact $ hc { who = Just w }
_ouFirst :: Lens' HyperdataContact ContactWhere
_ouFirst = lens getter setter
where
getter (HyperdataContact hc@{ou}) = fromMaybe defaultContactWhere $ A.head ou
setter (HyperdataContact hc@{ou}) o = HyperdataContact $ hc { ou = fromMaybe [o] $ A.updateAt 0 o ou }
_lastName :: Lens' ContactWho String
_lastName = lens getter setter
where
getter (ContactWho cw@{lastName: Nothing}) = ""
getter (ContactWho cw@{lastName: Just ln}) = ln
getter (ContactWho cw@{lastName}) = fromMaybe "" lastName
setter (ContactWho cw) ln = ContactWho $ cw { lastName = Just ln }
_firstName :: Lens' ContactWho String
_firstName = lens getter setter
where
getter (ContactWho cw@{firstName}) = fromMaybe "" firstName
setter (ContactWho cw) fn = ContactWho $ cw { firstName = Just fn }
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