@@ -38,8 +38,8 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
38
38
allPersons : [ ] ,
39
39
currentPicker : 0 ,
40
40
peoplePartTitle : "" ,
41
- peoplePartTooltip : "" ,
42
- isLoading : false ,
41
+ peoplePartTooltip : "" ,
42
+ isLoading : false ,
43
43
showmessageerror : false
44
44
} ;
45
45
}
@@ -55,15 +55,15 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
55
55
// online mode
56
56
// Load the users
57
57
this . _thisLoadUsers ( ) ;
58
- }
58
+ }
59
59
}
60
60
61
61
/**
62
62
* Generate the user photo link
63
63
*
64
64
* @param value
65
65
*/
66
- private generateUserPhotoLink ( value : string ) : string {
66
+ private generateUserPhotoLink ( value : string ) : string {
67
67
return `https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=${ value } &UA=0&size=HR96x96` ;
68
68
}
69
69
@@ -80,7 +80,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
80
80
text : "Roger Federer" ,
81
81
secondaryText :
"[email protected] " ,
82
82
tertiaryText : "" ,
83
- optionalText :""
83
+ optionalText : ""
84
84
} ) ;
85
85
_fakeUsers . push ( {
86
86
id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c2" ,
@@ -89,7 +89,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
89
89
text : "Rafael Nadal" ,
90
90
secondaryText :
"[email protected] " ,
91
91
tertiaryText : "" ,
92
- optionalText :""
92
+ optionalText : ""
93
93
} ) ;
94
94
_fakeUsers . push ( {
95
95
id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c3" ,
@@ -98,7 +98,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
98
98
text : "Novak Djokovic" ,
99
99
secondaryText :
"[email protected] " ,
100
100
tertiaryText : "" ,
101
- optionalText :""
101
+ optionalText : ""
102
102
} ) ;
103
103
_fakeUsers . push ( {
104
104
id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c4" ,
@@ -107,7 +107,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
107
107
text : "Juan Martin del Potro" ,
108
108
secondaryText :
"[email protected] " ,
109
109
tertiaryText : "" ,
110
- optionalText :""
110
+ optionalText : ""
111
111
} ) ;
112
112
113
113
let personaList : IPersonaProps [ ] = [ ] ;
@@ -131,20 +131,36 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
131
131
* Retrieve the users
132
132
*/
133
133
private async _thisLoadUsers ( ) : Promise < void > {
134
- var stringVal = "" ;
134
+ var stringVal : string = "" ;
135
+
135
136
if ( this . props . groupName ) {
136
137
stringVal = `/_api/web/sitegroups/GetByName('${ this . props . groupName } ')/users` ;
137
138
} else {
138
139
stringVal = "/_api/web/siteusers" ;
139
140
}
140
141
142
+ // filter for principal Type
143
+ var filterVal : string = "" ;
144
+ if ( this . props . principleTypes ) {
145
+ filterVal = `?$filter=${ this . props . principleTypes . map ( principalType => `(PrincipalType eq ${ principalType } )` ) . join ( " or " ) } ` ;
146
+ }
147
+
148
+ // filter for showHiddenInUI
149
+ if ( this . props . showHiddenInUI ) {
150
+ filterVal = filterVal ? `${ filterVal } and (IsHiddenInUI eq ${ this . props . showHiddenInUI } )` : `?$filter=IsHiddenInUI eq ${ this . props . showHiddenInUI } ` ;
151
+ }
152
+
141
153
const webAbsoluteUrl = this . props . webAbsoluteUrl || this . props . context . pageContext . web . absoluteUrl ;
142
154
// Create the rest API
143
- const restApi = `${ webAbsoluteUrl } ${ stringVal } ` ;
155
+ const restApi = `${ webAbsoluteUrl } ${ stringVal } ${ filterVal } ` ;
144
156
145
157
try {
146
158
// Call the API endpoint
147
- const items : IUsers = await this . props . context . spHttpClient . get ( restApi , SPHttpClient . configurations . v1 ) . then ( resp => resp . json ( ) ) ;
159
+ const items : IUsers = await this . props . context . spHttpClient . get ( restApi , SPHttpClient . configurations . v1 , {
160
+ headers : {
161
+ 'Accept' : 'application/json;odata.metadata=none'
162
+ }
163
+ } ) . then ( resp => resp . json ( ) ) ;
148
164
149
165
// Check if items were retrieved
150
166
if ( items && items . value && items . value . length > 0 ) {
@@ -154,7 +170,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
154
170
// Loop over all the retrieved items
155
171
for ( let i = 0 ; i < items . value . length ; i ++ ) {
156
172
const item = items . value [ i ] ;
157
- if ( ! item . IsHiddenInUI || ( this . props . showHiddenInUI && item . IsHiddenInUI ) ) {
173
+ if ( ! item . IsHiddenInUI || ( this . props . showHiddenInUI && item . IsHiddenInUI ) ) {
158
174
// Check if the the type must be returned
159
175
if ( ! this . props . principleTypes || this . props . principleTypes . indexOf ( item . PrincipalType ) !== - 1 ) {
160
176
userValuesArray . push ( {
@@ -171,7 +187,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
171
187
}
172
188
173
189
// Set Default selected persons
174
- let defaultUsers : any = [ ] ;
190
+ let defaultUsers : any = [ ] ;
175
191
let defaultPeopleList : IPersonaProps [ ] = [ ] ;
176
192
if ( this . props . defaultSelectedUsers ) {
177
193
defaultUsers = this . getDefaultUsers ( userValuesArray , this . props . defaultSelectedUsers ) ;
@@ -191,10 +207,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
191
207
192
208
// Update the current state
193
209
this . setState ( {
194
- allPersons : userValuesArray ,
195
- selectedPersons : defaultPeopleList . length != 0 ? defaultPeopleList : [ ] ,
196
- peoplePersonaMenu : personaList ,
197
- mostRecentlyUsedPersons : personaList . slice ( 0 , 5 ) ,
210
+ allPersons : userValuesArray ,
211
+ selectedPersons : defaultPeopleList . length != 0 ? defaultPeopleList : [ ] ,
212
+ peoplePersonaMenu : personaList ,
213
+ mostRecentlyUsedPersons : personaList . slice ( 0 , 5 ) ,
198
214
showmessageerror : this . props . isRequired && this . state . selectedPersons . length === 0
199
215
} ) ;
200
216
}
@@ -269,10 +285,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
269
285
*/
270
286
private _filterPersons ( filterText : string ) : IPersonaProps [ ] {
271
287
return this . state . peoplePersonaMenu . filter ( item =>
272
- this . _doesTextStartWith ( item . text as string , filterText )
273
- || this . _doesTextContains ( item . text as string , filterText )
274
- || this . _doesTextStartWith ( item . secondaryText as string , filterText )
275
- || this . _doesTextContains ( item . secondaryText as string , filterText ) ) ;
288
+ this . _doesTextStartWith ( item . text as string , filterText )
289
+ || this . _doesTextContains ( item . text as string , filterText )
290
+ || this . _doesTextStartWith ( item . secondaryText as string , filterText )
291
+ || this . _doesTextContains ( item . secondaryText as string , filterText ) ) ;
276
292
}
277
293
278
294
@@ -296,12 +312,12 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
296
312
return text && text . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) === 0 ;
297
313
}
298
314
299
- /**
300
- * Checks if text contains
301
- *
302
- * @param text
303
- * @param filterText
304
- */
315
+ /**
316
+ * Checks if text contains
317
+ *
318
+ * @param text
319
+ * @param filterText
320
+ */
305
321
private _doesTextContains ( text : string , filterText : string ) : boolean {
306
322
return text && text . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) > 0 ;
307
323
}
@@ -326,23 +342,23 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
326
342
* @param userValuesArray
327
343
* @param selectedUsers
328
344
*/
329
- private getDefaultUsers ( userValuesArray : any [ ] , selectedUsers : string [ ] ) : any {
345
+ private getDefaultUsers ( userValuesArray : any [ ] , selectedUsers : string [ ] ) : any {
330
346
let defaultuserValuesArray : any [ ] = [ ] ;
331
347
for ( let i = 0 ; i < selectedUsers . length ; i ++ ) {
332
348
const obj = { valToCompare : selectedUsers [ i ] } ;
333
349
const length = defaultuserValuesArray . length ;
334
- defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( userValuesArray . filter ( this . filterUsers , obj ) ) : userValuesArray . filter ( this . filterUsers , obj ) ;
350
+ defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( userValuesArray . filter ( this . filterUsers , obj ) ) : userValuesArray . filter ( this . filterUsers , obj ) ;
335
351
if ( length === defaultuserValuesArray . length ) {
336
352
const defaultUnknownUser = [ {
337
353
id : 1000 + i , //just a random number
338
354
imageUrl : "" ,
339
355
imageInitials : "" ,
340
- text : selectedUsers [ i ] , //Name
356
+ text : selectedUsers [ i ] , //Name
341
357
secondaryText : selectedUsers [ i ] , //Role
342
358
tertiaryText : "" , //status
343
359
optionalText : "" //stgring
344
360
} ] ;
345
- defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( defaultUnknownUser ) : defaultUnknownUser ;
361
+ defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( defaultUnknownUser ) : defaultUnknownUser ;
346
362
}
347
363
}
348
364
return defaultuserValuesArray ;
@@ -374,49 +390,49 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
374
390
< Label > { this . props . titleText || strings . peoplePickerComponentTitleText } </ Label >
375
391
376
392
< NormalPeoplePicker pickerSuggestionsProps = { suggestionProps }
377
- onResolveSuggestions = { this . _onPersonFilterChanged }
378
- onEmptyInputFocus = { this . _returnMostRecentlyUsedPerson }
379
- getTextFromItem = { ( peoplePersonaMenu : IPersonaProps ) => peoplePersonaMenu . text }
380
- className = { `'ms-PeoplePicker' ${ this . props . peoplePickerCntrlclassName ? this . props . peoplePickerCntrlclassName : '' } ` }
381
- key = { 'normal' }
382
- onValidateInput = { this . _validateInputPeople }
383
- removeButtonAriaLabel = { 'Remove' }
384
- inputProps = { {
385
- 'aria-label' : 'People Picker'
386
- } }
387
- selectedItems = { this . state . selectedPersons }
388
- itemLimit = { this . props . personSelectionLimit || 1 }
389
- disabled = { this . props . disabled }
390
- onChange = { this . _onPersonItemsChange } />
393
+ onResolveSuggestions = { this . _onPersonFilterChanged }
394
+ onEmptyInputFocus = { this . _returnMostRecentlyUsedPerson }
395
+ getTextFromItem = { ( peoplePersonaMenu : IPersonaProps ) => peoplePersonaMenu . text }
396
+ className = { `'ms-PeoplePicker' ${ this . props . peoplePickerCntrlclassName ? this . props . peoplePickerCntrlclassName : '' } ` }
397
+ key = { 'normal' }
398
+ onValidateInput = { this . _validateInputPeople }
399
+ removeButtonAriaLabel = { 'Remove' }
400
+ inputProps = { {
401
+ 'aria-label' : 'People Picker'
402
+ } }
403
+ selectedItems = { this . state . selectedPersons }
404
+ itemLimit = { this . props . personSelectionLimit || 1 }
405
+ disabled = { this . props . disabled }
406
+ onChange = { this . _onPersonItemsChange } />
391
407
</ div >
392
408
) ;
393
409
394
410
return (
395
411
< div >
396
- {
397
- this . props . showtooltip ? (
398
- < TooltipHost content = { this . props . tooltipMessage || strings . peoplePickerComponentTooltipMessage }
399
- id = 'pntp'
400
- calloutProps = { { gapSpace : 0 } }
401
- directionalHint = { this . props . tooltipDirectional || DirectionalHint . leftTopEdge } >
402
- { peoplepicker }
403
- </ TooltipHost >
404
- ) : (
405
- < div >
406
- { peoplepicker }
407
- </ div >
408
- )
409
- }
412
+ {
413
+ this . props . showtooltip ? (
414
+ < TooltipHost content = { this . props . tooltipMessage || strings . peoplePickerComponentTooltipMessage }
415
+ id = 'pntp'
416
+ calloutProps = { { gapSpace : 0 } }
417
+ directionalHint = { this . props . tooltipDirectional || DirectionalHint . leftTopEdge } >
418
+ { peoplepicker }
419
+ </ TooltipHost >
420
+ ) : (
421
+ < div >
422
+ { peoplepicker }
423
+ </ div >
424
+ )
425
+ }
410
426
411
- {
412
- ( this . props . isRequired && this . state . showmessageerror ) && (
413
- < MessageBar messageBarType = { MessageBarType . error }
414
- isMultiline = { false }
415
- className = { `${ this . props . errorMessageclassName ? this . props . errorMessageclassName : '' } ` } >
416
- { this . props . errorMessage ? this . props . errorMessage : strings . peoplePickerComponentErrorMessage }
417
- </ MessageBar >
418
- )
419
- }
427
+ {
428
+ ( this . props . isRequired && this . state . showmessageerror ) && (
429
+ < MessageBar messageBarType = { MessageBarType . error }
430
+ isMultiline = { false }
431
+ className = { `${ this . props . errorMessageclassName ? this . props . errorMessageclassName : '' } ` } >
432
+ { this . props . errorMessage ? this . props . errorMessage : strings . peoplePickerComponentErrorMessage }
433
+ </ MessageBar >
434
+ )
435
+ }
420
436
</ div >
421
437
) ;
422
438
}
0 commit comments