Skip to content

Commit 8691055

Browse files
fix: people-picker uses show-max attribute (#2527)
adds top to caching of people picker graph calls ensures that show max is used when loading the initial state with no other options set Co-authored-by: Sébastien Levert <[email protected]>
1 parent d35ba23 commit 8691055

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ <h2>mgt-login</h2>
5454
</div>
5555
<!-- <mgt-login></mgt-login> -->
5656
<!-- <h2>mgt-person me query two lines card on click with presence</h2> -->
57-
<mgt-person person-query="me" view="twoLines" person-card="hover" show-presence></mgt-person>
57+
<!-- <mgt-person person-query="me" view="twoLines" person-card="hover" show-presence></mgt-person> -->
5858
<!-- <mgt-person-card person-query="me"></mgt-person-card> -->
5959
<h2>mgt-people-picker</h2>
60-
<mgt-people-picker></mgt-people-picker>
61-
<h2>mgt-teams-channel-picker</h2>
62-
<mgt-teams-channel-picker></mgt-teams-channel-picker>
60+
<mgt-people-picker show-max="6"></mgt-people-picker>
61+
<!-- <h2>mgt-teams-channel-picker</h2>
62+
<mgt-teams-channel-picker></mgt-teams-channel-picker> -->
6363
<!-- <h2>mgt-tasks</h2>
6464
<mgt-tasks></mgt-tasks> -->
6565
<!-- <h2>mgt-agenda group-by-day</h2>

packages/mgt-components/src/components/mgt-people-picker/mgt-people-picker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
10711071
if (this._userFilters && isUserOrContactType) {
10721072
people = await getUsers(graph, this._userFilters, this.showMax);
10731073
} else {
1074-
people = await getPeople(graph, this.userType, this._peopleFilters);
1074+
people = await getPeople(graph, this.userType, this._peopleFilters, this.showMax);
10751075
}
10761076
}
10771077
} else if (this.type === PersonType.group) {

packages/mgt-components/src/graph/graph.groups.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const findGroups = async (
109109
const scopes = 'Group.Read.All';
110110

111111
let cache: CacheStore<CacheGroupQuery>;
112-
const key = `${query ? query : '*'}*${groupTypes}*${groupFilters}`;
112+
const key = `${query ? query : '*'}*${groupTypes}*${groupFilters}:${top}`;
113113

114114
if (getIsGroupsCacheEnabled()) {
115115
cache = CacheService.getCache(schemas.groups, schemas.groups.stores.groupsQuery);

packages/mgt-components/src/graph/graph.people.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ export const findPeople = async (
173173
export const getPeople = async (
174174
graph: IGraph,
175175
userType: UserType = UserType.any,
176-
peopleFilters = ''
176+
peopleFilters = '',
177+
top = 10
177178
): Promise<Person[]> => {
178179
const scopes = 'people.read';
179180

180181
let cache: CacheStore<CachePeopleQuery>;
181-
const cacheKey = peopleFilters ? peopleFilters : `*:${userType}`;
182+
const cacheKey = `${peopleFilters ? peopleFilters : `*:${userType}`}:${top}`;
182183

183184
if (getIsPeopleCacheEnabled()) {
184185
cache = CacheService.getCache<CachePeopleQuery>(schemas.people, schemas.people.stores.peopleQuery);
@@ -205,7 +206,7 @@ export const getPeople = async (
205206

206207
let people: CollectionResponse<Person>;
207208
try {
208-
let graphRequest = graph.api(uri).middlewareOptions(prepScopes(scopes)).filter(filter);
209+
let graphRequest = graph.api(uri).middlewareOptions(prepScopes(scopes)).top(top).filter(filter);
209210

210211
if (userType !== UserType.contact) {
211212
// for any type other than Contact, user a wider search

packages/mgt-components/src/graph/graph.user.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const getIsUsersCacheEnabled = (): boolean =>
5252
export const getUsers = async (graph: IGraph, userFilters = '', top = 10): Promise<User[]> => {
5353
const apiString = '/users';
5454
let cache: CacheStore<CacheUserQuery>;
55-
const cacheKey = userFilters === '' ? '*' : userFilters;
55+
const cacheKey = `${userFilters === '' ? '*' : userFilters}:${top}`;
5656
const cacheItem = { maxResults: top, results: null };
5757

5858
if (getIsUsersCacheEnabled()) {
@@ -386,11 +386,12 @@ export const getUsersForPeopleQueries = async (
386386
export const findUsers = async (graph: IGraph, query: string, top = 10, userFilters = ''): Promise<User[]> => {
387387
const scopes = 'User.ReadBasic.All';
388388
const item = { maxResults: top, results: null };
389+
const cacheKey = `${query}:${top}:${userFilters}`;
389390
let cache: CacheStore<CacheUserQuery>;
390391

391392
if (getIsUsersCacheEnabled()) {
392393
cache = CacheService.getCache<CacheUserQuery>(schemas.users, schemas.users.stores.usersQuery);
393-
const result: CacheUserQuery = await cache.getValue(query);
394+
const result: CacheUserQuery = await cache.getValue(cacheKey);
394395

395396
if (result && getUserInvalidationTime() > Date.now() - result.timeCached) {
396397
return result.results.map(userStr => JSON.parse(userStr) as User);
@@ -444,7 +445,7 @@ export const findGroupMembers = async (
444445
const item = { maxResults: top, results: null };
445446

446447
let cache: CacheStore<CacheUserQuery>;
447-
const key = `${groupId || '*'}:${query || '*'}:${personType}:${transitive}:${userFilters}`;
448+
const key = `${groupId || '*'}:${query || '*'}:${top}:${personType}:${transitive}:${userFilters}`;
448449

449450
if (getIsUsersCacheEnabled()) {
450451
cache = CacheService.getCache<CacheUserQuery>(schemas.users, schemas.users.stores.usersQuery);

0 commit comments

Comments
 (0)