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

Updated support for sorting of drop downs #265

Merged
merged 5 commits into from Feb 21, 2018

Conversation

chalettu
Copy link
Contributor

@chalettu chalettu commented Feb 20, 2018

@miq-bot add_label bug
@miq-bot add_label gaprindashvili/yes
This PR also addresses an issue where "None" option should default to staying at the top of a dropdown list of options.
Fix for BZ https://bugzilla.redhat.com/show_bug.cgi?id=1531677

@chalettu
Copy link
Contributor Author

Screenshot of Drop down sorted in descending order with Int selected as value type
sortdesc

@chalettu
Copy link
Contributor Author

Screenshot of Dropdown sorted Asc with value set to Int and sorting on description field.
sortasc

@chalettu
Copy link
Contributor Author

Screenshot of a dropdown thats values are a string and sorted by description. Notice the None staying on top
stringsortasc

@chalettu
Copy link
Contributor Author

Screenshot of radio button groups sorted desc and asc.
radio

@chessbyte chessbyte changed the title BZ#1531677 - Updated support for sorting of drop downs Updated support for sorting of drop downs Feb 20, 2018
Copy link
Member

@eclarizio eclarizio left a comment

Choose a reason for hiding this comment

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

Can you add more to the existing specs to include the case that the BZ was running into? (something like 1, 2, 11, since the "11" was the one throwing off the sorting).

Other than that and one smaller nitpick, I think we're good to go.

defaultDropdownField = tempValues.shift();
} else if(_.isNull(tempValues[FIRST_OPTION][VALUE])) {
defaultDropdownField = tempValues.shift();
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we just combine this else if and the if with an || since both lines 58 and 60 do the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that when i reviewed my own code. I think I will try that but will put the or on a separate line

dropDownValues.push(option);
}
const value = (field.data_type === 'integer' ? parseInt(option[0], 10) : option[0]);
const description = (parseInt(option[1], 10) ? parseInt(option[1], 10) : option[1]);
Copy link
Contributor

@himdel himdel Feb 21, 2018

Choose a reason for hiding this comment

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

Is this description used only for sorting?

Because if not, this breaks on any description which starts with a number. "3 horses" will become just 3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Description is only used for sorting the drop down list.

Copy link
Contributor

@himdel himdel Feb 21, 2018

Choose a reason for hiding this comment

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

Oh.. and maybe an _.isNaN?

Otherwise 0 will still get sorted last.. (because parseInt("0", 10) is 0 => falsy)

EDIT: you can also use Number.isNaN if you don't like lodash, it is shimmed by es6-shim so no browser compatibility issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ha, you beat me to it. I just added isNan in just now.

it('should allow a numeric Description field to be sorted in a dropdown', () => {
const testDropDownDescription = {
values: [
[0, '0'],
Copy link
Contributor

@himdel himdel Feb 21, 2018

Choose a reason for hiding this comment

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

Also, can you change the keys and values to something different (from each other)?

It is impossible to tell from this spec if this really works or if it just sorts by value instead :).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, and also without an 11 or something like that, it doesn't actually tell us if those are sorted as numbers or as strings..

Copy link
Member

Choose a reason for hiding this comment

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

Also, we need to set the data.data_type to integer which is part of the original problem that javascript was sorting 1, 11, and 2 as if they were strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually that wasn't the problem this PR addresses. This deals with a use case where a user would decide to actually use numbers in the description field and then decide they want to sort the dropdown by the description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eclarizio , I went ahead and updated one of the test cases to actually specify the data type. It wasn't directly related to this test but I added it in for clarity sake.

@miq-bot
Copy link
Member

miq-bot commented Feb 21, 2018

Checked commits chalettu/ui-components@6d6663d~...0873a72 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
0 files checked, 0 offenses detected
Everything looks fine. 👍

Copy link
Member

@eclarizio eclarizio left a comment

Choose a reason for hiding this comment

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

👍

@himdel himdel merged commit fa8af25 into ManageIQ:master Feb 21, 2018
@himdel himdel added this to the Sprint 80 Ending Feb 26, 2018 milestone Feb 21, 2018
@himdel
Copy link
Contributor

himdel commented Feb 21, 2018

Released in 1.1.7 (master only)

himdel added a commit that referenced this pull request Feb 21, 2018
Updated support for sorting of drop downs

(cherry picked from commit fa8af25)
@himdel
Copy link
Contributor

himdel commented Feb 21, 2018

Backported to gaprindashvili:

commit b4dbb3407b4a7d64a02b6d38d4ec1f6333bc2889 (HEAD -> gaprindashvili, upstream/gaprindashvili)
Author: Martin Hradil <himdel@seznam.cz>
Date:   Wed Feb 21 18:07:03 2018 +0000

    Merge pull request #265 from chalettu/dialog-sorting-dropdowns
    
    Updated support for sorting of drop downs
    
    (cherry picked from commit fa8af254089eb5e6e9425a2fbfdcacdfe2886f67)

@JPrause
Copy link
Member

JPrause commented Feb 21, 2018

Awesome! Thanks @chalettu @eclarizio @himdel

@himdel
Copy link
Contributor

himdel commented Feb 21, 2018

Released in 1.0.16 (gaprindashvili)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants