Skip to content

Commit 8217c1a

Browse files
NathZ1Mnickiisebastienlevert
authored
MGT Person - Disable attempt to get user photo when using userId/personQuery and fetchImage=false (#1562)
Co-authored-by: Nickii Miaro <[email protected]> Co-authored-by: Sébastien Levert <[email protected]>
1 parent ae546e2 commit 8217c1a

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,19 @@ export class MgtPerson extends MgtTemplatedComponent {
345345
})
346346
public fetchImage: boolean;
347347

348+
/**
349+
* Sets whether to disable the person image fetch
350+
* from the Microsoft Graph
351+
*
352+
* @type {boolean}
353+
* @memberof MgtPerson
354+
*/
355+
@property({
356+
attribute: 'disable-image-fetch',
357+
type: Boolean
358+
})
359+
public disableImageFetch: boolean;
360+
348361
/**
349362
* Determines and sets person avatar
350363
*
@@ -526,6 +539,7 @@ export class MgtPerson extends MgtTemplatedComponent {
526539
this.line3Property = 'jobTitle';
527540
this.view = ViewType.image;
528541
this.avatarSize = 'auto';
542+
this.disableImageFetch = false;
529543
this._isInvalidImageSrc = false;
530544
this._avatarType = 'photo';
531545
}
@@ -1019,7 +1033,7 @@ export class MgtPerson extends MgtTemplatedComponent {
10191033
} else if (this.userId || this.personQuery === 'me') {
10201034
// Use userId or 'me' query to get the person and image
10211035
let person;
1022-
if (this._avatarType === 'photo') {
1036+
if (this._avatarType === 'photo' && !this.disableImageFetch) {
10231037
person = await getUserWithPhoto(graph, this.userId, personProps);
10241038
} else {
10251039
if (this.personQuery === 'me') {
@@ -1040,7 +1054,7 @@ export class MgtPerson extends MgtTemplatedComponent {
10401054

10411055
if (people && people.length) {
10421056
this.personDetailsInternal = people[0];
1043-
if (this._avatarType === 'photo') {
1057+
if (this._avatarType === 'photo' && !this.disableImageFetch) {
10441058
const image = await getPersonImage(graph, people[0], MgtPerson.config.useContactApis);
10451059

10461060
if (image) {

packages/mgt-react/src/generated/react.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export type PersonProps = {
170170
line3Property?: string;
171171
view?: ViewType | PersonViewType;
172172
avatarSize?: AvatarSize;
173+
disableImageFetch?: boolean;
173174
templateContext?: TemplateContext;
174175
mediaQuery?: ComponentMediaQuery;
175176
line1clicked?: (e: Event) => void;

stories/components/person/person.properties.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ export const personAvatarType = () => html`
268268
<mgt-person person-query="me" avatar-type="initials"></mgt-person>
269269
`;
270270

271+
export const personDisableImageFetch = () => html`
272+
<mgt-person person-query="me" disable-image-fetch></mgt-person>
273+
`;
274+
271275
export const moreExamples = () => html`
272276
<style>
273277
.example {

0 commit comments

Comments
 (0)