@@ -44,8 +44,8 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
44
44
allPersons : [ ] ,
45
45
currentPicker : 0 ,
46
46
peoplePartTitle : "" ,
47
- peoplePartTooltip : "" ,
48
- isLoading : false ,
47
+ peoplePartTooltip : "" ,
48
+ isLoading : false ,
49
49
showmessageerror : false
50
50
} ;
51
51
}
@@ -61,15 +61,15 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
61
61
// online mode
62
62
// Load the users
63
63
this . _thisLoadUsers ( ) ;
64
- }
64
+ }
65
65
}
66
66
67
67
/**
68
68
* Generate the user photo link
69
69
*
70
70
* @param value
71
71
*/
72
- private generateUserPhotoLink ( value : string ) : string {
72
+ private generateUserPhotoLink ( value : string ) : string {
73
73
return `https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=${ value } &UA=0&size=HR96x96` ;
74
74
}
75
75
@@ -86,7 +86,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
86
86
text : "Roger Federer" ,
87
87
secondaryText :
"[email protected] " ,
88
88
tertiaryText : "" ,
89
- optionalText :""
89
+ optionalText : ""
90
90
} ) ;
91
91
_fakeUsers . push ( {
92
92
id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c2" ,
@@ -95,7 +95,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
95
95
text : "Rafael Nadal" ,
96
96
secondaryText :
"[email protected] " ,
97
97
tertiaryText : "" ,
98
- optionalText :""
98
+ optionalText : ""
99
99
} ) ;
100
100
_fakeUsers . push ( {
101
101
id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c3" ,
@@ -104,7 +104,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
104
104
text : "Novak Djokovic" ,
105
105
secondaryText :
"[email protected] " ,
106
106
tertiaryText : "" ,
107
- optionalText :""
107
+ optionalText : ""
108
108
} ) ;
109
109
_fakeUsers . push ( {
110
110
id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c4" ,
@@ -113,7 +113,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
113
113
text : "Juan Martin del Potro" ,
114
114
secondaryText :
"[email protected] " ,
115
115
tertiaryText : "" ,
116
- optionalText :""
116
+ optionalText : ""
117
117
} ) ;
118
118
119
119
let personaList : IPersonaProps [ ] = [ ] ;
@@ -137,20 +137,40 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
137
137
* Retrieve the users
138
138
*/
139
139
private async _thisLoadUsers ( ) : Promise < void > {
140
- var stringVal = "" ;
140
+ var stringVal : string = "" ;
141
+
142
+ let filtered : boolean = false ;
143
+
141
144
if ( this . props . groupName ) {
142
145
stringVal = `/_api/web/sitegroups/GetByName('${ this . props . groupName } ')/users` ;
143
146
} else {
144
147
stringVal = "/_api/web/siteusers" ;
145
148
}
146
149
150
+ // filter for principal Type
151
+ var filterVal : string = "" ;
152
+ if ( this . props . principleTypes ) {
153
+ filterVal = `${ "?$filter=" } ${ this . props . principleTypes . map ( principalType => `(PrincipalType eq ${ principalType } )` ) . join ( " or " ) } ` ;
154
+ filtered = true ;
155
+ }
156
+
157
+ // filter for showHiddenInUI
158
+ if ( this . props . showHiddenInUI ) {
159
+ filterVal = filtered ? `${ filterVal } and (IsHiddenInUI eq ${ this . props . showHiddenInUI } )` : `?$filter=IsHiddenInUI eq ${ this . props . showHiddenInUI } ` ;
160
+ filtered = true ;
161
+ }
162
+
147
163
const webAbsoluteUrl = this . props . webAbsoluteUrl || this . props . context . pageContext . web . absoluteUrl ;
148
164
// Create the rest API
149
- const restApi = `${ webAbsoluteUrl } ${ stringVal } ` ;
165
+ const restApi = filtered ? ` ${ webAbsoluteUrl } ${ stringVal } ${ filterVal } ` : `${ webAbsoluteUrl } ${ stringVal } ` ;
150
166
151
167
try {
152
168
// Call the API endpoint
153
- const items : IUsers = await this . props . context . spHttpClient . get ( restApi , SPHttpClient . configurations . v1 ) . then ( resp => resp . json ( ) ) ;
169
+ const items : IUsers = await this . props . context . spHttpClient . get ( restApi , SPHttpClient . configurations . v1 , {
170
+ headers : {
171
+ 'Accept' : 'application/json;odata.metadata=none'
172
+ }
173
+ } ) . then ( resp => resp . json ( ) ) ;
154
174
155
175
// Check if items were retrieved
156
176
if ( items && items . value && items . value . length > 0 ) {
@@ -160,7 +180,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
160
180
// Loop over all the retrieved items
161
181
for ( let i = 0 ; i < items . value . length ; i ++ ) {
162
182
const item = items . value [ i ] ;
163
- if ( ! item . IsHiddenInUI || ( this . props . showHiddenInUI && item . IsHiddenInUI ) ) {
183
+ if ( ! item . IsHiddenInUI || ( this . props . showHiddenInUI && item . IsHiddenInUI ) ) {
164
184
// Check if the the type must be returned
165
185
if ( ! this . props . principleTypes || this . props . principleTypes . indexOf ( item . PrincipalType ) !== - 1 ) {
166
186
userValuesArray . push ( {
@@ -177,7 +197,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
177
197
}
178
198
179
199
// Set Default selected persons
180
- let defaultUsers : any = [ ] ;
200
+ let defaultUsers : any = [ ] ;
181
201
let defaultPeopleList : IPersonaProps [ ] = [ ] ;
182
202
if ( this . props . defaultSelectedUsers ) {
183
203
defaultUsers = this . getDefaultUsers ( userValuesArray , this . props . defaultSelectedUsers ) ;
@@ -197,10 +217,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
197
217
198
218
// Update the current state
199
219
this . setState ( {
200
- allPersons : userValuesArray ,
201
- selectedPersons : defaultPeopleList . length != 0 ? defaultPeopleList : [ ] ,
202
- peoplePersonaMenu : personaList ,
203
- mostRecentlyUsedPersons : personaList . slice ( 0 , 5 ) ,
220
+ allPersons : userValuesArray ,
221
+ selectedPersons : defaultPeopleList . length != 0 ? defaultPeopleList : [ ] ,
222
+ peoplePersonaMenu : personaList ,
223
+ mostRecentlyUsedPersons : personaList . slice ( 0 , 5 ) ,
204
224
showmessageerror : this . props . isRequired && this . state . selectedPersons . length === 0
205
225
} ) ;
206
226
}
@@ -275,10 +295,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
275
295
*/
276
296
private _filterPersons ( filterText : string ) : IPersonaProps [ ] {
277
297
return this . state . peoplePersonaMenu . filter ( item =>
278
- this . _doesTextStartWith ( item . text as string , filterText )
279
- || this . _doesTextContains ( item . text as string , filterText )
280
- || this . _doesTextStartWith ( item . secondaryText as string , filterText )
281
- || this . _doesTextContains ( item . secondaryText as string , filterText ) ) ;
298
+ this . _doesTextStartWith ( item . text as string , filterText )
299
+ || this . _doesTextContains ( item . text as string , filterText )
300
+ || this . _doesTextStartWith ( item . secondaryText as string , filterText )
301
+ || this . _doesTextContains ( item . secondaryText as string , filterText ) ) ;
282
302
}
283
303
284
304
@@ -302,12 +322,12 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
302
322
return text && text . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) === 0 ;
303
323
}
304
324
305
- /**
306
- * Checks if text contains
307
- *
308
- * @param text
309
- * @param filterText
310
- */
325
+ /**
326
+ * Checks if text contains
327
+ *
328
+ * @param text
329
+ * @param filterText
330
+ */
311
331
private _doesTextContains ( text : string , filterText : string ) : boolean {
312
332
return text && text . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) > 0 ;
313
333
}
@@ -332,23 +352,23 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
332
352
* @param userValuesArray
333
353
* @param selectedUsers
334
354
*/
335
- private getDefaultUsers ( userValuesArray : any [ ] , selectedUsers : string [ ] ) : any {
355
+ private getDefaultUsers ( userValuesArray : any [ ] , selectedUsers : string [ ] ) : any {
336
356
let defaultuserValuesArray : any [ ] = [ ] ;
337
357
for ( let i = 0 ; i < selectedUsers . length ; i ++ ) {
338
358
const obj = { valToCompare : selectedUsers [ i ] } ;
339
359
const length = defaultuserValuesArray . length ;
340
- defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( userValuesArray . filter ( this . filterUsers , obj ) ) : userValuesArray . filter ( this . filterUsers , obj ) ;
360
+ defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( userValuesArray . filter ( this . filterUsers , obj ) ) : userValuesArray . filter ( this . filterUsers , obj ) ;
341
361
if ( length === defaultuserValuesArray . length ) {
342
362
const defaultUnknownUser = [ {
343
363
id : 1000 + i , //just a random number
344
364
imageUrl : "" ,
345
365
imageInitials : "" ,
346
- text : selectedUsers [ i ] , //Name
366
+ text : selectedUsers [ i ] , //Name
347
367
secondaryText : selectedUsers [ i ] , //Role
348
368
tertiaryText : "" , //status
349
369
optionalText : "" //stgring
350
370
} ] ;
351
- defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( defaultUnknownUser ) : defaultUnknownUser ;
371
+ defaultuserValuesArray = defaultuserValuesArray . length !== 0 ? defaultuserValuesArray . concat ( defaultUnknownUser ) : defaultUnknownUser ;
352
372
}
353
373
}
354
374
return defaultuserValuesArray ;
@@ -372,49 +392,49 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
372
392
< Label > { this . props . titleText || strings . peoplePickerComponentTitleText } </ Label >
373
393
374
394
< NormalPeoplePicker pickerSuggestionsProps = { suggestionProps }
375
- onResolveSuggestions = { this . _onPersonFilterChanged }
376
- onEmptyInputFocus = { this . _returnMostRecentlyUsedPerson }
377
- getTextFromItem = { ( peoplePersonaMenu : IPersonaProps ) => peoplePersonaMenu . text }
378
- className = { `'ms-PeoplePicker' ${ this . props . peoplePickerCntrlclassName ? this . props . peoplePickerCntrlclassName : '' } ` }
379
- key = { 'normal' }
380
- onValidateInput = { this . _validateInputPeople }
381
- removeButtonAriaLabel = { 'Remove' }
382
- inputProps = { {
383
- 'aria-label' : 'People Picker'
384
- } }
385
- selectedItems = { this . state . selectedPersons }
386
- itemLimit = { this . props . personSelectionLimit || 1 }
387
- disabled = { this . props . disabled }
388
- onChange = { this . _onPersonItemsChange } />
395
+ onResolveSuggestions = { this . _onPersonFilterChanged }
396
+ onEmptyInputFocus = { this . _returnMostRecentlyUsedPerson }
397
+ getTextFromItem = { ( peoplePersonaMenu : IPersonaProps ) => peoplePersonaMenu . text }
398
+ className = { `'ms-PeoplePicker' ${ this . props . peoplePickerCntrlclassName ? this . props . peoplePickerCntrlclassName : '' } ` }
399
+ key = { 'normal' }
400
+ onValidateInput = { this . _validateInputPeople }
401
+ removeButtonAriaLabel = { 'Remove' }
402
+ inputProps = { {
403
+ 'aria-label' : 'People Picker'
404
+ } }
405
+ selectedItems = { this . state . selectedPersons }
406
+ itemLimit = { this . props . personSelectionLimit || 1 }
407
+ disabled = { this . props . disabled }
408
+ onChange = { this . _onPersonItemsChange } />
389
409
</ div >
390
410
) ;
391
411
392
412
return (
393
413
< div >
394
- {
395
- this . props . showtooltip ? (
396
- < TooltipHost content = { this . props . tooltipMessage || strings . peoplePickerComponentTooltipMessage }
397
- id = 'pntp'
398
- calloutProps = { { gapSpace : 0 } }
399
- directionalHint = { this . props . tooltipDirectional || DirectionalHint . leftTopEdge } >
400
- { peoplepicker }
401
- </ TooltipHost >
402
- ) : (
403
- < div >
404
- { peoplepicker }
405
- </ div >
406
- )
407
- }
414
+ {
415
+ this . props . showtooltip ? (
416
+ < TooltipHost content = { this . props . tooltipMessage || strings . peoplePickerComponentTooltipMessage }
417
+ id = 'pntp'
418
+ calloutProps = { { gapSpace : 0 } }
419
+ directionalHint = { this . props . tooltipDirectional || DirectionalHint . leftTopEdge } >
420
+ { peoplepicker }
421
+ </ TooltipHost >
422
+ ) : (
423
+ < div >
424
+ { peoplepicker }
425
+ </ div >
426
+ )
427
+ }
408
428
409
- {
410
- ( this . props . isRequired && this . state . showmessageerror ) && (
411
- < MessageBar messageBarType = { MessageBarType . error }
412
- isMultiline = { false }
413
- className = { `${ this . props . errorMessageclassName ? this . props . errorMessageclassName : '' } ` } >
414
- { this . props . errorMessage ? this . props . errorMessage : strings . peoplePickerComponentErrorMessage }
415
- </ MessageBar >
416
- )
417
- }
429
+ {
430
+ ( this . props . isRequired && this . state . showmessageerror ) && (
431
+ < MessageBar messageBarType = { MessageBarType . error }
432
+ isMultiline = { false }
433
+ className = { `${ this . props . errorMessageclassName ? this . props . errorMessageclassName : '' } ` } >
434
+ { this . props . errorMessage ? this . props . errorMessage : strings . peoplePickerComponentErrorMessage }
435
+ </ MessageBar >
436
+ )
437
+ }
418
438
</ div >
419
439
) ;
420
440
}
0 commit comments