-
Notifications
You must be signed in to change notification settings - Fork 308
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
fix: add Group entity to IDynamicPerson type and introduce typeguards to find the entity type #2688
Conversation
Thank you for creating a Pull Request @Mnickii. This is a checklist for the PR reviewer(s) to complete before approving and merging this PR:
|
@sebastienlevert from your proposal you'd suggested using personType as the property added, but Person entity already has personType as a property , which can be of a class Person or Group. |
Renaming means breaking change. @gavinbarron do you have a suggestion for this case? We need to identify a way to know if a picked entity is a group or a person. |
The updated storybook is available here |
The updated storybook is available here |
packages/mgt-components/src/components/mgt-person/mgt-person.ts
Outdated
Show resolved
Hide resolved
Adding a new property, which is what I think @Mnickii has done is not a breaking change though. Adding to the type guard idea you can factor out the typing even further: type IUser = (MicrosoftGraph.User | MicrosoftGraph.Person) & { entityType: 'user' }
type IContact = MicrosoftGraph.Contact & { entityType: 'contact' }
type IGroup MicrosoftGraph.Group & { entityType: 'group' }
export type IDynamicPerson = (
IUser
| IContact
| IGroup
) & {
/**
* personDetails.personImage is a toolkit injected property to pass image between components
* an optimization to avoid fetching the image when unnecessary.
*
* @type {string}
*/
personImage?: string;
};
isGroup = (obj: IDynamicPerson): obj is Group => {
return entityType === 'group';
}; |
Actually, on reflection, perhaps the better approach here is to provide an exported isGroup type guard function for developers to use should they need to determine an object emitted in an event is a group or not? Thoughts? |
I like this last proposal @gavinbarron! |
The updated storybook is available here |
The updated storybook is available here |
The updated storybook is available here |
The updated storybook is available here |
1 similar comment
The updated storybook is available here |
To illustrate this scenario, could we build a simple story? |
The updated storybook is available here |
packages/mgt-components/src/components/mgt-person/mgt-person.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-person/mgt-person.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-person/mgt-person.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-person/mgt-person.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-person/mgt-person.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-person/mgt-person.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-organization/mgt-organization.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-organization/mgt-organization.ts
Outdated
Show resolved
Hide resolved
The updated storybook is available here |
packages/mgt-components/src/components/mgt-organization/mgt-organization.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-organization/mgt-organization.ts
Outdated
Show resolved
Hide resolved
packages/mgt-components/src/components/mgt-people-picker/mgt-people-picker.ts
Outdated
Show resolved
Hide resolved
The updated storybook is available here |
1 similar comment
The updated storybook is available here |
The updated storybook is available here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic stuff, this give us a nice clean mechanism for understanding the type of a result with minimal code changes.
I really appreciate the work that you put in to get this one over the line.
… to find the entity type (#2688) add Group type to IDynamicPerson implement type guards refactor getInitials to use type guard functions add entityType story export typeguards
Closes #2649
PR Type
Bugfix
Description of the changes
Update the IDynamicPerson type with Group entity
Include entityType as a way to find the selected person type
PR checklist
yarn build
) and changes have been tested in at least two supported browsers (Edge + non-Chromium based browser)yarn setLicense
)Other information