Skip to content

Commit ad6b37a

Browse files
vogtnnmetulev
andauthored
[mgt-people] fallback details feature (#1355)
Co-authored-by: Nikola Metulev <[email protected]>
1 parent 52e76ce commit ad6b37a

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

packages/mgt-components/src/components/mgt-people/mgt-people.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,27 @@ export class MgtPeople extends MgtTemplatedComponent {
210210
})
211211
public scopes: string[] = [];
212212

213+
/**
214+
* Fallback when no user is found
215+
* @type {IDynamicPerson[]}
216+
*/
217+
@property({
218+
attribute: 'fallback-details',
219+
type: Array
220+
})
221+
public get fallbackDetails(): IDynamicPerson[] {
222+
return this._fallbackDetails;
223+
}
224+
public set fallbackDetails(value: IDynamicPerson[]) {
225+
if (value === this._fallbackDetails) {
226+
return;
227+
}
228+
229+
this._fallbackDetails = value;
230+
231+
this.requestStateUpdate();
232+
}
233+
213234
/**
214235
* Get the scopes required for people
215236
*
@@ -236,6 +257,7 @@ export class MgtPeople extends MgtTemplatedComponent {
236257
private _peoplePresence: {};
237258
private _resource: string;
238259
private _version: string = 'v1.0';
260+
private _fallbackDetails: IDynamicPerson[];
239261

240262
constructor() {
241263
super();
@@ -304,7 +326,6 @@ export class MgtPeople extends MgtTemplatedComponent {
304326
*/
305327
protected renderPeople(): TemplateResult {
306328
const maxPeople = this.people.slice(0, this.showMax);
307-
308329
return html`
309330
<ul class="people-list">
310331
${repeat(
@@ -405,10 +426,21 @@ export class MgtPeople extends MgtTemplatedComponent {
405426
// populate people
406427
if (this.groupId) {
407428
this.people = await findGroupMembers(graph, null, this.groupId, this.showMax, PersonType.person);
408-
} else if (this.userIds) {
409-
this.people = await getUsersForUserIds(graph, this.userIds);
410-
} else if (this.peopleQueries) {
411-
this.people = await getUsersForPeopleQueries(graph, this.peopleQueries);
429+
} else if (this.userIds || this.peopleQueries) {
430+
this.userIds
431+
? (this.people = await getUsersForUserIds(graph, this.userIds))
432+
: (this.people = await getUsersForPeopleQueries(graph, this.peopleQueries));
433+
if (this._fallbackDetails) {
434+
// replace null people with fallback details
435+
this.people = this.people.map((p, i) => {
436+
if (p) {
437+
return p;
438+
} else if (i < this._fallbackDetails.length) {
439+
return this._fallbackDetails[i];
440+
}
441+
return null;
442+
});
443+
}
412444
} else if (this.resource) {
413445
this.people = await getPeopleFromResource(graph, this.version, this.resource, this.scopes);
414446
} else {

packages/mgt-components/src/graph/graph.user.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ export async function getUser(graph: IGraph, userPrincipleName: string, requeste
118118
}
119119

120120
// else we must grab it
121-
const response = await graph.api(apiString).middlewareOptions(prepScopes(scopes)).get();
121+
let response;
122+
try {
123+
response = await graph.api(apiString).middlewareOptions(prepScopes(scopes)).get();
124+
} catch (_) {}
125+
122126
if (getIsUsersCacheEnabled()) {
123127
cache.putValue(userPrincipleName, { user: JSON.stringify(response) });
124128
}
@@ -254,6 +258,8 @@ export async function getUsersForPeopleQueries(graph: IGraph, peopleQueries: str
254258
if (getIsUsersCacheEnabled()) {
255259
cache.putValue(personQuery, { maxResults: 1, results: [JSON.stringify(response.content.value[0])] });
256260
}
261+
} else {
262+
people.push(null);
257263
}
258264
}
259265

stories/components/people/people.properties.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,19 @@ export const PersonCard = () => html`
5050
<div style="margin-bottom:10px">Person card Click</div>
5151
<mgt-people show-max="5" person-card="click"></mgt-people>
5252
`;
53+
54+
export const FallbackDetails = () => html`
55+
<mgt-people
56+
user-ids="2804bc07-1e1f-4938-9085-ce6d756a32d2, [email protected]"
57+
fallback-details='[{"mail": "[email protected]"},{"displayName": "[email protected]", "mail":"[email protected]"}]'
58+
>
59+
</mgt-people>
60+
`;
61+
62+
export const FallbackDetailsPeopleQuery = () => html`
63+
<mgt-people
64+
65+
fallback-details='[{ "mail":"[email protected]"},{"mail": "[email protected]"}]'
66+
>
67+
</mgt-people>
68+
`;

0 commit comments

Comments
 (0)