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

fix(link-with-icon): refactor LINK_SIZE enum #11071

Conversation

andy-blum
Copy link
Contributor

Related Ticket(s)

ADCMS-3542

Description

We've been digging into a sticky bug that we think we finally have an explanation for. To see the problem in action see this codepen.

As we understand it, this issue is:

There are lots of other places in the code base that we use ENUMs that don’t cause issues, but this one does and as far as we can tell it’s the only one that:

  • is defined in CWC
  • is used to set a default value in C4IBM

Changelog

Changed

  • Refactor LINK_SIZE from enum to a union

@andy-blum andy-blum requested a review from a team as a code owner October 27, 2023 16:21
@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Oct 27, 2023

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Oct 27, 2023

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Oct 30, 2023

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Oct 30, 2023

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Oct 30, 2023

@@ -50,7 +50,7 @@ class DDSLinkWithIcon extends StableSelectorMixin(BXLink) {
* @internal
*/
@property()
size = LINK_SIZE.LARGE;
size = 'lg' as LINK_SIZE;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, having to cast this string seems like a smell. Does the solution from https://dev.to/ivanzm123/dont-use-enums-in-typescript-they-are-very-dangerous-57bh obviate the need for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to this method.

I had originally gone with the union instead to avoid having to import both an object and a type, but it seems that the type cascades through the inheritance chain on its own just fine, and if the object keeps the same name as the enum, we can make future refactors simpler.

Comment on lines 23 to 24
[`Small size (sm)`]: 'sm',
[`Large size (lg)`]: 'lg',
Copy link
Member

Choose a reason for hiding this comment

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

Given #11071 (comment), what do you think about reverting this?

@@ -190,7 +182,7 @@ class BXLink extends FocusMixin(LitElement) {
* Link size.
*/
@property({ reflect: true })
size = LINK_SIZE.REGULAR;
size: LINK_SIZE_TYPE = '';
Copy link
Member

Choose a reason for hiding this comment

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

Same question here – can you go back to setting this to LINK_SIZE.REGULAR?

@andy-blum andy-blum changed the base branch from main to release/v1.53.0 November 1, 2023 15:22
@andy-blum andy-blum force-pushed the fix/enum-compilation-bug branch from 5443497 to af5f295 Compare November 1, 2023 15:27
@IgnacioBecerra IgnacioBecerra added the Ready to merge Label for the pull requests that are ready to merge label Nov 1, 2023
@IgnacioBecerra IgnacioBecerra merged commit cf570e1 into carbon-design-system:release/v1.53.0 Nov 1, 2023
@andy-blum andy-blum deleted the fix/enum-compilation-bug branch November 1, 2023 20:37
kennylam pushed a commit to kennylam/carbon-for-ibm-dotcom that referenced this pull request Dec 4, 2023
)

* fix(link-with-icon): refactor LINK_SIZE enum

* fix(link-with-icon): export LINK_SIZE

* fix(link-with-icon): change union to object-to-type

* fix(link-with-icon): revert LINK_SIZE reference removals

* chore(release): publish

 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]

* Revert "chore(release): publish"

This reverts commit af5f295.

---------

Co-authored-by: ibmdotcom-bot <[email protected]>
kennylam pushed a commit to kennylam/carbon-for-ibm-dotcom that referenced this pull request Jun 11, 2024
)

* fix(link-with-icon): refactor LINK_SIZE enum

* fix(link-with-icon): export LINK_SIZE

* fix(link-with-icon): change union to object-to-type

* fix(link-with-icon): revert LINK_SIZE reference removals

* chore(release): publish

 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]
 - @carbon/[email protected]

* Revert "chore(release): publish"

This reverts commit af5f295.

---------

Co-authored-by: ibmdotcom-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Ready to merge Label for the pull requests that are ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants