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

[RFC][UN-14114] Add groups to uni select #260

Merged
merged 2 commits into from
Aug 29, 2018

Conversation

carantunes
Copy link
Contributor

@carantunes carantunes commented Aug 27, 2018

@carantunes carantunes force-pushed the UN-14114/add-groups-to-uni-select branch 11 times, most recently from 5b2bb7c to 2cc8435 Compare August 29, 2018 09:56
@carantunes carantunes force-pushed the UN-14114/add-groups-to-uni-select branch from 2cc8435 to 5be7d81 Compare August 29, 2018 10:03
@carantunes carantunes changed the title [WIP][UN-14114] Add groups to uni select [RFC][UN-14114] Add groups to uni select Aug 29, 2018
Copy link
Contributor

@AndreJoaquim AndreJoaquim left a comment

Choose a reason for hiding this comment

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

After already talking with @carantunes, I don't think that this is not the best solution for this problem. I think that it's not good to be able to have two separate APIs for the same component -- groups vs. options.

One of the problems is the following: what will happen when someone invokes {{uni-select groups=groups options=options}}?

Also, this solution doesn't allow to create a uni-select with groups and regular options under the same <select>.

My suggestion, and the one I believe is the most correct solution, is having an optional field inside the option object passed to the uni-select component:

const selectOptions: [{
    label: ‘this is a group’,
    options: [] // If it has options, it'll behave as a group
  },
  {
    label: 'this is a regular option'
  }
]

and invoking the component as we already do:

{{uni-select options=selectOptions}}

This will lead to:

  • Not having possible conflict situations: groups and options parameters both being passed
  • Keeping the same API: when we want to add groups to already existent uni-select, it's adding the options array
  • Allowing optgroups and options to co-exist

placeholder: null,
useAlias: false,
aliasValue: null,
groups: [],

hasGroups: computed('groups', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use computed.gt('groups.length', 0)

@carantunes
Copy link
Contributor Author

I don't think its a good behaviour to have both options alone and groups in the same select. Its confusing to select an option without group, and not being able to select a group.

Having that said and as this is an improvement to the code and as there's no other select with groups in the works, i suggest creating a ticket for the frontend guild and i can tackle it in the next sprint.

@carantunes carantunes requested a review from mmelo August 29, 2018 11:03
Copy link
Contributor

@henrmota henrmota left a comment

Choose a reason for hiding this comment

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

🔝

}
},

actions: {
changeSelected({ target }) {
if (this.get('useAlias')) {
this._changeAliasValue(target.value);
let group = this.get('hasGroups') ? target.options[target.selectedIndex].parentNode.getAttribute('key') : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

this has more than 120 chars?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly 120 😆

_changeAliasValue(key) {
let option = A(this.get('options')).findBy('key', key);
_changeAliasValue(key, group = null) {
let options = this.get('options');
Copy link
Contributor

Choose a reason for hiding this comment

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

let options = group ? A(this.get('groups')).findBy('key', group).options : this.get('options');

@AndreJoaquim AndreJoaquim merged commit 69e1876 into master Aug 29, 2018
@AndreJoaquim AndreJoaquim deleted the UN-14114/add-groups-to-uni-select branch August 29, 2018 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants