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: Refactored List component so type and display options are handled separately (#512) #513

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

johglove
Copy link
Contributor

No description provided.

@johglove johglove requested review from basham, athill and burnumd January 24, 2025 19:09
@johglove johglove added the bug Something isn't working label Jan 24, 2025
src/components/List/List.test.jsx Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.20%. Comparing base (ce7ee10) to head (70070ef).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #513   +/-   ##
=======================================
  Coverage   99.20%   99.20%           
=======================================
  Files         110      110           
  Lines        1256     1261    +5     
  Branches      172      172           
=======================================
+ Hits         1246     1251    +5     
  Misses          5        5           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@burnumd burnumd left a comment

Choose a reason for hiding this comment

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

I'm not sure this change qualifies as a fix since it will break existing uses of the List component. I made a suggestion to preserve the functionality, but I'm curious of others' opinions.

variant = "unordered",
...attrs
}) => {
const classes = classNames(
inline ? `${classPrefix}-inline` : classPrefix,
variant === "plain" && `${classPrefix}-plain`,
className
plain ? `${classPrefix}-plain` : "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
plain ? `${classPrefix}-plain` : "",
(plain || variant === "plain") ? `${classPrefix}-plain` : "",

Would help preserve backwards compatibility if the variant plain is deprecated and not actually removed.

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't have a "plain" prop, because then it could lead to some weird situations:

<List plain variant="description">

There should just be the "variant" prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having plain as a variant is what caused the original issue (#512). While having it as a separate prop may cause strange combinations they don't directly conflict outside and it would be on the users if they want the combination and if so how to handle any strangeness.

Copy link
Member

@basham basham Jan 24, 2025

Choose a reason for hiding this comment

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

FYI: I added a comment to #512 that I'm hoping may inform what happens in this PR.

Or maybe it just opens up a rabbit hole. Feel free to just shut me up if you want.

Copy link
Member

@basham basham left a comment

Choose a reason for hiding this comment

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

Don't consider my comments a blocker.

);
const ListTag = variant === "ordered" ? "ol" : "ul";
const ListTag = getElement(variant);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than a function, you could do this:

// At the top of the module:
const variantTagMap = {
  description: 'dl',
  ordered: 'ol',
  plain: 'ul',
  unordered: 'ul'
};

// Here:
const ListTag = variantTagMap[variant];

Up to you if you want to change it. But I feel like these mapping objects tend to be cleaner than functions and switch statements.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I wonder if we need to be a little more internally consistent on something. Here, we use both "tag" and "element" interchangeably. Then PR #511 uses the "component" prop. Maybe that's something we clean up at some point.

Copy link
Member

Choose a reason for hiding this comment

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

Likewise, HTML conventions tends to use a "type" attribute similarly to how we're using the "variant" prop here. So again, I don't know if this is something to discuss.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with standardizing on component (I've seen that on other projects). HTML using type as an attribute throws a wrench in our library components.l I think it was alerts we had a problem with in the alpha and switched away from type.

variant = "unordered",
...attrs
}) => {
const classes = classNames(
inline ? `${classPrefix}-inline` : classPrefix,
variant === "plain" && `${classPrefix}-plain`,
className
plain ? `${classPrefix}-plain` : "",
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't have a "plain" prop, because then it could lead to some weird situations:

<List plain variant="description">

There should just be the "variant" prop.

@johglove
Copy link
Contributor Author

My original intent was to keep existing functionality but just in a deprecated state until a major release. However forgot I needed to keep the original line and have readded it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants