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
Bug 1826234: Filter out duplicate OSes in the new VM wizard #4897
Bug 1826234: Filter out duplicate OSes in the new VM wizard #4897
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.
What does it mean, in the future? Shouldn't we commit this change after it is ready?
|
||
export const removeOSDups = (osArr: OperatingSystemArray): OperatingSystemArray => { | ||
const osNames: { [key: string]: string } = {}; | ||
osArr.forEach((os) => { |
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.
what happens when these OS are in different templates?
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.
@suomiy what do you mean?
we expect each record to be in the form: { name: "Fedora31", id: "someID" }.
Am I missing something ?
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.
if you have
template1:
{ name: "Fedora29+", id: "fedora29" }.
template2
{ name: "Fedora29+", id: "fedora31" }.
you will always choose template2 even though you should have chosen template1
* edited
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.
edited original comment
ah I see, I made a mistake - now it makes sense even with mutiple templates - we just choose the newer version one
and if the user wants his to be used he should change their own template to
template1:
{ name: "Fedora29", id: "fedora29" }.
const osNames: { [key: string]: string } = {}; | ||
osArr.forEach((os) => { | ||
if (osNames[os.name]) { | ||
osNames[os.name] = os.id > osNames[os.name] ? os.id : osNames[os.name]; |
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.
what happens when the comparison misbehaves? - shouldn't we test at least for numbers?
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 checked the comparison with several examples - they all went OK.
@suomiy can you think of a scenario that is would misbehave ?
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.
for example "ubuntu9.10" > "ubuntu10.04"
@@ -110,3 +110,8 @@ export type VMSettingsValidationConfig = { | |||
validator: VmSettingsValidator; | |||
}; | |||
}; | |||
|
|||
export type OperatingSystemArray = { |
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.
please do not create array types, also it should not be under wizard directory
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.
done.
: operatingSystemsNative; | ||
const operatingSystems = removeOSDups( | ||
openshiftFlag | ||
? ignoreCaseSort(getOperatingSystems(vanillaTemplates, params), ['name']) |
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 the only place we should worry about?
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.
@suomiy The template validations are working.
except the wizard, do you think on other places ?
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.
IMO this functionality should be implemented in the following function to be applied everywhere in the wizard (for example this is used in template prefil)
getTemplateOperatingSystems = (templates: TemplateKind[])
in selectors/vm-template/advanced.ts
@suomiy "in the future" means that the templates in common-templates project are being modified to minimize the Operating-Systems dropdown list by changing the os.template annotations as follows: instead of
have:
|
47dc686
to
0910c0b
Compare
osArr.forEach((os) => { | ||
if (osNames[os.name]) { | ||
osNames[os.name] = | ||
os.id.toLocaleLowerCase().localeCompare(osNames[os.name].toLocaleLowerCase()) >= 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.
better, but still not working
I see, that looks useful |
0910c0b
to
310272b
Compare
310272b
to
9c59c87
Compare
* return 0 when equal. | ||
* | ||
*/ | ||
const compareVersions = (osVersion1: number[], osVersion2: number[]): number => { |
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.
nice function! just few nitpicks
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.
a short test for this function would be also nice
* | ||
*/ | ||
const compareVersions = (osVersion1: number[], osVersion2: number[]): number => { | ||
if (!osVersion1 || !osVersion2) { |
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.
if (!osVersion1 || !osVersion2) { | |
if (!osVersion1 && !osVersion2) { |
should be 0 only in this case no?
otherwise the present one should be larger
export const operatingSystemsNative = [ | ||
import { OperatingSystemRecord } from '../../../types'; | ||
|
||
export const operatingSystemsNative: OperatingSystemRecord[] = [ |
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.
could you move this file to src/constants/vm-templates/os.ts
please?
osNames[os.name] = os.id; | ||
} | ||
}); | ||
return Object.keys(osNames).map((name) => { |
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.
this whole function would be more simpler and readable if we just used sort
and then _.sortedUniqBy
. It is much easier to add other conditions in the future
9c59c87
to
e209a29
Compare
@irosenzw: This pull request references Bugzilla bug 1826234, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker. 3 validation(s) were run on this bug
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/retest |
return 0; | ||
} | ||
|
||
if (!osVersion1) { |
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.
these two ifs should just fill osVersion with empty array - you don't know what will come in the other version.
It could be [0] or [null]
can you please add a test for that?
}; | ||
|
||
const descSortOSes = (os1: OperatingSystemRecord, os2: OperatingSystemRecord): number => { | ||
if (os1.name > os2.name) { |
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 we use localCompare for these two to be more accurate?
}; | ||
|
||
export const removeOSDups = (osArr: OperatingSystemRecord[]): OperatingSystemRecord[] => | ||
_.orderBy(_.uniqBy(osArr.sort(descSortOSes), 'name'), ['name']); |
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.
please can you remove orderBy? This is not the purpose of this function and is sorted by ignoreCaseSort
down the road
return compareVersions(getOSVersion(os1.id), getOSVersion(os2.id)) * -1; | ||
}; | ||
|
||
export const removeOSDups = (osArr: OperatingSystemRecord[]): OperatingSystemRecord[] => |
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.
could you add a small test for this function as well?
const getOSVersion = (osName: string): number[] => | ||
osName | ||
.split(/\D/) | ||
.filter((x) => x) |
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.
this should test if it is a number
this would mean that 2.1.0
== 2.0.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.
probably makes sense to do the map first
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.
@suomiy I think you are mistaken
2.1.0
will yield [2,1,0]
2.0.1
will yield [2,0,1]
The comparison afterwards will examine the two arrays by the value at the same index,
thus determine that 2.1.0
> 2.0.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.
yes, you are right
I forgot that these are strings and not numbers.
"0" == 0
// > true
!"0" == !0
// > false
}; | ||
|
||
export const removeOSDups = (osArr: OperatingSystemRecord[]): OperatingSystemRecord[] => | ||
_.orderBy(_.uniqBy(osArr.sort(descSortOSes), 'name'), ['name']); |
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.
_.orderBy(_.uniqBy(osArr.sort(descSortOSes), 'name'), ['name']); | |
_.orderBy(_.uniqBy([...osArr].sort(descSortOSes), 'name'), ['name']); |
better not to change the underlying array we don't own in this function
e209a29
to
c2e88e8
Compare
}; | ||
|
||
const descSortOSes = (os1: OperatingSystemRecord, os2: OperatingSystemRecord): number => { | ||
if (os1.name.localeCompare(os2.name) > 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.
can we remember result of this call and just check if it is not equal to 0 and return it?
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.
we need to return it multiplied by (-1), but yeah... totally make sense
return 0; | ||
} | ||
|
||
const osVer1 = osVersion1 || [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.
these can be just [] no?
@@ -46,3 +47,74 @@ export const ignoreCaseSort = <T>( | |||
}; | |||
return array.sort((a, b) => resolve(a).localeCompare(resolve(b))); | |||
}; | |||
|
|||
const getOSVersion = (osName: string): number[] => | |||
osName |
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.
osName | |
(osID || "") |
}; | ||
|
||
const descSortOSes = (os1: OperatingSystemRecord, os2: OperatingSystemRecord): number => { | ||
if (os1.name.localeCompare(os2.name) > 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.
if (os1.name.localeCompare(os2.name) > 0) { | |
if ((os1.name || "").localeCompare(os2.name) > 0) { |
}; | ||
|
||
export const removeOSDups = (osArr: OperatingSystemRecord[]): OperatingSystemRecord[] => | ||
_.uniqBy([...osArr].sort(descSortOSes), 'name'); |
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.
_.uniqBy([...osArr].sort(descSortOSes), 'name'); | |
_.uniqBy(osArr.filter(a => a).sort(descSortOSes), 'name'); |
I guess this makes it more useful and we get a new array as well
c2e88e8
to
b64207f
Compare
In the future, the common-templates will have more labels pointing to the same name annotation. Thus, filter the duplicate OSes names presented in the VM wizard Signed-off-by: Ido Rosenzwig <irosenzw@redhat.com>
b64207f
to
8a1212c
Compare
/bugzilla refresh |
@suomiy: This pull request references Bugzilla bug 1826234, which is valid. 3 validation(s) were run on this bug
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: irosenzw, suomiy The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@irosenzw: All pull requests linked via external trackers have merged: openshift/console#4897. Bugzilla bug 1826234 has been moved to the MODIFIED state. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
templates in
common-templates
have some labels pointing to the same name annotation.Thus, filter the duplicate OSes names presented in the VM wizard.
Signed-off-by: Ido Rosenzwig irosenzw@redhat.com