-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes 1871108: usability bug: the ui selections are unclear
- Loading branch information
Showing
20 changed files
with
683 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
.../packages/kubevirt-plugin/src/components/create-vm-wizard/tabs/vm-settings-tab/flavor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import * as _ from 'lodash'; | ||
import * as React from 'react'; | ||
import { SelectOption } from '@patternfly/react-core'; | ||
import { ValidationErrorType, asValidationObject } from '@console/shared/src/utils/validation'; | ||
import { | ||
iGetIsLoaded, | ||
iGetLoadedData, | ||
iGetLoadError, | ||
immutableListToShallowJS, | ||
toShallowJS, | ||
} from '../../../../utils/immutable'; | ||
import { FormFieldRow } from '../../form/form-field-row'; | ||
import { FormField, FormFieldType } from '../../form/form-field'; | ||
import { | ||
getFlavors, | ||
getWorkloadProfiles, | ||
} from '../../../../selectors/vm-template/combined-dependent'; | ||
import { flavorSort } from '../../../../utils/sort'; | ||
import { VMSettingsField } from '../../types'; | ||
import { iGetFieldValue } from '../../selectors/immutable/field'; | ||
import { nullOnEmptyChange } from '../../utils/utils'; | ||
import { FormPFSelect } from '../../../form/form-pf-select'; | ||
|
||
export const Flavor: React.FC<FlavorProps> = React.memo( | ||
({ | ||
iUserTemplate, | ||
commonTemplates, | ||
os, | ||
flavorField, | ||
workloadProfile, | ||
cnvBaseImages, | ||
onChange, | ||
openshiftFlag, | ||
}) => { | ||
const flavor = iGetFieldValue(flavorField); | ||
const isUserTemplateValid = iGetIsLoaded(iUserTemplate) && !iGetLoadError(iUserTemplate); | ||
|
||
const params = { | ||
flavor, | ||
workload: workloadProfile, | ||
os, | ||
}; | ||
|
||
const templates = iUserTemplate | ||
? isUserTemplateValid | ||
? [toShallowJS(iGetLoadedData(iUserTemplate))] | ||
: [] | ||
: immutableListToShallowJS(iGetLoadedData(commonTemplates)); | ||
|
||
const flavors = flavorSort(getFlavors(templates, params)); | ||
|
||
const workloadProfiles = getWorkloadProfiles(templates, params); | ||
|
||
const loadingResources = openshiftFlag | ||
? { | ||
commonTemplates, | ||
cnvBaseImages, | ||
} | ||
: {}; | ||
|
||
if (openshiftFlag && iUserTemplate) { | ||
Object.assign(loadingResources, { iUserTemplate }); | ||
} | ||
|
||
let flavorValidation; | ||
|
||
if ( | ||
iGetIsLoaded(commonTemplates) && | ||
(!iUserTemplate || isUserTemplateValid) && | ||
(flavors.length === 0 || workloadProfiles.length === 0) | ||
) { | ||
const validation = asValidationObject( | ||
'There is no valid template for this combination. Please install required template or select different os/flavor/workload profile combination.', | ||
ValidationErrorType.Info, | ||
); | ||
if (!flavorField.get('validation')) { | ||
flavorValidation = validation; | ||
} | ||
} | ||
|
||
return ( | ||
<FormFieldRow | ||
field={flavorField} | ||
fieldType={FormFieldType.PF_SELECT} | ||
validation={flavorValidation} | ||
loadingResources={loadingResources} | ||
> | ||
<FormField value={flavor} isDisabled={flavor && flavors.length === 1}> | ||
<FormPFSelect | ||
onSelect={(e, v) => nullOnEmptyChange(onChange, VMSettingsField.FLAVOR)(v.toString())} | ||
> | ||
{flavors.map((f) => { | ||
return ( | ||
<SelectOption key={f} value={f}> | ||
{_.capitalize(f)} | ||
</SelectOption> | ||
); | ||
})} | ||
</FormPFSelect> | ||
</FormField> | ||
</FormFieldRow> | ||
); | ||
}, | ||
); | ||
|
||
type FlavorProps = { | ||
iUserTemplate: any; | ||
commonTemplates: any; | ||
flavorField: any; | ||
os: string; | ||
workloadProfile: string; | ||
cnvBaseImages: any; | ||
openshiftFlag: boolean; | ||
onChange: (key: string, value: string | boolean) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.