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
Conversation
There was a problem hiding this 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(); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
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 :).
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Released in 1.1.7 (master only) |
Updated support for sorting of drop downs (cherry picked from commit fa8af25)
Backported to
|
Awesome! Thanks @chalettu @eclarizio @himdel |
Released in 1.0.16 (gaprindashvili) |
@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