@@ -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,40 @@ 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
+
136
+ let filtered : boolean = false ;
137
+
135
138
if ( this . props . groupName ) {
136
139
stringVal = `/_api/web/sitegroups/GetByName('${ this . props . groupName } ')/users` ;
137
140
} else {
138
141
stringVal = "/_api/web/siteusers" ;
139
142
}
140
143
144
+ // filter for principal Type
145
+ var filterVal : string = "" ;
146
+ if ( this . props . principleTypes ) {
147
+ filterVal = `${ "?$filter=" } ${ this . props . principleTypes . map ( principalType => `(PrincipalType eq ${ principalType } )` ) . join ( " or " ) } ` ;
148
+ filtered = true ;
149
+ }
150
+
151
+ // filter for showHiddenInUI
152
+ if ( this . props . showHiddenInUI ) {
153
+ filterVal = filtered ? `${ filterVal } and (IsHiddenInUI eq ${ this . props . showHiddenInUI } )` : `?$filter=IsHiddenInUI eq ${ this . props . showHiddenInUI } ` ;
154
+ filtered = true ;
155
+ }
156
+
141
157
const webAbsoluteUrl = this . props . webAbsoluteUrl || this . props . context . pageContext . web . absoluteUrl ;
142
158
// Create the rest API
143
- const restApi = `${ webAbsoluteUrl } ${ stringVal } ` ;
159
+ const restApi = filtered ? ` ${ webAbsoluteUrl } ${ stringVal } ${ filterVal } ` : `${ webAbsoluteUrl } ${ stringVal } ` ;
144
160
145
161
try {
146
162
// Call the API endpoint
147
- const items : IUsers = await this . props . context . spHttpClient . get ( restApi , SPHttpClient . configurations . v1 ) . then ( resp => resp . json ( ) ) ;
163
+ const items : IUsers = await this . props . context . spHttpClient . get ( restApi , SPHttpClient . configurations . v1 , {
164
+ headers : {
165
+ 'Accept' : 'application/json;odata.metadata=none'
166
+ }
167
+ } ) . then ( resp => resp . json ( ) ) ;
148
168
149
169
// Check if items were retrieved
150
170
if ( items && items . value && items . value . length > 0 ) {
@@ -154,7 +174,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
154
174
// Loop over all the retrieved items
155
175
for ( let i = 0 ; i < items . value . length ; i ++ ) {
156
176
const item = items . value [ i ] ;
157
- if ( ! item . IsHiddenInUI || ( this . props . showHiddenInUI && item . IsHiddenInUI ) ) {
177
+ if ( ! item . IsHiddenInUI || ( this . props . showHiddenInUI && item . IsHiddenInUI ) ) {
158
178
// Check if the the type must be returned
159
179
if ( ! this . props . principleTypes || this . props . principleTypes . indexOf ( item . PrincipalType ) !== - 1 ) {
160
180
userValuesArray . push ( {
@@ -171,7 +191,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
171
191
}
172
192
173
193
// Set Default selected persons
174
- let defaultUsers : any = [ ] ;
194
+ let defaultUsers : any = [ ] ;
175
195
let defaultPeopleList : IPersonaProps [ ] = [ ] ;
176
196
if ( this . props . defaultSelectedUsers ) {
177
197
defaultUsers = this . getDefaultUsers ( userValuesArray , this . props . defaultSelectedUsers ) ;
@@ -191,10 +211,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
191
211
192
212
// Update the current state
193
213
this . setState ( {
194
- allPersons : userValuesArray ,
195
- selectedPersons : defaultPeopleList . length != 0 ? defaultPeopleList : [ ] ,
196
- peoplePersonaMenu : personaList ,
197
- mostRecentlyUsedPersons : personaList . slice ( 0 , 5 ) ,
214
+ allPersons : userValuesArray ,
215
+ selectedPersons : defaultPeopleList . length != 0 ? defaultPeopleList : [ ] ,
216
+ peoplePersonaMenu : personaList ,
217
+ mostRecentlyUsedPersons : personaList . slice ( 0 , 5 ) ,
198
218
showmessageerror : this . props . isRequired && this . state . selectedPersons . length === 0
199
219
} ) ;
200
220
}
@@ -269,10 +289,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
269
289
*/
270
290
private _filterPersons ( filterText : string ) : IPersonaProps [ ] {
271
291
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 ) ) ;
292
+ this . _doesTextStartWith ( item . text as string , filterText )
293
+ || this . _doesTextContains ( item . text as string , filterText )
294
+ || this . _doesTextStartWith ( item . secondaryText as string , filterText )
295
+ || this . _doesTextContains ( item . secondaryText as string , filterText ) ) ;
276
296
}
277
297
278
298
@@ -296,12 +316,12 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
296
316
return text && text . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) === 0 ;
297
317
}
298
318
299
- /**
300
- * Checks if text contains
301
- *
302
- * @param text
303
- * @param filterText
304
- */
319
+ /**
320
+ * Checks if text contains
321
+ *
322
+ * @param text
323
+ * @param filterText
324
+ */
305
325
private _doesTextContains ( text : string , filterText : string ) : boolean {
306
326
return text && text . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) > 0 ;
307
327
}
@@ -326,23 +346,23 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
326
346
* @param userValuesArray
327
347
* @param selectedUsers
328
348
*/
329
- private getDefaultUsers ( userValuesArray : any [ ] , selectedUsers : string [ ] ) : any {
349
+ private getDefaultUsers ( userValuesArray : any [ ] , selectedUsers : string [ ] ) : any {
330
350
let defaultuserValuesArray : any [ ] = [ ] ;
331
351
for ( let i = 0 ; i < selectedUsers . length ; i ++ ) {
332
352
const obj = { valToCompare : selectedUsers [ i ] } ;
333
353
const length = defaultuserValuesArray . length ;
334
- defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( userValuesArray . filter ( this . filterUsers , obj ) ) : userValuesArray . filter ( this . filterUsers , obj ) ;
354
+ defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( userValuesArray . filter ( this . filterUsers , obj ) ) : userValuesArray . filter ( this . filterUsers , obj ) ;
335
355
if ( length === defaultuserValuesArray . length ) {
336
356
const defaultUnknownUser = [ {
337
357
id : 1000 + i , //just a random number
338
358
imageUrl : "" ,
339
359
imageInitials : "" ,
340
- text : selectedUsers [ i ] , //Name
360
+ text : selectedUsers [ i ] , //Name
341
361
secondaryText : selectedUsers [ i ] , //Role
342
362
tertiaryText : "" , //status
343
363
optionalText : "" //stgring
344
364
} ] ;
345
- defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( defaultUnknownUser ) : defaultUnknownUser ;
365
+ defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( defaultUnknownUser ) : defaultUnknownUser ;
346
366
}
347
367
}
348
368
return defaultuserValuesArray ;
@@ -374,49 +394,49 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
374
394
< Label > { this . props . titleText || strings . peoplePickerComponentTitleText } </ Label >
375
395
376
396
< 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 } />
397
+ onResolveSuggestions = { this . _onPersonFilterChanged }
398
+ onEmptyInputFocus = { this . _returnMostRecentlyUsedPerson }
399
+ getTextFromItem = { ( peoplePersonaMenu : IPersonaProps ) => peoplePersonaMenu . text }
400
+ className = { `'ms-PeoplePicker' ${ this . props . peoplePickerCntrlclassName ? this . props . peoplePickerCntrlclassName : '' } ` }
401
+ key = { 'normal' }
402
+ onValidateInput = { this . _validateInputPeople }
403
+ removeButtonAriaLabel = { 'Remove' }
404
+ inputProps = { {
405
+ 'aria-label' : 'People Picker'
406
+ } }
407
+ selectedItems = { this . state . selectedPersons }
408
+ itemLimit = { this . props . personSelectionLimit || 1 }
409
+ disabled = { this . props . disabled }
410
+ onChange = { this . _onPersonItemsChange } />
391
411
</ div >
392
412
) ;
393
413
394
414
return (
395
415
< 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
- }
416
+ {
417
+ this . props . showtooltip ? (
418
+ < TooltipHost content = { this . props . tooltipMessage || strings . peoplePickerComponentTooltipMessage }
419
+ id = 'pntp'
420
+ calloutProps = { { gapSpace : 0 } }
421
+ directionalHint = { this . props . tooltipDirectional || DirectionalHint . leftTopEdge } >
422
+ { peoplepicker }
423
+ </ TooltipHost >
424
+ ) : (
425
+ < div >
426
+ { peoplepicker }
427
+ </ div >
428
+ )
429
+ }
410
430
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
- }
431
+ {
432
+ ( this . props . isRequired && this . state . showmessageerror ) && (
433
+ < MessageBar messageBarType = { MessageBarType . error }
434
+ isMultiline = { false }
435
+ className = { `${ this . props . errorMessageclassName ? this . props . errorMessageclassName : '' } ` } >
436
+ { this . props . errorMessage ? this . props . errorMessage : strings . peoplePickerComponentErrorMessage }
437
+ </ MessageBar >
438
+ )
439
+ }
420
440
</ div >
421
441
) ;
422
442
}
0 commit comments