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

Writing code to convert enum props to string literal #1815

Closed
Tracked by #1800
yangwooseong opened this issue Dec 15, 2023 · 1 comment · Fixed by #1990
Closed
Tracked by #1800

Writing code to convert enum props to string literal #1815

yangwooseong opened this issue Dec 15, 2023 · 1 comment · Fixed by #1990
Assignees
Labels
bezier-codemod Issue or PR related to bezier-codemod

Comments

@yangwooseong
Copy link
Collaborator

yangwooseong commented Dec 15, 2023

Summary

  • 컴포넌트 속성값으로 enum을 주던 것을 string literal로 변경하는 codemod 를 추가합니다.

Description

// As-is
import { Button, ButtonStyleVariant, ButtonColorVariant } from '@channel.io/bezier-react'

<Button
  styleVariant={ButtonStyleVariant.Tertiary}
  colorVariant={ButtonColorVariant.MonochromeLight}
/>

// To-be
import { Button } from '@channel.io/bezier-react'

<Button
  styleVariant="tertiary"
  colorVariant="monochromeLight"
/>
  • 기존의 codemod 에서 styled-components 에서 스타일링 하고 있는 부분까지 커버가 되는지 확인이 필요합니다.
  • 변환해야 하는 속성들은 다음과 같습니다.
  • AvatarSize, AvatarGroupEllipsisType
  • BannerVariant
  • ButtonStyleVariant, ButtonColorVariant
  • IconSize
  • StatusSize, StatusType
  • SegmentedControlSize
  • SwitchSize
  • TagBadgeSize, TagBadgeVariant
  • TextFieldVariant
  • TooltipPosition
  • (WIP)

References

@yangwooseong yangwooseong added the bezier-codemod Issue or PR related to bezier-codemod label Dec 15, 2023
@yangwooseong yangwooseong mentioned this issue Dec 15, 2023
@yangwooseong yangwooseong self-assigned this Dec 18, 2023
@yangwooseong
Copy link
Collaborator Author

enum -> string literal 로 변경하면서 enum value가 number타입인 것을 모두 string으로 변경하자 (EmojiSize.Size16 = '16'이 되도록)

yangwooseong added a commit that referenced this issue Feb 8, 2024
… Banner, etc (#1984)

<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] I tested the changes in various browsers. (or didn't have to)
  - Windows: Chrome, Edge, (Optional) Firefox
  - macOS: Chrome, Edge, Safari, (Optional) Firefox

## Related Issue
<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

- #1815
- #1568

## Summary
<!-- Please brief explanation of the changes made -->

- 컴포넌트의 enum 타입을 string literal 타입으로 변경하고 codemod 에 변경되는 속성을 추가합니다. 
- 한 pr 에 하기에는 변경사항이 많아서 2~3개로 분리해서 작업하려고 합니다.

## Details
<!-- Please elaborate description of the changes -->

- `v2-enum-member-to-string-literal` codemod 를 사용해서 하나씩 변환했습니다. 
- 스토리북에서 enum 으로부터 control option 을 얻어오는 부분은 string literal 타입이 되면 스토리북이
알아서 radio 버튼으로 바꿔주기 때문에 제거했습니다. 개발 모드에서는 input type으로 되어 직접 입력해야하지만, 크게
불편하지는 않다고 생각됩니다.
- StatusType 만 'OnlineCrescent' 처럼 PascalCase 로 되어있고 다른 부분은 kebab-case
라서 변환하면서 모두 kebab-case 로 통일해야 하나 고민입니다. 일관성 측면에서 통일하는게 좋아보입니다.



### Breaking change? (Yes/No)
<!-- If Yes, please describe the impact and migration path for users -->

- Yes

## References
<!-- Please list any other resources or points the reviewer should be
aware of -->

- None
yangwooseong added a commit that referenced this issue Feb 13, 2024
…Tooltip, etc (#1990)

<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] I tested the changes in various browsers. (or didn't have to)
  - Windows: Chrome, Edge, (Optional) Firefox
  - macOS: Chrome, Edge, Safari, (Optional) Firefox

## Related Issue
<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

- Fixes #1815 
- Fixes #1568 

## Summary
<!-- Please brief explanation of the changes made -->

- #1984 의 후속 작업입니다. 
- 컴포넌트의 enum 타입을 string literal 타입으로 변경하고, codemod 에 변경사항을 추가하여 마이그레이션을
지원합니다.

## Details
<!-- Please elaborate description of the changes -->

- 대부분의 경우는 이전 pr과 동일하게 PascalCase 의 enum 을 kebab-case 의 string literal
타입으로 변환하는 작업입니다. 여기서 2가지 경우만 약간의 예외적인 상황이 있었습니다.
- `IconSize`의 경우 `IconSize.Normal = 24`와 같이 size value 를 그대로 사용하던 것을
`'normal'` 을 받고 컴포넌트 내부에서 size 로 맵핑하는 형식으로 변경했습니다. number literal 을 그대로
받는 것보다 이렇게 하는 게 다른 컴포넌트와의 일관성이 유지된다고 생각하였습니다.
- 한편 `TextAreaHeight` enum 은 `TextAreaHeight.Row16` 처럼 쓰이고 있어서 이를
`'row16'` 으로 바꾸는 것보다는 `16`으로 받는게 깔끔한 것 같아서 예외적으로 number literal 을 받도록
했습니다.

### Breaking change? (Yes/No)
<!-- If Yes, please describe the impact and migration path for users -->
- Yes (changeset 참고) 

## References
<!-- Please list any other resources or points the reviewer should be
aware of -->

- None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bezier-codemod Issue or PR related to bezier-codemod
Projects
Archived in project
1 participant