Skip to content

Commit c69ba4a

Browse files
Add new prop for PeoplePicker control: useSubstrateSearch (pnp#1819)
1 parent 584b06c commit c69ba4a

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

docs/documentation/docs/controls/PeoplePicker.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This control renders a People picker field which can be used to select one or mo
1313

1414
![Selecting People](../assets/Peoplepicker-selectingchoices.png)
1515

16-
**Selected people**
16+
**Selected people**
1717

1818
![Selected people](../assets/Peoplepicker-multiplechoices.png)
1919

@@ -58,6 +58,10 @@ private _getPeoplePickerItems(items: any[]) {
5858
}
5959
```
6060

61+
## Use Substrate search
62+
63+
Sometimes, depending on how your organization is configured regarding users and groups, performing search can be tricky. As the `PeoplePicker` is using the `SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser` endpoint under the hood, there is an optional parameter called `useSubstrateSearch`. Setting this to `true` will perform a search using the Microsoft 365 Substrate, which will go through centralized stored data in order to find requested info. More details about this feature can be found [here](https://techcommunity.microsoft.com/t5/video-hub/admin-39-s-guide-to-the-microsoft-365-substrate/ba-p/3633132) and [here](https://youtu.be/uuiTR8r27Os?si=JkPyfiQggvCMj0xg&t=467).
64+
6165
## Implementation
6266

6367
The People picker control can be configured with the following properties:
@@ -66,8 +70,8 @@ The People picker control can be configured with the following properties:
6670
| ---- | ---- | ---- | ---- | ---- |
6771
| context | IPeoplePickerContext | yes | Context of the component, based on the SPFx context ([*BaseComponentContext*](https://learn.microsoft.com/javascript/api/sp-component-base/basecomponentcontext?view=sp-typescript-latest)). | |
6872
| titleText | string | no | Text to be displayed on the control | |
69-
| groupName | string | no | Group from which users are fetched. Leave it blank if need to filter all users. When both groupName and groupId specified groupName takes precedence. | _none_ |
70-
| groupId | number \| string \| (string\|number)[] | no | Group from which users are fetched. Leave it blank if need to filter all users. When both groupId and groupName specified groupName takes precedence. If string is specified, Microsoft 365 Group is used. If array is used, fetch results from multiple groups | _none_ |
73+
| groupName | string | no | Group from which users are fetched. Leave it blank if need to filter all users. When both groupName and groupId specified groupName takes precedence. | *none* |
74+
| groupId | number \| string \| (string\|number)[] | no | Group from which users are fetched. Leave it blank if need to filter all users. When both groupId and groupName specified groupName takes precedence. If string is specified, Microsoft 365 Group is used. If array is used, fetch results from multiple groups | *none* |
7175
| personSelectionLimit | number | no | Defines the limit of people that can be selected in the control | 1 |
7276
| required | boolean | no | Set if the control is required or not | false |
7377
| disabled | boolean | no | Set if the control is disabled or not | false |
@@ -88,8 +92,9 @@ The People picker control can be configured with the following properties:
8892
| suggestionsLimit | number | no | Maximum number of suggestions to show in the full suggestion list. | 5 |
8993
| resolveDelay | number | no | Add delay to resolve and search users | 200 |
9094
| placeholder | string | no | Short text hint to display in empty picker | |
91-
| styles | Partial<IBasePickerStyles> | no | Styles to apply on control | |
95+
| styles | Partial&lt;IBasePickerStyles&gt; | no | Styles to apply on control | |
9296
| searchTextLimit | number | no | Specifies the minimum character count needed to begin retrieving search results. | 2 |
97+
| useSubstrateSearch | boolean | no | When `true`, performs a wider search using Microsoft 365 Substrate. | false |
9398

9499
Enum `PrincipalType`
95100

src/controls/peoplepicker/IPeoplePicker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ export interface IPeoplePickerProps {
136136
* Define a filter to be applied to the search results, such as a filter to only show users from a specific domain
137137
*/
138138
resultFilter?: (result: IPersonaProps[]) => IPersonaProps[];
139+
/**
140+
* When `true`, performs a wider search using Microsoft 365 Substrate
141+
*/
142+
useSubstrateSearch?: boolean;
139143
}
140144

141145
export interface IPeoplePickerUserItem {

src/controls/peoplepicker/PeoplePickerComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
3636
constructor(props: IPeoplePickerProps) {
3737
super(props);
3838

39-
this.peopleSearchService = new SPPeopleSearchService(props.context);
39+
this.peopleSearchService = new SPPeopleSearchService(props.context, props.useSubstrateSearch);
4040
this.suggestionsLimit = this.props.suggestionsLimit ? this.props.suggestionsLimit : 5;
4141
this.searchTextCount = this.props.searchTextLimit ? this.props.searchTextLimit : 2;
4242

src/services/PeopleSearchService.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ import { IPeoplePickerContext, IPeoplePickerUserItem, PrincipalType } from "../P
1212
* Service implementation to search people in SharePoint
1313
*/
1414
export default class SPPeopleSearchService {
15-
private cachedPersonas: { [property: string]: IUserInfo[] };
1615
private cachedLocalUsers: { [siteUrl: string]: IUserInfo[] };
1716

1817
/**
1918
* Service constructor
2019
*/
21-
constructor(private context: IPeoplePickerContext) {
22-
this.cachedPersonas = {};
20+
constructor(private context: IPeoplePickerContext, private substrateSearchEnabled: boolean) {
2321
this.cachedLocalUsers = {};
2422
this.cachedLocalUsers[context.absoluteUrl] = [];
2523
// Setup PnPjs
@@ -123,6 +121,7 @@ export default class SPPeopleSearchService {
123121
PrincipalSource: 15,
124122
PrincipalType: this.getSumOfPrincipalTypes(principalTypes),
125123
QueryString: query,
124+
UseSubstrateSearch: this.substrateSearchEnabled ?? false
126125
}
127126
};
128127

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
13351335
personSelectionLimit={1}
13361336
ensureUser={true}
13371337
principalTypes={[PrincipalType.User, PrincipalType.SharePointGroup, PrincipalType.SecurityGroup, PrincipalType.DistributionList]}
1338-
onChange={this._getPeoplePickerItems} />
1338+
onChange={this._getPeoplePickerItems}
1339+
useSubstrateSearch={false} />
13391340

13401341
<PeoplePicker context={this.peoplePickerContext}
13411342
titleText="People Picker with filter for '.com'"

0 commit comments

Comments
 (0)