@@ -13,7 +13,8 @@ import { getUsersForUserIds } from '../../graph/graph.user';
1313import { Providers } from '../../Providers' ;
1414import { ProviderState } from '../../providers/IProvider' ;
1515import '../../styles/fabric-icon-font' ;
16- import '../mgt-person/mgt-person' ;
16+ import { arraysAreEqual } from '../../utils/Utils' ;
17+ import { IDynamicPerson } from '../mgt-person/mgt-person' ;
1718import { MgtTemplatedComponent } from '../templatedComponent' ;
1819import { PersonCardInteraction } from './../PersonCardInteraction' ;
1920import { styles } from './mgt-people-css' ;
@@ -38,26 +39,6 @@ export class MgtPeople extends MgtTemplatedComponent {
3839 return styles ;
3940 }
4041
41- /**
42- * containing array of people used in the component.
43- * @type {Array<MgtPersonDetails> }
44- */
45- @property ( {
46- attribute : 'people' ,
47- type : Object
48- } )
49- public people : Array < MicrosoftGraph . User | MicrosoftGraph . Person | MicrosoftGraph . Contact > ;
50-
51- /**
52- * developer determined max people shown in component
53- * @type {number }
54- */
55- @property ( {
56- attribute : 'show-max' ,
57- type : Number
58- } )
59- public showMax : number ;
60-
6142 /**
6243 * determines if agenda events come from specific group
6344 * @type {string }
@@ -66,7 +47,16 @@ export class MgtPeople extends MgtTemplatedComponent {
6647 attribute : 'group-id' ,
6748 type : String
6849 } )
69- public groupId : string ;
50+ public get groupId ( ) : string {
51+ return this . _groupId ;
52+ }
53+ public set groupId ( value ) {
54+ if ( this . _groupId === value ) {
55+ return ;
56+ }
57+ this . _groupId = value ;
58+ this . requestStateUpdate ( true ) ;
59+ }
7060
7161 /**
7262 * user id array
@@ -76,19 +66,40 @@ export class MgtPeople extends MgtTemplatedComponent {
7666 @property ( {
7767 attribute : 'user-ids' ,
7868 converter : ( value , type ) => {
79- return value . split ( ',' ) ;
69+ return value . split ( ',' ) . map ( v => v . trim ( ) ) ;
8070 }
8171 } )
8272 public get userIds ( ) : string [ ] {
83- return this . privateUserIds ;
73+ return this . _userIds ;
8474 }
8575 public set userIds ( value : string [ ] ) {
86- const oldValue = this . userIds ;
87- this . privateUserIds = value ;
88- this . updateUserIds ( value ) ;
89- this . requestUpdate ( 'userIds' , oldValue ) ;
76+ if ( arraysAreEqual ( this . _userIds , value ) ) {
77+ return ;
78+ }
79+ this . _userIds = value ;
80+ this . requestStateUpdate ( true ) ;
9081 }
9182
83+ /**
84+ * containing array of people used in the component.
85+ * @type {Array<MgtPersonDetails> }
86+ */
87+ @property ( {
88+ attribute : 'people' ,
89+ type : Object
90+ } )
91+ public people : IDynamicPerson [ ] ;
92+
93+ /**
94+ * developer determined max people shown in component
95+ * @type {number }
96+ */
97+ @property ( {
98+ attribute : 'show-max' ,
99+ type : Number
100+ } )
101+ public showMax : number ;
102+
92103 /**
93104 * Sets how the person-card is invoked
94105 * Set to PersonCardInteraction.none to not show the card
@@ -109,14 +120,29 @@ export class MgtPeople extends MgtTemplatedComponent {
109120 } )
110121 public personCardInteraction : PersonCardInteraction = PersonCardInteraction . hover ;
111122
112- private privateUserIds : string [ ] ;
123+ private _groupId : string ;
124+ private _userIds : string [ ] ;
113125
114126 constructor ( ) {
115127 super ( ) ;
116128
117129 this . showMax = 3 ;
118130 }
119131
132+ /**
133+ * Request to reload the state.
134+ * Use reload instead of load to ensure loading events are fired.
135+ *
136+ * @protected
137+ * @memberof MgtBaseComponent
138+ */
139+ protected requestStateUpdate ( force ?: boolean ) {
140+ if ( force ) {
141+ this . people = null ;
142+ }
143+ return super . requestStateUpdate ( force ) ;
144+ }
145+
120146 /**
121147 * Invoked on each update to perform rendering tasks. This method must return
122148 * a lit-html TemplateResult. Setting properties inside this method will *not*
@@ -250,34 +276,4 @@ export class MgtPeople extends MgtTemplatedComponent {
250276 }
251277 }
252278 }
253-
254- private async updateUserIds ( newIds : string [ ] ) {
255- if ( this . isLoadingState ) {
256- return ;
257- }
258-
259- const newIdsSet = new Set ( newIds ) ;
260- this . people = this . people ? this . people . filter ( p => newIdsSet . has ( p . id ) ) : [ ] ;
261- const oldIdsSet = new Set ( this . people ? this . people . map ( p => p . id ) : [ ] ) ;
262-
263- const newToLoad = [ ] ;
264-
265- for ( const id of newIds ) {
266- if ( ! oldIdsSet . has ( id ) ) {
267- newToLoad . push ( id ) ;
268- }
269- }
270-
271- if ( newToLoad && newToLoad . length > 0 ) {
272- const provider = Providers . globalProvider ;
273- if ( ! provider || provider . state !== ProviderState . SignedIn ) {
274- return ;
275- }
276-
277- const graph = provider . graph . forComponent ( this ) ;
278-
279- const newPeople = await getUsersForUserIds ( graph , newToLoad ) ;
280- this . people = ( this . people || [ ] ) . concat ( newPeople ) ;
281- }
282- }
283279}
0 commit comments