Skip to content

Fix/picker get label #1059

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

Merged
merged 3 commits into from
Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions src/components/picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,9 @@ class Picker extends PureComponent {
};
};

shouldNotChangePickerLabelWhileSelecting = () => {
const {mode} = this.props;
return mode === Picker.modes.MULTI;
};

getLabelValueText = () => {
const {value: propsValue} = this.props;
const {value: stateValue} = this.props;

if (this.shouldNotChangePickerLabelWhileSelecting()) {
return this.getLabel(propsValue);
}
return this.getLabel(stateValue);
const {value} = this.props;
return this.getLabel(value);
};
Comment on lines 230 to 233
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that now getLabelValueText is redundant..
it's just a wrapper of this.getLabel.
Can we remove it?

Copy link
Contributor Author

@mendyEdri mendyEdri Dec 7, 2020

Choose a reason for hiding this comment

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

Right, It's just since there are value deconstruction that needs to be repeated for a few times in this class, maybe it's still valid?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it was valid before when you had some logic there..
But now we use it only in one place and all it does it extract the value prop. Which seems a little redundant, no?


getLabelsFromArray = value => {
Expand All @@ -256,14 +246,14 @@ class Picker extends PureComponent {
getLabel(value) {
const {getLabel} = this.props;

if (_.isFunction(getLabel) && !_.isUndefined(getLabel(value))) {
return getLabel(value);
}

if (_.isArray(value)) {
return this.getLabelsFromArray(value);
}

if (_.isFunction(getLabel)) {
return getLabel(value);
}

if (_.isPlainObject(value)) {
return _.get(value, 'label');
}
Expand Down