From 4bc09f942d08eac51f0dc78c4b6dd1bc49a1f1bc Mon Sep 17 00:00:00 2001 From: oliver fu Date: Wed, 18 Oct 2023 18:45:43 -0700 Subject: [PATCH 01/10] add relationship (need to clean up later) --- src/components/Modals/AddContactModal.jsx | 50 ++++++++++++++++++++++- src/constants/index.js | 4 +- src/constants/relationship_status.js | 7 ++++ src/constants/relationships.js | 7 ++++ src/hooks/useContactsList.js | 6 +++ src/pages/Contacts.jsx | 5 ++- 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/constants/relationship_status.js create mode 100644 src/constants/relationships.js diff --git a/src/components/Modals/AddContactModal.jsx b/src/components/Modals/AddContactModal.jsx index d670b7428..5f93a130a 100644 --- a/src/components/Modals/AddContactModal.jsx +++ b/src/components/Modals/AddContactModal.jsx @@ -11,6 +11,10 @@ import FormControl from '@mui/material/FormControl'; import IconButton from '@mui/material/IconButton'; import InputAdornment from '@mui/material/InputAdornment'; import TextField from '@mui/material/TextField'; +import InputLabel from '@mui/material/InputLabel'; +import Select from '@mui/material/Select'; +import MenuItem from '@mui/material/MenuList'; +import { RELATIONSHIPS, RELATIONSHIP_STATUS } from '@constants'; // Component Imports import { FormSection } from '../Form'; import useNotification from '../../hooks/useNotification'; @@ -44,8 +48,12 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod const [userFamilyName, setUserFamilyName] = useState(''); const [username, setUsername] = useState(''); const [webId, setWebId] = useState(''); + const [pod, setPod] = useState(''); + const [relationship, setRelationship] = useState(''); + const [relationshipStatus, setRelationshipStatus] = useState(''); const [processing, setProcessing] = useState(false); + const wrappedSetUsername = (value) => { setUsername(value); const renderedWebId = renderWebId(value); @@ -58,7 +66,10 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod const userObject = { givenName: event.target.addUserGivenName.value, familyName: event.target.addUserFamilyName.value, - webId: event.target.addWebId.value + webId: event.target.addWebId.value, + pod: event.target.pod, + relationship: event.target.relationship, + relationshipStatus: event.target.relationshipStatus }; try { @@ -88,6 +99,7 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod
+ + setPod(e.target.value)} + fullWidth + /> + Relationship + + Relationship Status + {data.length > 0 ? ( Date: Tue, 24 Oct 2023 23:33:15 -0700 Subject: [PATCH 02/10] use getPodUrlAll --- src/components/Modals/AddContactModal.jsx | 15 +++++++++------ src/constants/rdf_predicates.js | 4 +++- src/constants/relationship_status.js | 1 + src/constants/relationships.js | 1 + src/hooks/useContactsList.js | 23 ++++++++++++++++++----- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/components/Modals/AddContactModal.jsx b/src/components/Modals/AddContactModal.jsx index 5f93a130a..541bd0f0d 100644 --- a/src/components/Modals/AddContactModal.jsx +++ b/src/components/Modals/AddContactModal.jsx @@ -67,9 +67,9 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod givenName: event.target.addUserGivenName.value, familyName: event.target.addUserFamilyName.value, webId: event.target.addWebId.value, - pod: event.target.pod, - relationship: event.target.relationship, - relationshipStatus: event.target.relationshipStatus + pod: event.target.pod.value, + relationship: event.target.relationship.value, + relationshipStatus: event.target.relationshipStatus.value }; try { @@ -161,7 +161,7 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod margin="normal" id="pod" name="addPod" - label="pod" + label="Pod URL" autoComplete="pod" value={pod} onChange={(e) => setPod(e.target.value)} @@ -170,12 +170,14 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod Relationship setRelationshipStatus(e.target.value)} diff --git a/src/constants/rdf_predicates.js b/src/constants/rdf_predicates.js index 9168ee413..e9c95507e 100644 --- a/src/constants/rdf_predicates.js +++ b/src/constants/rdf_predicates.js @@ -30,7 +30,9 @@ const RDF_PREDICATES = { nickname: FOAF.nick, dateCreated: 'https://schema.org/dateCreated', propertyValue: 'https://schema.org/PropertyValue', - value: 'https://schema.org/value' + value: 'https://schema.org/value', + role: 'https://schema.org/Role', + status: 'https://schema.org/status' }; export default RDF_PREDICATES; diff --git a/src/constants/relationship_status.js b/src/constants/relationship_status.js index 2000f54bd..02a63f83b 100644 --- a/src/constants/relationship_status.js +++ b/src/constants/relationship_status.js @@ -1,4 +1,5 @@ const RELATIONSHIP_STATUS = { + BLANK: '', ACTIVE: 'self', ARCHIVED: 'cross', ETC: 'etc' diff --git a/src/constants/relationships.js b/src/constants/relationships.js index 4c01ce32d..cfa4d8f0e 100644 --- a/src/constants/relationships.js +++ b/src/constants/relationships.js @@ -1,4 +1,5 @@ const RELATIONSHIPS = { + Blank: '', Client: 'Client', CaseManagement: 'Case Management', AssociatedOrg: 'Associated Organization', diff --git a/src/hooks/useContactsList.js b/src/hooks/useContactsList.js index 1edf44864..8bc5bbcdf 100644 --- a/src/hooks/useContactsList.js +++ b/src/hooks/useContactsList.js @@ -10,23 +10,36 @@ import { setThing, createSolidDataset, getSolidDataset, - saveSolidDatasetAt + saveSolidDatasetAt, + getPodUrlAll } from '@inrupt/solid-client'; import { RDF_PREDICATES } from '@constants'; import useSession from './useSession'; -const makeContactIntoThing = ({ givenName, familyName, webId }) => +// optional: the person's preferred pod url. +// If not present, we fetch the first pod url on the profile document. +// If that's not present, we derive it from the webid + +const fetchAlternatePodUrl = webId => { + const urls = getPodUrlAll(webId); + const firstURL = urls[0]; + const result = urls ? firstURL : webId; + return result; +}; + +const makeContactIntoThing = ({ givenName, familyName, webId, pod, relationship, relationshipStatus }) => buildThing(createThing({ name: encodeURIComponent(webId) })) .addStringNoLocale(RDF_PREDICATES.Person, `${givenName} ${familyName}`) .addStringNoLocale(RDF_PREDICATES.givenName, givenName) .addStringNoLocale(RDF_PREDICATES.familyName, familyName) .addUrl(RDF_PREDICATES.identifier, webId) .addUrl(RDF_PREDICATES.URL, webId.split('profile')[0]) - .addUrl(pod, pod) - .addStringNoLocale(relationship, relationship) - .addStringNoLocale(relationshipStatus, relationshipStatus) + .addUrl(RDF_PREDICATES.profileName, pod ? pod : fetchAlternatePodUrl(webId)) + .addStringNoLocale(RDF_PREDICATES.role, relationship) + .addStringNoLocale(RDF_PREDICATES.status, relationshipStatus) .build(); + const parseContacts = (data) => { const contactThings = getThingAll(data); const contacts = []; From 0f3cbaa5a62a4ed5c8a1ae57d569be31ccfa4c91 Mon Sep 17 00:00:00 2001 From: oliver fu Date: Tue, 24 Oct 2023 23:41:01 -0700 Subject: [PATCH 03/10] clean up --- src/hooks/useContactsList.js | 7 ------- src/pages/Contacts.jsx | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/hooks/useContactsList.js b/src/hooks/useContactsList.js index 8bc5bbcdf..25f71be03 100644 --- a/src/hooks/useContactsList.js +++ b/src/hooks/useContactsList.js @@ -16,10 +16,6 @@ import { import { RDF_PREDICATES } from '@constants'; import useSession from './useSession'; -// optional: the person's preferred pod url. -// If not present, we fetch the first pod url on the profile document. -// If that's not present, we derive it from the webid - const fetchAlternatePodUrl = webId => { const urls = getPodUrlAll(webId); const firstURL = urls[0]; @@ -112,9 +108,6 @@ const useContactsList = () => { const thing = makeContactIntoThing(newContact); const newDataset = setThing(data, thing); const savedDataset = await saveData(newDataset); - console.table(newContact); - console.table(data); - console.table(thing); return savedDataset; }, onSuccess: (resData) => { diff --git a/src/pages/Contacts.jsx b/src/pages/Contacts.jsx index 5eff14b08..8a5e06cfa 100644 --- a/src/pages/Contacts.jsx +++ b/src/pages/Contacts.jsx @@ -69,7 +69,7 @@ const Contacts = () => { onClick={() => setShowAddContactModal(true)} sx={{ marginTop: '3rem' }} > - Add Contact {url} hello + Add Contact {data.length > 0 ? ( Date: Tue, 31 Oct 2023 22:31:11 -0700 Subject: [PATCH 04/10] save quote-unquote progress --- src/hooks/useContactsList.js | 20 +++++++++++++------- src/pages/Contacts.jsx | 5 +---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/hooks/useContactsList.js b/src/hooks/useContactsList.js index 25f71be03..283d36c46 100644 --- a/src/hooks/useContactsList.js +++ b/src/hooks/useContactsList.js @@ -15,27 +15,33 @@ import { } from '@inrupt/solid-client'; import { RDF_PREDICATES } from '@constants'; import useSession from './useSession'; +// currently works if pod is given -const fetchAlternatePodUrl = webId => { - const urls = getPodUrlAll(webId); - const firstURL = urls[0]; - const result = urls ? firstURL : webId; +const fetchAlternatePodUrl = async (webId) => { + const urls = await getPodUrlAll(webId, { fetch }); + const result = urls?.length > 0 ? urls[0] : webId; return result; }; -const makeContactIntoThing = ({ givenName, familyName, webId, pod, relationship, relationshipStatus }) => +const makeContactIntoThing = ({ + givenName, + familyName, + webId, + pod, + relationship, + relationshipStatus +}) => buildThing(createThing({ name: encodeURIComponent(webId) })) .addStringNoLocale(RDF_PREDICATES.Person, `${givenName} ${familyName}`) .addStringNoLocale(RDF_PREDICATES.givenName, givenName) .addStringNoLocale(RDF_PREDICATES.familyName, familyName) .addUrl(RDF_PREDICATES.identifier, webId) .addUrl(RDF_PREDICATES.URL, webId.split('profile')[0]) - .addUrl(RDF_PREDICATES.profileName, pod ? pod : fetchAlternatePodUrl(webId)) + .addUrl(RDF_PREDICATES.profileName, pod || fetchAlternatePodUrl(webId)) .addStringNoLocale(RDF_PREDICATES.role, relationship) .addStringNoLocale(RDF_PREDICATES.status, relationshipStatus) .build(); - const parseContacts = (data) => { const contactThings = getThingAll(data); const contacts = []; diff --git a/src/pages/Contacts.jsx b/src/pages/Contacts.jsx index 910c8fc57..17132bd47 100644 --- a/src/pages/Contacts.jsx +++ b/src/pages/Contacts.jsx @@ -11,7 +11,6 @@ import { useContactsList, useNotification } from '@hooks'; import { AddContactModal, ConfirmationModal } from '@components/Modals'; import { ContactListTable } from '@components/Contacts'; import { LoadingAnimation, EmptyListNotification } from '@components/Notification'; -import useSession from '../hooks/useSession'; /** * Contacts Component - Component that generates Contacts Page for PASS @@ -28,8 +27,6 @@ const Contacts = () => { const [selectedContactToDelete, setSelectedContactToDelete] = useState(null); const { data, isLoading, isError, error, addContact, deleteContact } = useContactsList(); const { addNotification } = useNotification(); - const { podUrl } = useSession(); - const url = podUrl && new URL('PASS/Users/userlist.ttl', podUrl).toString(); const handleSelectDeleteContact = (contact) => { setSelectedContactToDelete(contact); @@ -70,7 +67,7 @@ const Contacts = () => { onClick={() => setShowAddContactModal(true)} sx={{ marginTop: '3rem' }} > - Add Contact + Add Contact {data.length > 0 ? ( Date: Tue, 7 Nov 2023 21:55:25 -0800 Subject: [PATCH 05/10] add relationship and relationship status, exclude podUrl from makeIntoThing --- src/hooks/useContactsList.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/hooks/useContactsList.js b/src/hooks/useContactsList.js index 706d21623..bb4c6214d 100644 --- a/src/hooks/useContactsList.js +++ b/src/hooks/useContactsList.js @@ -10,31 +10,22 @@ import { setThing, createSolidDataset, getSolidDataset, - saveSolidDatasetAt, - getPodUrlAll + saveSolidDatasetAt } from '@inrupt/solid-client'; import { RDF_PREDICATES } from '@constants'; import useSession from './useSession'; -// currently works if pod is given -const fetchAlternatePodUrl = async (webId) => { - const urls = await getPodUrlAll(webId, { fetch }); - const result = urls?.length > 0 ? urls[0] : webId; - return result; -}; - -const makeIntoThing = ({ givenName, familyName, webId, pod, relationship, relationshipStatus }) => +const makeIntoThing = ({ givenName, familyName, webId, relationship, relationshipStatus }) => buildThing(createThing({ name: encodeURIComponent(webId) })) .addStringNoLocale(RDF_PREDICATES.Person, `${givenName} ${familyName}`) .addStringNoLocale(RDF_PREDICATES.givenName, givenName) .addStringNoLocale(RDF_PREDICATES.familyName, familyName) .addUrl(RDF_PREDICATES.identifier, webId) .addUrl(RDF_PREDICATES.URL, webId.split('profile')[0]) - .addUrl(RDF_PREDICATES.profileName, pod || fetchAlternatePodUrl(webId)) .addStringNoLocale(RDF_PREDICATES.role, relationship) .addStringNoLocale(RDF_PREDICATES.status, relationshipStatus) .build(); - + /** * @typedef {object} ContactsList * @property {boolean} isLoading - if the contacts list is loading From d1b5987ff2987cad0318dbe16224723f642c220b Mon Sep 17 00:00:00 2001 From: oliver fu Date: Tue, 7 Nov 2023 22:16:42 -0800 Subject: [PATCH 06/10] clean up --- src/components/Modals/AddContactModal.jsx | 1 + src/hooks/useContactsList.js | 16 +++------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/components/Modals/AddContactModal.jsx b/src/components/Modals/AddContactModal.jsx index 4cd198e4d..f41866db0 100644 --- a/src/components/Modals/AddContactModal.jsx +++ b/src/components/Modals/AddContactModal.jsx @@ -90,6 +90,7 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod setUserFamilyName(''); setUsername(''); setWebId(''); + setPod(''); setShowAddContactModal(false); setProcessing(false); } diff --git a/src/hooks/useContactsList.js b/src/hooks/useContactsList.js index 78c24eda9..26c014469 100644 --- a/src/hooks/useContactsList.js +++ b/src/hooks/useContactsList.js @@ -8,18 +8,6 @@ import { import { RDF_PREDICATES } from '@constants'; import useSession from './useSession'; import useRdfCollection from './useRdfCollection'; - - -const makeIntoThing = ({ givenName, familyName, webId, relationship, relationshipStatus }) => - buildThing(createThing({ name: encodeURIComponent(webId) })) - .addStringNoLocale(RDF_PREDICATES.Person, `${givenName} ${familyName}`) - .addStringNoLocale(RDF_PREDICATES.givenName, givenName) - .addStringNoLocale(RDF_PREDICATES.familyName, familyName) - .addUrl(RDF_PREDICATES.identifier, webId) - .addUrl(RDF_PREDICATES.URL, webId.split('profile')[0]) - .addStringNoLocale(RDF_PREDICATES.role, relationship) - .addStringNoLocale(RDF_PREDICATES.status, relationshipStatus) - .build(); /** * @typedef {object} ContactsList @@ -60,13 +48,15 @@ const useContactsList = () => { return contacts; }; - const serialize = ({ givenName, familyName, webId }) => + const serialize = ({ givenName, familyName, webId, relationship, relationshipStatus }) => buildThing(createThing({ name: encodeURIComponent(webId) })) .addStringNoLocale(RDF_PREDICATES.Person, `${givenName} ${familyName}`) .addStringNoLocale(RDF_PREDICATES.givenName, givenName) .addStringNoLocale(RDF_PREDICATES.familyName, familyName) .addUrl(RDF_PREDICATES.identifier, webId) .addUrl(RDF_PREDICATES.URL, webId.split('profile')[0]) + .addStringNoLocale(RDF_PREDICATES.role, relationship) + .addStringNoLocale(RDF_PREDICATES.status, relationshipStatus) .build(); const hook = useRdfCollection(parse, serialize, fileUrl, fetch); From 3573305d197fe54cda94e6a7cce187735bf0616d Mon Sep 17 00:00:00 2001 From: oliver fu Date: Tue, 14 Nov 2023 00:12:52 -0800 Subject: [PATCH 07/10] do some requested changes --- src/components/Modals/AddContactModal.jsx | 22 ++-------------------- src/constants/relationship_status.js | 6 +++--- src/constants/relationships.js | 10 +++++----- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/components/Modals/AddContactModal.jsx b/src/components/Modals/AddContactModal.jsx index f41866db0..f22dff286 100644 --- a/src/components/Modals/AddContactModal.jsx +++ b/src/components/Modals/AddContactModal.jsx @@ -1,7 +1,6 @@ // React Imports import React, { useState } from 'react'; // Material UI Imports -import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import CheckIcon from '@mui/icons-material/Check'; import ClearIcon from '@mui/icons-material/Clear'; @@ -12,8 +11,6 @@ import FormControl from '@mui/material/FormControl'; import IconButton from '@mui/material/IconButton'; import InputAdornment from '@mui/material/InputAdornment'; import TextField from '@mui/material/TextField'; -import useMediaQuery from '@mui/material/useMediaQuery'; -import { useTheme } from '@mui/material/styles'; // Custom Hook Imports import useNotification from '@hooks/useNotification'; import InputLabel from '@mui/material/InputLabel'; @@ -52,12 +49,9 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod const [userFamilyName, setUserFamilyName] = useState(''); const [username, setUsername] = useState(''); const [webId, setWebId] = useState(''); - const [pod, setPod] = useState(''); const [relationship, setRelationship] = useState(''); const [relationshipStatus, setRelationshipStatus] = useState(''); const [processing, setProcessing] = useState(false); - const theme = useTheme(); - const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm')); const wrappedSetUsername = (value) => { setUsername(value); @@ -72,7 +66,6 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod givenName: event.target.addUserGivenName.value, familyName: event.target.addUserFamilyName.value, webId: event.target.addWebId.value, - pod: event.target.pod.value, relationship: event.target.relationship.value, relationshipStatus: event.target.relationshipStatus.value }; @@ -90,7 +83,6 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod setUserFamilyName(''); setUsername(''); setWebId(''); - setPod(''); setShowAddContactModal(false); setProcessing(false); } @@ -105,7 +97,6 @@ const AddContactModal = ({ addContact, showAddContactModal, setShowAddContactMod - - setPod(e.target.value)} - fullWidth - /> Relationship