Skip to content

Commit

Permalink
Review tab - Move getFlavorText and refactor getFlavorValue
Browse files Browse the repository at this point in the history
  • Loading branch information
pcbailey committed Apr 17, 2020
1 parent 4c7e102 commit 4756db0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { FormFieldType } from '../../form/form-field';
import { getBooleanReadableValue } from '../../../../utils/strings';
import { iGetFieldValue } from '../../selectors/immutable/field';
import { VMSettingsField } from '../../types';
import {iGet, iGetIn, toShallowJS} from '../../../../utils/immutable';
import { iGet, iGetIn, toShallowJS } from '../../../../utils/immutable';
import { CUSTOM_FLAVOR } from '../../../../constants/vm';
import { iGetRelevantTemplate } from '../../../../selectors/immutable/template/combined';
import { VMTemplateWrapper } from '../../../../k8s/wrapper/vm/vm-template-wrapper';
import { Map as ImmutableMap } from 'immutable';
import { ITemplate } from '../../../../types/template';
import { getFlavorText } from '../../../../selectors/vm/flavor-text';

export const getReviewValue = (field: any, fieldType: FormFieldType) => {
const value = iGetFieldValue(field);
Expand All @@ -19,7 +20,8 @@ export const getReviewValue = (field: any, fieldType: FormFieldType) => {

export const getField = (key: VMSettingsField, vmSettings) => iGet(vmSettings, key);

export const getFieldValue = (vmSettings, key: VMSettingsField) => iGetIn(vmSettings, [key, 'value']);
export const getFieldValue = (vmSettings, key: VMSettingsField) =>
iGetIn(vmSettings, [key, 'value']);

export const getFlavorValue = ({
iVMSettings,
Expand All @@ -28,22 +30,22 @@ export const getFlavorValue = ({
relevantOptions,
}: GetFlavorValueParams) => {
const flavor = getFieldValue(iVMSettings, VMSettingsField.FLAVOR);
let cpuCores, memory;
let cpu, memory;

if (flavor === CUSTOM_FLAVOR) {
cpuCores = getFieldValue(iVMSettings, VMSettingsField.CPU);
cpu = getFieldValue(iVMSettings, VMSettingsField.CPU);
memory = getFieldValue(iVMSettings, VMSettingsField.MEMORY);
} else {
const template_ = toShallowJS(
iGetRelevantTemplate(iUserTemplates, iCommonTemplates, relevantOptions),
);
const template = new VMTemplateWrapper(template_, true).init().clearRuntimeMetadata();

cpuCores = template.getCPU()?.cores;
cpu = template.getCPU();
memory = template.getMemory();
}

return `${flavor}: ${cpuCores} CPU, ${memory}`;
return getFlavorText({ cpu, memory, flavor });
};

type GetFlavorValueParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '../../selectors/vm/selectors';
import { getTemplateOperatingSystems } from '../../selectors/vm-template/advanced';
import { vmFlavorModal } from '../modals';
import { getFlavorText } from '../flavor-text';
import { EditButton } from '../edit-button';
import { VMDetailsItem } from '../vms/vm-resource';
import { DiskSummary } from '../vm-disks/disk-summary';
Expand All @@ -40,6 +39,7 @@ import {
AFFINITY_MODAL_TITLE,
} from '../modals/scheduling-modals/shared/consts';
import './_vm-template-resource.scss';
import { getFlavorText } from '../../selectors/vm/flavor-text';

export const VMTemplateResourceSummary: React.FC<VMTemplateResourceSummaryProps> = ({
template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import affinityModal from '../modals/scheduling-modals/affinity-modal/connected-
import { getRowsDataFromAffinity } from '../modals/scheduling-modals/affinity-modal/helpers';
import VMStatusModal from '../modals/vm-status-modal/vm-status-modal';
import { getDescription } from '../../selectors/selectors';
import { getFlavorText } from '../flavor-text';
import { EditButton } from '../edit-button';
import { VMStatuses } from '../vm-status';
import { DiskSummary } from '../vm-disks/disk-summary';
Expand All @@ -30,6 +29,7 @@ import { VirtualMachineInstanceModel, VirtualMachineModel } from '../../models';
import { asVMILikeWrapper } from '../../k8s/wrapper/utils/convert';
import { getVMTemplate } from '../../selectors/vm-template/selectors';
import { VMImportKind } from '../../types/vm-import/ovirt/vm-import';
import { getFlavorText } from '../../selectors/vm/flavor-text';
import {
NODE_SELECTOR_MODAL_TITLE,
DEDICATED_RESOURCES_PINNED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import { CPURaw } from '../../types/vm';
import { vCPUCount } from './cpu';
import { convertToBaseValue, humanizeBinaryBytes } from '@console/internal/components/utils';
import { vCPUCount } from '../selectors/vm';
import { CPURaw } from '../types/vm';
import * as _ from 'lodash';

export const getFlavorText = ({
cpu,
Expand Down

0 comments on commit 4756db0

Please sign in to comment.