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

WB-483: Add custom labels to MultiSelect #659

Merged
merged 19 commits into from Dec 18, 2019
Merged

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Dec 17, 2019

Summary

MultiSelect

Added the labels prop to the MultiSelect component that allows us to pass a set of custom labels to the component.

dropdown-translated

This is the set of keys allowed by the component:

labels={
    clearSearch: string,
    filter: string,
    noResults: string,
    selectAllLabel: (numOptions: number) => string,
    selectNoneLabel: string,
    noneSelected: string,
    someSelected: (numSelectedValues: number) => string,
    allSelected: string,
}

Test plan

  1. Run tests: yarn test.
  2. Open the example that uses a set of translated strings: http://localhost:6060/#!/MultiSelect/21.

cc @annr

@jandrade jandrade requested review from jangmi-jo and a team December 17, 2019 14:02
*/
selectItemType: string,
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm deprecating these two props in favor of labels.

@@ -184,6 +225,8 @@ export default class MultiSelect extends React.Component<Props, State> {
searchText: "",
lastSelectedValues: [],
};
// merge custom labels with the default ones
this.labels = {...defaultLabels, ...props.labels};
Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up creating this labels instance variable to merge the custom labels with the default labels defined in constants.js.

Copy link
Member

Choose a reason for hiding this comment

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

Will this update if the props change later on?

Copy link
Member Author

Choose a reason for hiding this comment

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

mmm It won't. I'll make the pertinent changes.

@codecov
Copy link

codecov bot commented Dec 17, 2019

Codecov Report

Merging #659 into master will increase coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #659      +/-   ##
==========================================
+ Coverage   95.48%   95.64%   +0.16%     
==========================================
  Files         135      134       -1     
  Lines        2260     2275      +15     
  Branches      425      428       +3     
==========================================
+ Hits         2158     2176      +18     
+ Misses         96       93       -3     
  Partials        6        6
Impacted Files Coverage Δ
...wonder-blocks-dropdown/components/single-select.js 100% <ø> (ø) ⬆️
packages/wonder-blocks-dropdown/util/constants.js 100% <100%> (ø) ⬆️
...wonder-blocks-dropdown/components/dropdown-core.js 99.45% <100%> (ø) ⬆️
...nder-blocks-dropdown/components/dropdown-opener.js 100% <100%> (ø) ⬆️
...s/wonder-blocks-dropdown/components/action-menu.js 100% <100%> (ø) ⬆️
.../wonder-blocks-dropdown/components/multi-select.js 96.7% <100%> (+0.27%) ⬆️
...er-blocks-dropdown/components/search-text-input.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fff8f4...0f63c8c. Read the comment docs.

@@ -34,3 +34,15 @@ export const SEPARATOR_ITEM_HEIGHT = 9;

export const SEARCH_ITEM_HEIGHT =
DROPDOWN_ITEM_HEIGHT + searchInputStyle.margin + searchInputStyle.marginTop;

// The default labels that will be used by different components
export const defaultLabels = {
Copy link
Member Author

Choose a reason for hiding this comment

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

Now all the default labels are centralized in this file.

Copy link
Member

Choose a reason for hiding this comment

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

Very nice!

@jandrade jandrade changed the title WB-483: Add translated labels to MultiSelect WB-483: Add custom labels to MultiSelect Dec 17, 2019
Copy link
Member

@jeresig jeresig left a comment

Choose a reason for hiding this comment

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

Excellent, thank you! A few questions inline.

* When this is true, the menu text shows "All {selectItemType}" when no
* item is selected.
* When this is true, the menu text shows "All items" when no item is
* selected.
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth mentioning which label this is, as well

@@ -184,6 +225,8 @@ export default class MultiSelect extends React.Component<Props, State> {
searchText: "",
lastSelectedValues: [],
};
// merge custom labels with the default ones
this.labels = {...defaultLabels, ...props.labels};
Copy link
Member

Choose a reason for hiding this comment

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

Will this update if the props change later on?

packages/wonder-blocks-dropdown/components/multi-select.js Outdated Show resolved Hide resolved
clearSearch: defaultLabels.clearSearch,
filter: defaultLabels.filter,
},
};
Copy link
Member

Choose a reason for hiding this comment

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

I notice you're not doing this this.labels here, any reason?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this component is only accessed by MultiSelect and we are doing the corresponding this.labels check in that component. In this case, we have two options:

  • No custom labels set: It will use the values from defaultValues.
  • Custom labels set: It will override the values of this.props.labels with the values passed from MultiSelect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Disregard my previous comment. We still need to sync the labels sent by the parent component, so I might to reuse the same logic to get the current labels from MultiSelect.

@@ -34,3 +34,15 @@ export const SEPARATOR_ITEM_HEIGHT = 9;

export const SEARCH_ITEM_HEIGHT =
DROPDOWN_ITEM_HEIGHT + searchInputStyle.margin + searchInputStyle.marginTop;

// The default labels that will be used by different components
export const defaultLabels = {
Copy link
Member

Choose a reason for hiding this comment

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

Very nice!

@jandrade jandrade changed the base branch from dropdown/remove-dropdown to master December 18, 2019 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants