Skip to content

fix: change group type handling and cache key construction #3359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/mgt-components/src/graph/cacheStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const schemas = {
userFilters: 'userFilters',
cardState: 'cardState'
},
version: 4
version: 5
},
photos: {
name: 'photos',
Expand All @@ -43,15 +43,15 @@ export const schemas = {
groupPeople: 'groupPeople',
peopleQuery: 'peopleQuery'
},
version: 3
version: 4
},
groups: {
name: 'groups',
stores: {
groups: 'groups',
groupsQuery: 'groupsQuery'
},
version: 5
version: 6
},
get: {
name: 'responses',
Expand All @@ -65,7 +65,7 @@ export const schemas = {
stores: {
responses: 'responses'
},
version: 2
version: 3
},
files: {
name: 'files',
Expand Down
18 changes: 10 additions & 8 deletions packages/mgt-components/src/graph/graph.groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import {
IGraph,
prepScopes,
BatchResponse,
CacheItem,
CacheService,
CacheStore,
BatchResponse,
CollectionResponse
CollectionResponse,
IGraph,
prepScopes
} from '@microsoft/mgt-element';
import { Group } from '@microsoft/microsoft-graph-types';
import { schemas } from './cacheStores';
Expand All @@ -26,8 +26,8 @@ const groupTypeValues = ['any', 'unified', 'security', 'mailenabledsecurity', 'd
* @enum {string}
*/
export type GroupType = (typeof groupTypeValues)[number];
export const isGroupType = (value: unknown): value is GroupType =>
typeof value === 'string' && groupTypeValues.includes(value as GroupType);
export const isGroupType = (groupType: string): groupType is (typeof groupTypeValues)[number] =>
groupTypeValues.includes(groupType as GroupType);
export const groupTypeConverter = (value: string, defaultValue: GroupType = 'any'): GroupType =>
isGroupType(value) ? value : defaultValue;

Expand Down Expand Up @@ -99,8 +99,9 @@ export const findGroups = async (
groupTypes: GroupType[] = ['any'],
groupFilters = ''
): Promise<Group[]> => {
const groupTypesString = Array.isArray(groupTypes) ? groupTypes.join('+') : JSON.stringify(groupTypes);
let cache: CacheStore<CacheGroupQuery>;
const key = `${query ? query : '*'}*${groupTypes.join('+')}*${groupFilters}:${top}`;
const key = `${query ? query : '*'}*${groupTypesString}*${groupFilters}:${top}`;

if (getIsGroupsCacheEnabled()) {
cache = CacheService.getCache(schemas.groups, schemas.groups.stores.groupsQuery);
Expand Down Expand Up @@ -227,7 +228,8 @@ export const findGroupsFromGroup = async (
groupTypes: GroupType[] = ['any']
): Promise<Group[]> => {
let cache: CacheStore<CacheGroupQuery>;
const key = `${groupId}:${query || '*'}:${groupTypes.join('+')}:${transitive}`;
const groupTypesString = Array.isArray(groupTypes) ? groupTypes.join('+') : JSON.stringify(groupTypes);
const key = `${groupId}:${query || '*'}:${groupTypesString}:${transitive}`;

if (getIsGroupsCacheEnabled()) {
cache = CacheService.getCache(schemas.groups, schemas.groups.stores.groupsQuery);
Expand Down
Loading