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

Fixed the VmDisks sort so bootable disks sort first on the VmDetail page #547

Merged
merged 3 commits into from
Apr 6, 2018

Conversation

sjd78
Copy link
Member

@sjd78 sjd78 commented Mar 29, 2018

Resolves issue #511


This change is Reviewable

Copy link
Contributor

@jniederm jniederm left a comment

Choose a reason for hiding this comment

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

otherwise LGTM


return aBoot && !bBoot ? -1
: !aBoot && bBoot ? 1
: a.get('name').localeCompare(b.get('name'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please use number aware sorting:

const b = ['r', 'ř10', 'ř9', 'ř']
b.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
// b is Array [ "r", "ř", "ř9", "ř10" ]

Copy link
Member Author

Choose a reason for hiding this comment

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

Excellent point. I've added that and some tests so it's a bit more obvious what is intended.

@sjd78
Copy link
Member Author

sjd78 commented Apr 5, 2018

I moved the disk sort out to its own file to keep the component simple. Adding in explicit locales to the compare is easier to see in the utils.js. The test make it explicit what we are expecting the sort to look like on screen.

package.json got a tweak to fix a jest complaint.

import { locale as appLocale, DEFAULT_LOCALE } from '../../intl'

function localeCompare (a, b, locale = appLocale) {
return a.localeCompare(b, [ locale, DEFAULT_LOCALE ], { numeric: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

[ locale, DEFAULT_LOCALE ]

IIUIC this is already done at

export const locale: string = getLocaleFromUrl() || getBrowserLocale() || DEFAULT_LOCALE
- locale from intl should always provide valid locale string. So using DEFAULT_LOCALE and exporting it seems redundant.

Copy link
Member Author

@sjd78 sjd78 Apr 5, 2018

Choose a reason for hiding this comment

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

I did notice that locale coming from intl.js will fallback to DEFAULT_LOCALE. However, the sort function accepts a locale as a parameter, primarily for testing purposes. When the locale passed in isn't correct, and there isn't a fallback given the behavior is inconsistent across browsers.

In short, it is there to protect against edge cases if the function is ever used elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

  • There is no test for invalid locale code so reproducibility of test isn't in risk.
  • Current production code won't provide wrong locale code.
  • Inconsistent sorting in case of potential future usage and wrong language code isn't much of an issue.

... which makes me find the second item of locales array redundant.

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 did a bit more reading and it is redundant and doesn't protect against bad locales passed in via function argument. I'm ok with letting the locale functions throw the errors if the locale isn't correct. I'll adjust accordingly.

Sorry for my confusion, it's been awhile since I dealt with the ECMA Intl APIs.

@@ -117,7 +117,9 @@
"^.+\\.css$": "<rootDir>/config/jest/CSSStub.js",
"ovirtapi": "<rootDir>/src/mock/ovirtapi.mock.js"
},
"scriptPreprocessor": "<rootDir>/config/jest/transform.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not able to find doc for scriptPreprocessor property. What is the motivation for this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is exactly why I changed it. scriptPreprocessor was migrated to transform. When I ran the tests, jest reported the change. It is talked about a bit here [1].

screenshot from 2018-04-05 09-59-19

[1] - jestjs/jest#1468 (comment)

Copy link
Contributor

@jniederm jniederm left a comment

Choose a reason for hiding this comment

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

LGTM, optional minor comments


{
testTitle: 'name with number',
locale: 'cs',
Copy link
Contributor

Choose a reason for hiding this comment

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

Note, action not required


['r', 'ř10', 'ř9', 'ř'].sort((a, b) => a.localeCompare(b, 'cs', { numeric: true }))
['r', 'ř10', 'ř9', 'ř'].sort((a, b) => a.localeCompare(b, 'en', { numeric: true }))

both returns the same result Array [ "r", "ř", "ř9", "ř10" ]. So this isn't actually testing that other sorting algorithm is used. The distiguishing difference might be the fact that Czech language consider sequence 'ch' as one char that is sorted between 'h' and 'i':

['cecil', 'chris', 'david', 'harry'].sort((a, b) => a.localeCompare(b, 'cs', { numeric: true }))
// Array [ "cecil", "david", "harry", "chris" ]
['cecil', 'chris', 'david', 'harry'].sort((a, b) => a.localeCompare(b, 'en', { numeric: true }))
// Array [ "cecil", "chris", "david", "harry" ]

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the language lesson! I'll adjust the tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh fun. The normal build of nodejs, at least for node 8 and newer, appears to enable the Intl API but only includes English (en). There is a way to include the full locale support. I'll update package.json to do that, however that will also require updating ovirt-engine-nodejs-modules for full CI and build support.

import { locale as appLocale, DEFAULT_LOCALE } from '../../intl'

function localeCompare (a, b, locale = appLocale) {
return a.localeCompare(b, [ locale, DEFAULT_LOCALE ], { numeric: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

  • There is no test for invalid locale code so reproducibility of test isn't in risk.
  • Current production code won't provide wrong locale code.
  • Inconsistent sorting in case of potential future usage and wrong language code isn't much of an issue.

... which makes me find the second item of locales array redundant.

Add full-icu to devDependencies to enable testing in multiple locales.
@sjd78
Copy link
Member Author

sjd78 commented Apr 5, 2018

How are new libraries/version handled in ovirt-web-ui? I added full-icu to enable jest to use locales other then 'en' in tests. I see CI passed, but will rpm packaging fail since ovirt-engine-nodejs-modules won't have full-icu available yet?

@mareklibra
Copy link
Contributor

@sjd78 , ovirt-engine-nodejs-modules needs to be rebuilt to take effect.
Don't worry about it now, it's one-time action before ovirt-web-ui release.

@mareklibra mareklibra merged commit 59d9f49 into oVirt:master Apr 6, 2018
@sjd78 sjd78 deleted the issue511 branch April 6, 2018 14:10
mareklibra added a commit that referenced this pull request Apr 9, 2018
Introduced by: #547
Breaks recent offline-build by using runtime-determined npm dependencies.

The npm package "full-icu" does post-installation setup consisting of downloading "icu4c-data"
_in a version corresponding to running nodejs_ which is determined at runtime.

Can be fixed by either including all potential icu4c-data versions in ovirt-engine-nodejs-modules
or using clean full-icu npm dependency mechanism.
mareklibra added a commit that referenced this pull request Apr 9, 2018
Introduced by: #547
Breaks recent offline-build by using runtime-determined npm dependencies.

The npm package "full-icu" does post-installation setup consisting of downloading "icu4c-data"
_in a version corresponding to running nodejs_ which is determined at runtime.

Can be fixed by either including all potential icu4c-data versions in ovirt-engine-nodejs-modules
or using clean full-icu npm dependency mechanism.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants