-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(WebexParticipantRoster): add participant roster component
- Loading branch information
1 parent
69d46d5
commit d53a34e
Showing
7 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/components/WebexParticipantRoster/WebexParticipantRoster.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {List} from '@momentum-ui/react'; | ||
|
||
import WebexParticipant from '../WebexParticipant/WebexParticipant'; | ||
import useParticipants from '../hooks/useParticipants'; | ||
|
||
/** | ||
* Displays the roster of Webex meeting or room participants. | ||
* | ||
* @param {string} props.location the roster of Webex meeting or room participants. | ||
* | ||
* @returns {object} JSX of the component | ||
*/ | ||
export default function WebexParticipantRoster({destination}) { | ||
const participants = useParticipants(destination); | ||
|
||
const participantList = participants.map((participant) => <WebexParticipant personID={participant.personID} />); | ||
|
||
return <List>{participantList}</List>; | ||
} | ||
|
||
WebexParticipantRoster.propTypes = { | ||
destination: PropTypes.string.isRequired, | ||
}; |
20 changes: 20 additions & 0 deletions
20
src/components/WebexParticipantRoster/WebexParticipantRoster.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import {storiesOf} from '@storybook/react'; | ||
|
||
import jsonData from '../../data'; | ||
import {WebexJSONAdapter} from '../../adapters'; | ||
|
||
import WebexParticipantRoster from './WebexParticipantRoster'; | ||
|
||
import {WebexDataProvider} from '..'; | ||
|
||
// Setup for the stories | ||
const stories = storiesOf('Webex Participant Roster', module); | ||
const webexAdapter = new WebexJSONAdapter(jsonData); | ||
|
||
// Stories | ||
stories.add('default', () => ( | ||
<WebexDataProvider adapter={webexAdapter}> | ||
<WebexParticipantRoster destination="default_membership" /> | ||
</WebexDataProvider> | ||
)); |
13 changes: 13 additions & 0 deletions
13
src/components/WebexParticipantRoster/WebexParticipantRoster.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
|
||
import WebexParticipantRoster from './WebexParticipantRoster'; | ||
|
||
jest.mock('../hooks/usePerson'); | ||
|
||
describe('Webex Participant Roster component', () => { | ||
describe('snapshot', () => { | ||
test('matches snapshot of webex participant roster', () => { | ||
expect(shallow(<WebexParticipantRoster destination="default_membership" />)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/components/WebexParticipantRoster/__snapshots__/WebexParticipantRoster.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Webex Participant Roster component snapshot matches snapshot of webex participant roster 1`] = ` | ||
<List | ||
active={null} | ||
className="" | ||
focus={null} | ||
focusFirst={true} | ||
focusFirstQuery="" | ||
focusQuery="" | ||
id={null} | ||
itemRole="listitem" | ||
onSelect={null} | ||
role="list" | ||
shouldFocusActive={false} | ||
shouldFocusInitial={true} | ||
shouldLoop={true} | ||
tabType="vertical" | ||
trackActive={true} | ||
type={null} | ||
wrap={false} | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {useContext} from 'react'; | ||
|
||
export default function useParticipants(membershipID) { | ||
const datasource = useContext(); | ||
let participants = {...datasource.membershipsAdapter[membershipID]}; | ||
|
||
if (!(membershipID in datasource.membershipsAdapter)) { | ||
participants = []; | ||
} | ||
|
||
return participants; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {useEffect, useContext, useState} from 'react'; | ||
|
||
import {AdapterContext} from '../../components/'; | ||
|
||
/** | ||
* Custom hook that returns a list of participant IDs given a membership ID. | ||
* | ||
* @param {string} membershipID ID of the room/meeting that contains the participants | ||
* @returns {Array.<Person>} List of the person IDs from the participants | ||
*/ | ||
export default function useParticipants(membershipID) { | ||
const [participants, setParticipants] = useState([]); | ||
const {membershipsAdapter} = useContext(AdapterContext); | ||
|
||
useEffect(() => { | ||
const onError = (error) => { | ||
setParticipants([]); | ||
|
||
// eslint-disable-next-line no-console | ||
console.error(error.message); | ||
}; | ||
const onMembers = (data) => { | ||
setParticipants(data.members); | ||
}; | ||
|
||
const subscription = membershipsAdapter.getMembers(membershipID).subscribe(onMembers, onError); | ||
|
||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
}, [membershipsAdapter, membershipID]); | ||
|
||
return participants; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters