Skip to content

Commit

Permalink
feat/pnp#958 Add selected items for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Morozov committed Jul 19, 2021
1 parent 2fc3d2e commit b11c175
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/controls/peoplepicker/IPeoplePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ export interface IPeoplePickerProps {
*/
errorMessageClassName?: string;
/**
* Default Selected User Emails
* Default Selected Items
* User -> Email
* Sharepoint Group -> Title
* Security Group -> Email
*/
defaultSelectedUsers?: string[];
defaultSelectedItems?: string[];
/**
* @deprecated
* Show users which are hidden from the UI
Expand Down
8 changes: 4 additions & 4 deletions src/controls/peoplepicker/PeoplePickerComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
* componentWillUpdate lifecycle hook
*/
public componentWillUpdate(nextProps: IPeoplePickerProps, nextState: IPeoplePickerState): void {
if (!isEqual(this.props.defaultSelectedUsers, nextProps.defaultSelectedUsers) ||
if (!isEqual(this.props.defaultSelectedItems, nextProps.defaultSelectedItems) ||
this.props.groupName !== nextProps.groupName ||
this.props.webAbsoluteUrl !== nextProps.webAbsoluteUrl ||
this.peopleSearchService.getSumOfPrincipalTypes(this.props.principalTypes) !== this.peopleSearchService.getSumOfPrincipalTypes(nextProps.principalTypes)) {
Expand All @@ -75,7 +75,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
* Get initial persons
*/
private async getInitialPersons(props: IPeoplePickerProps) {
const { groupName, groupId, webAbsoluteUrl, defaultSelectedUsers, ensureUser, principalTypes } = props;
const { groupName, groupId, webAbsoluteUrl, defaultSelectedItems, ensureUser, principalTypes } = props;
// Check if a group property was provided, and get the group ID
if (groupName) {
this.groupId = await this.peopleSearchService.getGroupId(groupName, webAbsoluteUrl);
Expand All @@ -92,9 +92,9 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
}

// Check for default user values
if (defaultSelectedUsers) {
if (defaultSelectedItems) {
let selectedPersons: IPersonaProps[] = [];
for (const userValue of props.defaultSelectedUsers) {
for (const userValue of props.defaultSelectedItems) {
let valueAndTitle: string[] = [];
valueAndTitle.push(userValue);
if (userValue && userValue.indexOf('/') > -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/PeopleSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default class SPPeopleSearchService {
loginName: element.LoginName ? element.LoginName : element.Key,
imageInitials: this.getFullNameInitials(element.DisplayText),
text: element.DisplayText,
secondaryText: element.ProviderName
secondaryText: element.EntityData.Email || element.ProviderName
} as IPeoplePickerUserItem;
case 'FormsRole':
return {
Expand Down

0 comments on commit b11c175

Please sign in to comment.