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: checkbox_group re-export #2212

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

AkshatJawne
Copy link
Contributor

@AkshatJawne AkshatJawne commented Sep 9, 2024

Resolves #2211

Needed for changes in plugins PR: deephaven/deephaven-plugins#813

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.

Project coverage is 46.60%. Comparing base (ec9b41e) to head (d23335c).

Files with missing lines Patch % Lines
packages/components/src/spectrum/CheckboxGroup.tsx 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2212      +/-   ##
==========================================
- Coverage   46.61%   46.60%   -0.01%     
==========================================
  Files         692      694       +2     
  Lines       38508    38517       +9     
  Branches     9826     9622     -204     
==========================================
+ Hits        17949    17951       +2     
- Misses      20506    20555      +49     
+ Partials       53       11      -42     
Flag Coverage Δ
unit 46.60% <22.22%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

@bmingles bmingles left a comment

Choose a reason for hiding this comment

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

Left some comments

if (isElementOfType(child, Checkbox)) {
return child;
}
return <Checkbox checked={false}>{child}</Checkbox>;
Copy link
Contributor

@bmingles bmingles Sep 10, 2024

Choose a reason for hiding this comment

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

I think this needs to be the Spectrum Checkbox since that is what we use in dh.ui. That should also allow you to get rid of checked={false}

Copy link
Contributor

@bmingles bmingles Sep 10, 2024

Choose a reason for hiding this comment

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

Also, I'd still highly recommend adding a couple of representative examples in the Styleguide. As-is, I don't think it actually accepts primitive children. Alternatively, you could write unit tests to verify the JSX is supported and produces expected output.

Copy link
Contributor

@bmingles bmingles left a comment

Choose a reason for hiding this comment

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

Left some comments

@AkshatJawne
Copy link
Contributor Author

Cannot verify in styleguide as labels are currently blank due to latest core change @bmingles , will update and add examples as soon as that is fixed

@bmingles
Copy link
Contributor

Cannot verify in styleguide as labels are currently blank due to latest core change @bmingles , will update and add examples as soon as that is fixed

@AkshatJawne I don't think those are related. The labels that are missing are in the ListView right?

Copy link
Contributor

@bmingles bmingles left a comment

Choose a reason for hiding this comment

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

Bumping back to you since still in flight.

{'String 2'}
{444}
{999}
{true}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the styleguide, I think there's a bug with handling of true / false

image

There's probably a stringify that needs to happen somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I wrap my children in wrappedChildren, I pass in String(child) into the checkbox, which seems to work for the other primitives. Is there any other way I can stringify?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the issue here is that React.Children.map converts true / false to null.

Copy link
Contributor

Choose a reason for hiding this comment

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

You might try ensureArray from @deephaven/utils instead

Copy link
Contributor

@bmingles bmingles Sep 19, 2024

Choose a reason for hiding this comment

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

Actually, you may still need React.Children.map to deal with key props, but you'll need to convert booleans to strings before passing into it.

children,
...props
}: CheckboxGroupProps): JSX.Element {
const [checkedState, setCheckedState] = useState<{ [key: number]: boolean }>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to store checkbox state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I use the DH Checkbox, there is this weird effect where I had to store state, since when I was checking one of the checkbox's in the group, all of the checkboxes were going into a checked state.

Copy link
Contributor

Choose a reason for hiding this comment

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

So is this unnecessary if you switch to SpectrumCheckbox ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think something like this will work:

const wrappedChildren = useMemo(
  () =>
    ensureArray(children).map(child =>
      isElementOfType(child, Checkbox) ? (
        child
      ) : (
        <Checkbox key={String(child)} value={String(child)}>
          {String(child)}
        </Checkbox>
      )
    ),
  [children]
);

Copy link
Contributor

@bmingles bmingles left a comment

Choose a reason for hiding this comment

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

Left some comments.

@AkshatJawne
Copy link
Contributor Author

Ironed out comments, not sure why the String(child) is resulting in booleans resulting in null showing up as the text, @bmingles any ideas?

Copy link
Contributor

@bmingles bmingles left a comment

Choose a reason for hiding this comment

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

See inline comments

@AkshatJawne
Copy link
Contributor Author

Should be good now, I still had to clone element, or else when we passed in Checkbox children, then the value would not be assigned properly, and thus selecting one would select all of them. @bmingles

@bmingles
Copy link
Contributor

I think the unit test failures are at least in part to needing a rebase / merge on latest main.

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

Successfully merging this pull request may close these issues.

checkbox_group re-export
2 participants