Skip to content
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

feat!: convert enums to string unions #2962

Merged
merged 5 commits into from
Jan 24, 2024

Conversation

gavinbarron
Copy link
Member

@gavinbarron gavinbarron commented Jan 23, 2024

Closes #2942

PR Type

  • Feature

Description of the changes

rework all enum based component attribute properties as string unions for consistency between react and web components

PR checklist

  • License header has been added to all new source files (yarn setLicense)
  • Contains NO breaking changes

Other information

There are many breaking changes in this PR for React consumers of the library, this simplifies the usage of the components

Old style:

import { PersonCardInteraction, ViewType, Person } from '@microsoft/mgt-react';

// snip
return <Person personCardInteraction={PersonCardInteraction.click} view={ViewType.twolines}  personQuery="me"/>

Old style:

import { Person } from '@microsoft/mgt-react';

// snip
return <Person personCardInteraction="click" view="twolines"  personQuery="me" />

Thanks to the use of string unions we still get intellisense and type checking on these props, they're just simpler to use and align to the web component attributes e.g.

<mgt-person person-card="click" view="twolines" person-query="me"></mgt-person>

All enums used as properties on components have been converted to string union types

refactor: ViewType is now a string union type and not an enum
   BREAKING CHANGE: ViewType is now a string union type and not an enum

 refactor: UserType is now a string union type and not an enum
   BREAKING CHANGE: UserType is now a string union type and not an enum

 refactor: PersonType is now a string union type and not an enum
   BREAKING CHANGE: PersonType is now a string union type and not an enum

 refactor: GroupType is now a string union type and not an enum
   BREAKING CHANGE: GroupType is now a string union type and not an enum

 refactor: groupType property on MgtPeoplePicker is now GroupType[]
   BREAKING CHANGE: groupType property on MgtPeoplePicker is now a GroupType[] not a GroupType that is a bitmask of the desired group types. Developers using the group-type attribute will find the behavior unchanged.

 refactor: avatarType renamed to AvatarType and converted to string union type
   BREAKING CHANGE: the avatarType eunm has been renamed to AvatarType for consistency and converted to a string union type

 refactor: ResponseType for mgt-get converted to string union type from enum
   BREAKING CHANGE: the ResponseType for mgt-get is now a string union type and not an enum

 refactor: PersonCardInteraction is now a string union type and not an enum
   BREAKING CHANGE: PersonCardInteraction is now a string union type and not an enum
Copy link

🚀 New react-contoso sample application deployed here

1 similar comment
Copy link

🚀 New react-contoso sample application deployed here

Copy link

📖 The updated storybook is available here

1 similar comment
Copy link

📖 The updated storybook is available here

Copy link

🚀 New react-contoso sample application deployed here

Copy link

📖 The updated storybook is available here

@gavinbarron gavinbarron changed the title Feat/convert enums string unions feat: convert enums to string unions Jan 24, 2024
Signed-off-by: Martin Musale <martinmusale@microsoft.com>
Copy link
Contributor

@musale musale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the changes this adds in MGT usage especially for react. I made updates to storybook usage and it's good to go!

Copy link

🚀 New react-contoso sample application deployed here

@musale musale changed the title feat: convert enums to string unions feat!: convert enums to string unions Jan 24, 2024
Copy link

📖 The updated storybook is available here

@sebastienlevert
Copy link
Contributor

This impacts directly #2934. We should wait for this to be merged before we merge the big storybook changes.

Copy link

🚀 New react-contoso sample application deployed here

Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
mgt-components.src.components 85% 67% 0
mgt-components.src.components.mgt-contact 63% 100% 0
mgt-components.src.components.mgt-file 62% 100% 0
mgt-components.src.components.mgt-file-list 46% 100% 0
mgt-components.src.components.mgt-file-list.mgt-file-upload 49% 86% 0
mgt-components.src.components.mgt-get 22% 100% 0
mgt-components.src.components.mgt-messages 68% 100% 0
mgt-components.src.components.mgt-organization 47% 100% 0
mgt-components.src.components.mgt-person 78% 65% 0
mgt-components.src.components.mgt-person-card 56% 54% 0
mgt-components.src.components.mgt-picker 80% 100% 0
mgt-components.src.components.mgt-profile 40% 100% 0
mgt-components.src.components.mgt-tasks-base 87% 100% 0
mgt-components.src.components.mgt-theme-toggle 100% 100% 0
mgt-components.src.components.mgt-todo 79% 100% 0
mgt-components.src.components.sub-components.mgt-flyout 72% 53% 0
mgt-components.src.components.sub-components.mgt-spinner 100% 100% 0
mgt-components.src.graph 38% 78% 0
mgt-components.src.styles 92% 80% 0
mgt-components.src.utils 78% 12% 0
mgt-element.dist.es6.components.src.components 72% 73% 0
mgt-element.dist.es6.mock.src.mock 90% 72% 0
mgt-element.dist.es6.providers.src.providers 85% 73% 0
mgt-element.dist.es6.src 91% 80% 0
mgt-element.dist.es6.utils.src.utils 66% 69% 0
mgt-element.src 93% 40% 0
mgt-element.src.components 78% 100% 0
mgt-element.src.mock 81% 56% 0
mgt-element.src.providers 83% 91% 0
mgt-element.src.utils 71% 90% 0
Summary 65% (13924 / 21438) 63% (402 / 634) 0

Copy link

📖 The updated storybook is available here

@gavinbarron
Copy link
Member Author

I really like the changes this adds in MGT usage especially for react. I made updates to storybook usage and it's good to go!

Thank you for catching those, I got the ones in the tests, but totally didn't think to double check the casing in the stories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG] Convert enums to string unions
4 participants