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

refactor(select): make selection string based #12

Merged
merged 1 commit into from
Apr 1, 2020

Conversation

HendrikThePendric
Copy link
Contributor

I've addressed the following:

  • Refactored the components so that they work with string based values
  • Updated docs and propTypes
  • Updated demo stories
  • Updated e2e stories and tests

All tests are green and when I do a full test run, I don't seem to be collecting any prop-type errors, so I think I've caught everything.

However, this PR touched a lot of files, so I won't be surprised if we end up finding some little issues.

Copy link
Member

@ismay ismay left a comment

Choose a reason for hiding this comment

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

Looks good, I think you got basically everything 🤘. Just a couple of very minor things:

  1. We should also update the error message in MultiSelect/SelectionList.js line 20 - 22 (Github won't let me leave a comment directly for some reason).
  2. Same for line 12 - 14 of SingleSelect/Selection.js.
  3. And unrelated, but 119 - 123 of Select/Select.js looks redundant. Maybe that changed when implementing the popperized Menu?

edit: One thing we could do is also add some tests for what will happen with duplicate values (and other data the Select will process, but not function correctly with). So that we know how it fails, and can make sure that the failure won't change as well.

@HendrikThePendric
Copy link
Contributor Author

@ismay Thanks for spotting those three things, I've addressed them in 1ccc223. Could you re-review?

@ismay ismay self-requested a review March 31, 2020 08:23
@varl
Copy link
Contributor

varl commented Mar 31, 2020

Now that we do not rely on the label + value, we could change the Option implementations to use the pattern we use elsewhere where the label is the children:

<Option value="smth">
  This is the label
</Option>

May be a different PR if we do that though.

Copy link
Contributor

@varl varl left a comment

Choose a reason for hiding this comment

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

None of the commits that introduce breaking changes has a proper commit message.

Copy link
Member

@ismay ismay left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments. I'm not sure about this part of the error message change:

The selected value could not be found in a child of the select..

To me that seems slightly difficult to understand. Maybe we could be more explicit, and word it as: There is no option with the value: "${value}". Make sure that all the values passed to the selected prop match an existing option.

The rest of the changes seem good to me 👍

@ismay ismay self-requested a review March 31, 2020 09:10
Copy link
Member

@ismay ismay left a comment

Choose a reason for hiding this comment

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

And this:

One thing we could do is also add some tests for what will happen with duplicate values (and other data the Select will process, but not function correctly with). So that we know how it fails, and can make sure that the failure won't change as well.

Do you think that'd be better suited as a follow up PR, or in this one? (Or not at all is also an option of course)

@HendrikThePendric
Copy link
Contributor Author

None of the commits that introduce breaking changes has a proper commit message.

Good catch. I'll squash my commits and add a correct footer

One thing we could do is also add some tests for what will happen with duplicate values (and other data the Select will process, but not function correctly with). So that we know how it fails, and can make sure that the failure won't change as well.

Do you think that'd be better suited as a follow up PR, or in this one? (Or not at all is also an option of course)

I'll look into this as well. It should end up being a passing test on "failing" behaviour. It'd be good to add, but I might require some assistance....

@HendrikThePendric
Copy link
Contributor Author

Now that we do not rely on the label + value, we could change the Option implementations to use the pattern we use elsewhere where the label is the children:

<Option value="smth">
  This is the label
</Option>

May be a different PR if we do that though.

Done in 7db3e9f

@ismay
Copy link
Member

ismay commented Apr 1, 2020

Now that we do not rely on the label + value, we could change the Option implementations to use the pattern we use elsewhere where the label is the children:

<Option value="smth">
  This is the label
</Option>

May be a different PR if we do that though.

Done in 7db3e9f

I think that that'll break the assumption the Select wrapper makes an the options having a label prop. I believe it uses that for filtering for example.

I would retain the current option implementation. If devs need to pass something as a child they have the option to create a custom option, whilst retaining the label prop (and other assumptions the select makes about the options).

Maybe we shouldn't change too much in this PR to keep the changes manageable.

@HendrikThePendric
Copy link
Contributor Author

I think that that'll break the assumption the Select wrapper makes an the options having a label prop. I believe it uses that for filtering for example.

Yeah, I can confirm that this is in fact happening. Somehow the test was green for me locally, but the test run here just failed due to filtering. I think filtering based on children is not really a valid approach. So I'll revert 7db3e9f.

I am still working on a test for the duplicate value behaviour though.

@HendrikThePendric HendrikThePendric force-pushed the refactor/select-with-string-values branch from bd07c9e to 4401ee9 Compare April 1, 2020 09:16
@HendrikThePendric
Copy link
Contributor Author

@varl @ismay I think this PR is now ready for a final re-review:

  • I've squashed my commits and included a BREAKING CHANGE section in the commit body
  • I've added tests that document what happens if the selects do encounter duplicate values
  • I've kept the label prop on the option components instead of switching to children, because the children approach doesn't go well with how options are being filtered.

BREAKING CHANGE:
- SingleSelect selection is now a string instead of an object with a value and label property
- MultiSelect selection is now an array of strings instead of an array of objects with a value and label property
@HendrikThePendric HendrikThePendric force-pushed the refactor/select-with-string-values branch from a679cf2 to e3627a4 Compare April 1, 2020 10:23
@ismay ismay self-requested a review April 1, 2020 10:25
Copy link
Member

@ismay ismay left a comment

Choose a reason for hiding this comment

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

Thanks for the modifications @HendrikThePendric, this looks good to merge to me (assuming that the tests will pass).

@HendrikThePendric HendrikThePendric merged commit 95600e4 into alpha Apr 1, 2020
@HendrikThePendric HendrikThePendric deleted the refactor/select-with-string-values branch April 1, 2020 11:33
@dhis2-bot
Copy link
Contributor

@HendrikThePendric HendrikThePendric added the breaking change Fixing this will break the existing API label Apr 25, 2020
@HendrikThePendric HendrikThePendric mentioned this pull request Apr 25, 2020
@dhis2-bot
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Fixing this will break the existing API released on @alpha released
Development

Successfully merging this pull request may close these issues.

None yet

4 participants