Skip to content

Commit

Permalink
nitpicks from openshift#3839
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Jan 7, 2020
1 parent 0f1578c commit 4f3e112
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '../../../selectors/immutable/vm-settings';
import { iGetLoadedCommonData, iGetName } from '../../../selectors/immutable/selectors';
import { VMSettingsField, VMWizardProps, VMSettingsRenderableField } from '../../../types';
import { iGetIn } from '../../../../../utils/immutable';
import { CommonTemplatesValidation } from './validation-types';
import { getValidationsFromTemplates, getFieldValidations } from './selectors';

Expand All @@ -29,14 +28,6 @@ export const getTemplateValidations = (
const { getState, id } = options;
const state = getState();

// Get OS, workload-profile and flavor attributes
const os = iGetVmSettingAttribute(state, id, VMSettingsField.OPERATING_SYSTEM);
const flavor = iGetVmSettingAttribute(state, id, VMSettingsField.FLAVOR);
const workloadProfile = iGetVmSettingAttribute(state, id, VMSettingsField.WORKLOAD_PROFILE);

// Get all the templates from common-templates
const commonTemplates = iGetLoadedCommonData(state, id, VMWizardProps.commonTemplates);

// Get userTemplate if it was chosen
const userTemplateName = iGetVmSettingValue(state, id, VMSettingsField.USER_TEMPLATE);
const iUserTemplates = iGetLoadedCommonData(state, id, VMWizardProps.userTemplates);
Expand All @@ -45,15 +36,24 @@ export const getTemplateValidations = (
? iUserTemplates.find((template) => iGetName(template) === userTemplateName)
: null;

if (iUserTemplate) {
const validations = getValidationsFromTemplates([iUserTemplate]);
return getFieldValidations(validations, IDToJsonPath[fieldId]);
}

// Get OS, workload-profile and flavor attributes
const os = iGetVmSettingAttribute(state, id, VMSettingsField.OPERATING_SYSTEM);
const flavor = iGetVmSettingAttribute(state, id, VMSettingsField.FLAVOR);
const workloadProfile = iGetVmSettingAttribute(state, id, VMSettingsField.WORKLOAD_PROFILE);

// Get all the templates from common-templates
const commonTemplates = iGetLoadedCommonData(state, id, VMWizardProps.commonTemplates);

// Get all the validations from the relevant templates:
// Get the validations from the user template, if chosen.
// If not, get the validations from Common-Templates based on OS, Workload-Profile and Flavor
const validations = iUserTemplate
? JSON.parse(iGetIn(iUserTemplate, ['metadata', 'annotations', 'validations']))
: getValidationsFromTemplates(
// Get templates based on OS, Workload-Profile and Flavor
getRelevantTemplates(commonTemplates, os, workloadProfile, flavor),
);
const templates = getRelevantTemplates(commonTemplates, os, workloadProfile, flavor);
const validations = getValidationsFromTemplates(templates);

// Return all the validations which are relevant for the field
return getFieldValidations(validations, IDToJsonPath[fieldId]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const getRelevantTemplates = (
workloadProfile: string,
flavor: string,
) => {
if (!commonTemplates || commonTemplates.length === 0 || !os || !workloadProfile) {
if (!commonTemplates || commonTemplates.length === 0) {
return [];
}
return (commonTemplates || []).filter(
Expand Down

0 comments on commit 4f3e112

Please sign in to comment.