1
1
import * as strings from 'ControlStrings' ;
2
2
import * as React from 'react' ;
3
- import { IPeoplePickerProps , IPeoplePickerState } from './IPeoplePicker' ;
3
+ import { IPeoplePickerProps , IPeoplePickerState , IPeoplePickerUserItem } from './IPeoplePicker' ;
4
4
import { IPersonaProps } from 'office-ui-fabric-react/lib/Persona' ;
5
5
import { TooltipHost , DirectionalHint } from 'office-ui-fabric-react/lib/Tooltip' ;
6
6
import { IBasePickerSuggestionsProps } from 'office-ui-fabric-react/lib/Pickers' ;
@@ -16,6 +16,7 @@ import {
16
16
} from 'office-ui-fabric-react/lib/Utilities' ;
17
17
import { IUsers } from './IUsers' ;
18
18
import { Label } from 'office-ui-fabric-react/lib/Label' ;
19
+ import { Environment , EnvironmentType } from "@microsoft/sp-core-library" ;
19
20
20
21
const suggestionProps : IBasePickerSuggestionsProps = {
21
22
suggestionsHeaderText : 'Suggested People' ,
@@ -41,15 +42,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
41
42
selectedPersons : [ ] ,
42
43
mostRecentlyUsedPersons : [ ] ,
43
44
currentSelectedPersons : [ ] ,
44
- allPersons : [ {
45
- id : "" ,
46
- imageUrl : "" ,
47
- imageInitials : "" ,
48
- primaryText : "" , //Name
49
- secondaryText : "" , //Role
50
- tertiaryText : "" , //status
51
- optionalText : "" //anything
52
- } ] ,
45
+ allPersons : [ ] ,
53
46
currentPicker : 0 ,
54
47
peoplePartTitle : "" ,
55
48
peoplePartTooltip : "" ,
@@ -62,8 +55,14 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
62
55
* componentWillMount lifecycle hook
63
56
*/
64
57
public componentWillMount ( ) : void {
65
- // Load the users
66
- this . _thisLoadUsers ( ) ;
58
+ if ( Environment . type === EnvironmentType . Local ) {
59
+ // local mode
60
+ this . _loadLocalWorkbenchUsers ( ) ;
61
+ } else {
62
+ // online mode
63
+ // Load the users
64
+ this . _thisLoadUsers ( ) ;
65
+ }
67
66
}
68
67
69
68
/**
@@ -75,6 +74,66 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
75
74
return `https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=${ value } &UA=0&size=HR96x96` ;
76
75
}
77
76
77
+ /**
78
+ * Retrieve the users for local demo and testing purposes
79
+ */
80
+ private async _loadLocalWorkbenchUsers ( ) : Promise < void > {
81
+ let _fakeUsers : Array < IPeoplePickerUserItem > = new Array < IPeoplePickerUserItem > ( ) ;
82
+
83
+ _fakeUsers . push ( {
84
+ id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c1" ,
85
+ imageUrl : "" ,
86
+ imageInitials : "RF" ,
87
+ primaryText : "Roger Federer" ,
88
+ secondaryText :
"[email protected] " ,
89
+ tertiaryText : "" ,
90
+ optionalText :""
91
+ } ) ;
92
+ _fakeUsers . push ( {
93
+ id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c2" ,
94
+ imageUrl : "" ,
95
+ imageInitials : "RN" ,
96
+ primaryText : "Rafael Nadal" ,
97
+ secondaryText :
"[email protected] " ,
98
+ tertiaryText : "" ,
99
+ optionalText :""
100
+ } ) ;
101
+ _fakeUsers . push ( {
102
+ id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c3" ,
103
+ imageUrl : "" ,
104
+ imageInitials : "ND" ,
105
+ primaryText : "Novak Djokovic" ,
106
+ secondaryText :
"[email protected] " ,
107
+ tertiaryText : "" ,
108
+ optionalText :""
109
+ } ) ;
110
+ _fakeUsers . push ( {
111
+ id : "10dfa208-d7d4-4aef-a7ea-f9e4bb1b85c4" ,
112
+ imageUrl : "" ,
113
+ imageInitials : "JP" ,
114
+ primaryText : "Juan Martin del Potro" ,
115
+ secondaryText :
"[email protected] " ,
116
+ tertiaryText : "" ,
117
+ optionalText :""
118
+ } ) ;
119
+
120
+ let personaList : IPersonaWithMenu [ ] = [ ] ;
121
+ for ( const persona of _fakeUsers ) {
122
+ let personaWithMenu : IPersonaWithMenu = { } ;
123
+ assign ( personaWithMenu , persona ) ;
124
+ personaList . push ( personaWithMenu ) ;
125
+ }
126
+
127
+ // update the current state
128
+ this . setState ( {
129
+ allPersons : _fakeUsers ,
130
+ peoplePersonaMenu : personaList ,
131
+ mostRecentlyUsedPersons : personaList . slice ( 0 , 5 ) ,
132
+ showmessageerror : this . props . isRequired && this . state . selectedPersons . length === 0
133
+ } ) ;
134
+
135
+ }
136
+
78
137
/**
79
138
* Retrieve the users
80
139
*/
@@ -95,39 +154,20 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
95
154
96
155
// Check if items were retrieved
97
156
if ( items && items . value && items . value . length > 0 ) {
98
- let userValuesArray : any = [ {
99
- id : 0 ,
100
- imageUrl : "" ,
101
- imageInitials : "" ,
102
- primaryText : "" , //Name
103
- secondaryText : "" , //Email
104
- tertiaryText : "" , //status
105
- optionalText : "" //anything
106
- } ] ;
157
+
158
+ let userValuesArray : Array < IPeoplePickerUserItem > = new Array < IPeoplePickerUserItem > ( ) ;
107
159
108
160
// Loop over all the retrieved items
109
161
for ( let i = 0 ; i < items . value . length ; i ++ ) {
110
- if ( i === 0 ) {
111
- userValuesArray = [ {
112
- id : items . value [ i ] . Id ,
113
- imageUrl : this . generateUserPhotoLink ( items . value [ i ] . Email ) ,
114
- imageInitials : "" ,
115
- primaryText : items . value [ i ] . Title , //Name
116
- secondaryText : items . value [ i ] . Email , //Email
117
- tertiaryText : "" , //status
118
- optionalText : "" //anything
119
- } ] ;
120
- } else {
121
- userValuesArray . push ( {
122
- id : items . value [ i ] . Id ,
123
- imageUrl : this . generateUserPhotoLink ( items . value [ i ] . Email ) ,
124
- imageInitials : "" ,
125
- primaryText : items . value [ i ] . Title , //Name
126
- secondaryText : items . value [ i ] . Email , //Email
127
- tertiaryText : "" , //status
128
- optionalText : "" //anything
129
- } ) ;
130
- }
162
+ userValuesArray . push ( {
163
+ id : items . value [ i ] . Id . toString ( ) ,
164
+ imageUrl : this . generateUserPhotoLink ( items . value [ i ] . Email ) ,
165
+ imageInitials : "" ,
166
+ primaryText : items . value [ i ] . Title , // name
167
+ secondaryText : items . value [ i ] . Email , // email
168
+ tertiaryText : "" , // status
169
+ optionalText : "" // anything
170
+ } ) ;
131
171
}
132
172
133
173
let personaList : IPersonaWithMenu [ ] = [ ] ;
0 commit comments