@@ -11,7 +11,7 @@ import { classMap } from 'lit-html/directives/class-map';
1111import { repeat } from 'lit-html/directives/repeat' ;
1212import { findGroups , getGroupsForGroupIds , GroupType , getGroup } from '../../graph/graph.groups' ;
1313import { findPeople , getPeople , PersonType , UserType } from '../../graph/graph.people' ;
14- import { findUsers , findGroupMembers , getUser , getUsersForUserIds } from '../../graph/graph.user' ;
14+ import { findUsers , findGroupMembers , getUser , getUsersForUserIds , getUsers } from '../../graph/graph.user' ;
1515import { IDynamicPerson , ViewType } from '../../graph/types' ;
1616import { Providers , ProviderState , MgtTemplatedComponent , arraysAreEqual } from '@microsoft/mgt-element' ;
1717import '../../styles/style-helper' ;
@@ -376,6 +376,45 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
376376 this . requestStateUpdate ( true ) ;
377377 }
378378
379+ /**
380+ * Filters that can be set on the user properties query.
381+ */
382+ @property ( { attribute : 'user-filters' } )
383+ public get userFilters ( ) : string {
384+ return this . _userFilters ;
385+ }
386+
387+ public set userFilters ( value : string ) {
388+ this . _userFilters = value ;
389+ this . requestStateUpdate ( true ) ;
390+ }
391+
392+ /**
393+ * Filters that can be set on the people query properties.
394+ */
395+ @property ( { attribute : 'people-filters' } )
396+ public get peopleFilters ( ) : string {
397+ return this . _peopleFilters ;
398+ }
399+
400+ public set peopleFilters ( value : string ) {
401+ this . _peopleFilters = value ;
402+ this . requestStateUpdate ( true ) ;
403+ }
404+
405+ /**
406+ * Filters that can be set on the group query properties.
407+ */
408+ @property ( { attribute : 'group-filters' } )
409+ public get groupFilters ( ) : string {
410+ return this . _groupFilters ;
411+ }
412+
413+ public set groupFilters ( value : string ) {
414+ this . _groupFilters = value ;
415+ this . requestStateUpdate ( true ) ;
416+ }
417+
379418 /**
380419 * Get the scopes required for people picker
381420 *
@@ -406,6 +445,9 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
406445 private _groupType : GroupType = GroupType . any ;
407446 private _userType : UserType = UserType . any ;
408447 private _currentSelectedUser : IDynamicPerson ;
448+ private _userFilters : string ;
449+ private _groupFilters : string ;
450+ private _peopleFilters : string ;
409451
410452 private defaultPeople : IDynamicPerson [ ] ;
411453
@@ -915,7 +957,8 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
915957 this . groupId ,
916958 this . showMax ,
917959 this . type ,
918- this . transitiveSearch
960+ this . transitiveSearch ,
961+ this . _groupFilters
919962 ) ;
920963 } catch ( _ ) {
921964 this . _groupPeople = [ ] ;
@@ -924,13 +967,18 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
924967 people = this . _groupPeople || [ ] ;
925968 } else if ( this . type === PersonType . person || this . type === PersonType . any ) {
926969 if ( this . userIds ) {
927- people = await getUsersForUserIds ( graph , this . userIds ) ;
970+ people = await getUsersForUserIds ( graph , this . userIds , '' , this . userFilters ) ;
928971 } else {
929- people = await getPeople ( graph , this . userType ) ;
972+ const isUserOrContactType = this . userType === UserType . user || this . userType === UserType . contact ;
973+ if ( this . _userFilters && isUserOrContactType ) {
974+ people = await getUsers ( graph , this . _userFilters , this . showMax ) ;
975+ } else {
976+ people = await getPeople ( graph , this . userType , this . _peopleFilters ) ;
977+ }
930978 }
931979 } else if ( this . type === PersonType . group ) {
932- let groups = ( await findGroups ( graph , '' , this . showMax , this . groupType ) ) || [ ] ;
933- if ( groups [ 0 ] [ 'value' ] ) {
980+ let groups = ( await findGroups ( graph , '' , this . showMax , this . groupType , this . _groupFilters ) ) || [ ] ;
981+ if ( groups . length > 0 && groups [ 0 ] [ 'value' ] ) {
934982 groups = groups [ 0 ] [ 'value' ] ;
935983 }
936984 people = groups ;
@@ -945,8 +993,12 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
945993 ! this . selectedPeople . length &&
946994 ! this . defaultSelectedUsers
947995 ) {
948- this . defaultSelectedUsers = await getUsersForUserIds ( graph , this . defaultSelectedUserIds ) ;
949- this . defaultSelectedGroups = await getGroupsForGroupIds ( graph , this . defaultSelectedGroupIds ) ;
996+ this . defaultSelectedUsers = await getUsersForUserIds ( graph , this . defaultSelectedUserIds , '' , this . _userFilters ) ;
997+ this . defaultSelectedGroups = await getGroupsForGroupIds (
998+ graph ,
999+ this . defaultSelectedGroupIds ,
1000+ this . _groupFilters
1001+ ) ;
9501002
9511003 this . defaultSelectedGroups = this . defaultSelectedGroups . filter ( group => {
9521004 return group !== null ;
@@ -966,22 +1018,39 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
9661018
9671019 if ( this . groupId ) {
9681020 people =
969- ( await findGroupMembers ( graph , input , this . groupId , this . showMax , this . type , this . transitiveSearch ) ) || [ ] ;
1021+ ( await findGroupMembers (
1022+ graph ,
1023+ input ,
1024+ this . groupId ,
1025+ this . showMax ,
1026+ this . type ,
1027+ this . transitiveSearch ,
1028+ this . _groupFilters
1029+ ) ) || [ ] ;
9701030 } else {
9711031 if ( this . type === PersonType . person || this . type === PersonType . any ) {
9721032 try {
973- if ( this . userIds && this . userIds . length ) {
974- people = await getUsersForUserIds ( graph , this . userIds , input ) ;
1033+ // Default UserType === any
1034+ if ( this . userType === UserType . contact || this . userType === UserType . user ) {
1035+ // we might have a user-filters property set, search for users with it.
1036+ if ( this . userIds && this . userIds . length ) {
1037+ // has the user-ids proerty set
1038+ people = await getUsersForUserIds ( graph , this . userIds , input , this . _userFilters ) ;
1039+ } else {
1040+ people = await findUsers ( graph , input , this . showMax , this . _userFilters ) ;
1041+ }
9751042 } else {
976- people = ( await findPeople ( graph , input , this . showMax , this . userType ) ) || [ ] ;
1043+ people = ( await findPeople ( graph , input , this . showMax , this . userType , this . _peopleFilters ) ) || [ ] ;
9771044 }
9781045 } catch ( e ) {
9791046 // nop
9801047 }
9811048
982- if ( people . length < this . showMax && this . userType !== UserType . contact ) {
1049+ // Don't follow this path if a people-filters attribute is set on the component as the
1050+ // default type === PersonType.person
1051+ if ( people . length < this . showMax && this . userType !== UserType . contact && this . type !== PersonType . person ) {
9831052 try {
984- const users = ( await findUsers ( graph , input , this . showMax ) ) || [ ] ;
1053+ const users = ( await findUsers ( graph , input , this . showMax , this . _userFilters ) ) || [ ] ;
9851054
9861055 // make sure only unique people
9871056 const peopleIds = new Set ( people . map ( p => p . id ) ) ;
@@ -995,10 +1064,11 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
9951064 }
9961065 }
9971066 }
1067+
9981068 if ( ( this . type === PersonType . group || this . type === PersonType . any ) && people . length < this . showMax ) {
9991069 let groups = [ ] ;
10001070 try {
1001- groups = ( await findGroups ( graph , input , this . showMax , this . groupType ) ) || [ ] ;
1071+ groups = ( await findGroups ( graph , input , this . showMax , this . groupType , this . _groupFilters ) ) || [ ] ;
10021072 people = people . concat ( groups ) ;
10031073 } catch ( e ) {
10041074 // nop
@@ -1007,7 +1077,6 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
10071077 }
10081078 }
10091079 }
1010-
10111080 //people = this.getUniquePeople(people);
10121081 this . _foundPeople = this . filterPeople ( people ) ;
10131082 }
@@ -1606,7 +1675,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
16061675 // check if people need to be updated
16071676 // ensuring people list is displayed
16081677 // find ids from selected people
1609- if ( people ) {
1678+ if ( people && people . length > 0 ) {
16101679 const idFilter = this . selectedPeople . map ( el => {
16111680 return el . id ? el . id : el . displayName ;
16121681 } ) ;
0 commit comments