Skip to content

Commit

Permalink
Unfilter OS dropdown in VM wizard when choosing flavor or workload
Browse files Browse the repository at this point in the history
When switching OS, the flavor or the workload values will be set to NULL
if there is no common-template that respects the new OS with one of them.

Signed-off-by: Ido Rosenzwig <irosenzw@redhat.com>
  • Loading branch information
irosenzw committed Aug 17, 2020
1 parent bfb5f0c commit bd5790a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
Expand Up @@ -159,9 +159,67 @@ const osUpdater = ({ id, prevState, dispatch, getState }: UpdateOptions) => {
vmWizardInternalActions[InternalActionType.UpdateVmSettingsField](
id,
VMSettingsField.MOUNT_WINDOWS_GUEST_TOOLS,
{ isHidden: asHidden(!isWindows, VMSettingsField.OPERATING_SYSTEM), value: isWindows },
{
isHidden: asHidden(!isWindows, VMSettingsField.OPERATING_SYSTEM),
value: isWindows,
},
),
);

const relevantOptions = iGetRelevantTemplateSelectors(state, id);
const iCommonTemplates = iGetLoadedCommonData(state, id, VMWizardProps.commonTemplates);
const iTemplate =
iCommonTemplates && iGetRelevantTemplate(null, iCommonTemplates, relevantOptions);

if (os && !iTemplate) {
const keepFlavor = Object.assign({}, relevantOptions);
Object.assign(keepFlavor, { workload: null });
// Check for a valid common-template that contain the chosen Flavor
if (iGetRelevantTemplate(null, iCommonTemplates, keepFlavor)) {
dispatch(
vmWizardInternalActions[InternalActionType.UpdateVmSettingsField](
id,
VMSettingsField.WORKLOAD_PROFILE,
{ value: null },
),
);
} else {
const keepWorkload = Object.assign({}, relevantOptions);
Object.assign(keepWorkload, { flavor: null });
// Check for a valid common-template that contain the chosen Workload
if (iGetRelevantTemplate(null, iCommonTemplates, keepWorkload)) {
dispatch(
vmWizardInternalActions[InternalActionType.UpdateVmSettings](id, {
[VMSettingsField.FLAVOR]: { value: null },
[VMSettingsField.MEMORY]: {
isHidden: asHidden(true, VMSettingsField.FLAVOR),
isRequired: asRequired(false, VMSettingsField.FLAVOR),
},
[VMSettingsField.CPU]: {
isHidden: asHidden(true, VMSettingsField.FLAVOR),
isRequired: asRequired(false, VMSettingsField.FLAVOR),
},
}),
);
} else {
// Reset both Workload and Flavor as no valid common-template has been found
dispatch(
vmWizardInternalActions[InternalActionType.UpdateVmSettings](id, {
[VMSettingsField.WORKLOAD_PROFILE]: { value: null },
[VMSettingsField.FLAVOR]: { value: null },
[VMSettingsField.MEMORY]: {
isHidden: asHidden(true, VMSettingsField.FLAVOR),
isRequired: asRequired(false, VMSettingsField.FLAVOR),
},
[VMSettingsField.CPU]: {
isHidden: asHidden(true, VMSettingsField.FLAVOR),
isRequired: asRequired(false, VMSettingsField.FLAVOR),
},
}),
);
}
}
}
};

const baseImageUpdater = ({ id, prevState, dispatch, getState }: UpdateOptions) => {
Expand Down
Expand Up @@ -81,7 +81,7 @@ export const OSFlavor: React.FC<OSFlavorProps> = React.memo(
operatingSystems = [{ name: display, id: display }];
} else {
operatingSystems = openshiftFlag
? ignoreCaseSort(getOperatingSystems(vanillaTemplates, params), ['name'])
? ignoreCaseSort(getOperatingSystems(vanillaTemplates, params.userTemplate), ['name'])
: operatingSystemsNative;
}

Expand Down
Expand Up @@ -34,22 +34,13 @@ export const getFlavorLabel = (flavor: string) => {
return undefined;
};

export const getOperatingSystems = (
templates: TemplateKind[],
{ workload, flavor, userTemplate }: { workload: string; flavor: string; userTemplate: string },
) => {
let templatesWithLabels;
export const getOperatingSystems = (templates: TemplateKind[], userTemplate: string) => {
if (userTemplate) {
templatesWithLabels = [
return getTemplateOperatingSystems([
getTemplatesOfLabelType(templates, TEMPLATE_TYPE_VM).find((t) => getName(t) === userTemplate),
];
} else {
templatesWithLabels = getTemplatesWithLabels(
getTemplatesOfLabelType(templates, TEMPLATE_TYPE_BASE),
[getWorkloadLabel(workload), getFlavorLabel(flavor)],
);
]);
}
return getTemplateOperatingSystems(templatesWithLabels);
return getTemplateOperatingSystems(getTemplatesOfLabelType(templates, TEMPLATE_TYPE_BASE));
};

export const getWorkloadProfiles = (
Expand Down

0 comments on commit bd5790a

Please sign in to comment.