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

[Data Grid] Pluralization of sort button #5043

Merged
merged 12 commits into from
Aug 23, 2021

Conversation

babs20
Copy link
Contributor

@babs20 babs20 commented Aug 17, 2021

Summary

Fixes #5037

Updated the EuiDataGrid sort button text to include pluralization of the text when fields are sorted.

Before:
Before 1
Before 2

After:
Before 1
Before 2

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
    - [ ] Props have proper autodocs and playground toggles
    - [ ] Added documentation
  • Checked Code Sandbox works for the any docs examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@babs20 babs20 marked this pull request as ready for review August 17, 2021 19:18
@babs20
Copy link
Contributor Author

babs20 commented Aug 17, 2021

To the reviewer, not sure if I need to add any tests for this change. I didn't see any test checking the text of the sort button after sorting a column, so I assumed it was not needed.

Let me know if you need me to implement a test for this change.

@elizabetdev
Copy link
Contributor

Thanks for opening this PR! 🎉 

Let me get our CI running our tests, build a preview, and then I can start a review: jenkins test this.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5043/

@elizabetdev elizabetdev self-requested a review August 18, 2021 13:44
Copy link
Contributor

@elizabetdev elizabetdev left a comment

Choose a reason for hiding this comment

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

Thanks @babs20! Tested, looked at the code, and LGTM! 🎉

I don't think we need tests for this but let me confirm with @chandlerprall.

@chandlerprall
Copy link
Contributor

Thank you for the change, @babs20 ! Some languages have different rules instead of 1 vs 0 or 2+; e.g. pluralization for 2 items is different than 3 items, and we may need to try and account for that. Let me track down some more information before we move forward with this change.

It would be great to have a new test covering this change; but I'll research this first.

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Instead of concatenating / performing the pluralizing logic in the template string, we can move it into the i18n token itself which will allow applications full control over how they want to localize/translate:

The Interpolation example shows how the value can be included in the token defaults, but it will require a small refactor because our i18n utility doesn't support passing values to more than one tokens. Instead of nesting EuiI18n, that render prop function can be replaced by our useEuiI18n hook (also in that Interpolation section).

As an additional reference, color_picker_swatch.tsx:32 has an instance of useEuiI18n with a value.

Let me know if any of that doesn't make sense or isn't clear how to implement.

@babs20
Copy link
Contributor Author

babs20 commented Aug 19, 2021

After looking over this again, I believe I misunderstood the useEuiI18n values prop, so this solution will not work, as it gives applications no way to manipulate the text.

I will go back and take a look at this again.

@chandlerprall
Copy link
Contributor

chandlerprall commented Aug 19, 2021

I missed mentioning that the token's default can be a function and hold that extra logic. Something like:

const button = useEuiI18n('euiColumnSorting.button', 'Sort fields');
const buttonActive = useEuiI18n(
  'euiColumnSorting.buttonActive',
  ({ numberOfSortedFields }) => `${numberOfSortedFields} field${numberOfSortedFields === 1 ? '' : 's'} sorted`,
  { numberOfSortedFields }
);

...

        <EuiButtonEmpty
          size="xs"
          iconType="sortable"
          color="text"
          className={controlBtnClasses}
          data-test-subj="dataGridColumnSortingButton"
          onClick={() => setIsOpen(!isOpen)}>
          {numberOfSortedFields > 0 ? buttonActive : button}
        </EuiButtonEmpty>

Which keeps all of the token definitions in the localization system, and ensures numberOfSortedFields is available to any token overrides provided by the application

@babs20
Copy link
Contributor Author

babs20 commented Aug 19, 2021

I missed mentioning that the token's default can be a function and hold that extra logic.

Ahhh, I got it now. Thanks for the clarification!

@cchaos cchaos requested a review from chandlerprall August 23, 2021 15:10
@cee-chen
Copy link
Member

@cchaos Thanks a million for getting the merge upstream on this PR! 🙏

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Changes LGTM, will merge when CI passes

Thanks for the fix & unit test @babs20 !

@chandlerprall
Copy link
Contributor

jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5043/

@chandlerprall chandlerprall merged commit 9229b92 into elastic:master Aug 23, 2021
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5043/

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.

[Data Grid] Pluralization of sort button
6 participants