Skip to content

Commit 3e13492

Browse files
committed
Merge branch 'tsekityam-patch-2' into dev
2 parents 36b2f12 + 1c6f051 commit 3e13492

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/controls/peoplepicker/PeoplePickerComponent.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
4646
* componentWillMount lifecycle hook
4747
*/
4848
public componentWillMount(): void {
49-
this.getInitialPersons();
49+
this.getInitialPersons(this.props);
5050
}
5151

5252

@@ -56,20 +56,21 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
5656
public componentWillUpdate(nextProps: IPeoplePickerProps, nextState: IPeoplePickerState): void {
5757
if (!isEqual(this.props.defaultSelectedUsers, nextProps.defaultSelectedUsers) ||
5858
this.props.groupName !== nextProps.groupName ||
59-
this.props.webAbsoluteUrl !== nextProps.webAbsoluteUrl) {
60-
this.getInitialPersons();
59+
this.props.webAbsoluteUrl !== nextProps.webAbsoluteUrl ||
60+
this.peopleSearchService.getSumOfPrincipalTypes(this.props.principalTypes) !== this.peopleSearchService.getSumOfPrincipalTypes(nextProps.principalTypes)) {
61+
this.getInitialPersons(nextProps);
6162
}
6263
}
6364

6465

6566
/**
6667
* Get initial persons
6768
*/
68-
private async getInitialPersons() {
69-
const { groupName } = this.props;
69+
private async getInitialPersons(props: IPeoplePickerProps) {
70+
const { groupName, webAbsoluteUrl, defaultSelectedUsers, ensureUser, principalTypes } = props;
7071
// Check if a group property was provided, and get the group ID
7172
if (groupName) {
72-
this.groupId = await this.peopleSearchService.getGroupId(this.props.groupName, this.props.webAbsoluteUrl);
73+
this.groupId = await this.peopleSearchService.getGroupId(groupName, webAbsoluteUrl);
7374
if (!this.groupId) {
7475
this.setState({
7576
errorMessage: "Group could not be found."
@@ -81,10 +82,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
8182
}
8283

8384
// Check for default user values
84-
if (this.props.defaultSelectedUsers && this.props.defaultSelectedUsers.length) {
85+
if (defaultSelectedUsers) {
8586
let selectedPersons: IPersonaProps[] = [];
86-
for (const userValue of this.props.defaultSelectedUsers) {
87-
const userResult = await this.peopleSearchService.searchPersonByEmailOrLogin(userValue, this.props.principalTypes, this.props.webAbsoluteUrl, this.groupId, this.props.ensureUser);
87+
for (const userValue of props.defaultSelectedUsers) {
88+
const userResult = await this.peopleSearchService.searchPersonByEmailOrLogin(userValue, principalTypes, webAbsoluteUrl, this.groupId, ensureUser);
8889
if (userResult) {
8990
selectedPersons.push(userResult);
9091
}

src/services/PeopleSearchService.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ export default class SPPeopleSearchService {
3232
return `https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=${value}&UA=0&size=HR96x96`;
3333
}
3434

35+
/**
36+
* Generate sum of principal types
37+
*
38+
* PrincipalType controls the type of entities that are returned in the results.
39+
* Choices are All - 15, Distribution List - 2 , Security Groups - 4, SharePoint Groups - 8, User - 1.
40+
* These values can be combined (example: 13 is security + SP groups + users)
41+
*
42+
* @param principalTypes
43+
*/
44+
public getSumOfPrincipalTypes(principalTypes: PrincipalType[]) {
45+
return !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1;
46+
}
47+
3548
/**
3649
* Retrieve the specified group
3750
*
@@ -161,10 +174,7 @@ export default class SPPeopleSearchService {
161174
AllUrlZones: false,
162175
MaximumEntitySuggestions: maximumSuggestions,
163176
PrincipalSource: 15,
164-
// PrincipalType controls the type of entities that are returned in the results.
165-
// Choices are All - 15, Distribution List - 2 , Security Groups - 4, SharePoint Groups - 8, User - 1.
166-
// These values can be combined (example: 13 is security + SP groups + users)
167-
PrincipalType: !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1,
177+
PrincipalType: this.getSumOfPrincipalTypes(principalTypes),
168178
QueryString: query
169179
}
170180
};

0 commit comments

Comments
 (0)