-
Notifications
You must be signed in to change notification settings - Fork 667
kubevirt: VMWizard - redesign and import the first step (General) #2452
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
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
atiratree:kubevirt.createVMWizard
Sep 26, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
frontend/packages/kubevirt-plugin/src/components/create-vm-wizard/create-vm-wizard.scss
This file contains hidden or 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,21 @@ | ||
| .kubevirt-create-vm-modal__container { | ||
| height: 100%; | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| .kubevirt-create-vm-modal__wizard-content { | ||
| flex-flow: wrap | ||
| } | ||
|
|
||
| .pf-c-wizard__outer-wrap { | ||
| min-height: inherit; | ||
| } | ||
|
|
||
| .pf-c-wizard__nav { | ||
| z-index: calc(var(--pf-global--ZIndex--xs) + 1); | ||
| } | ||
|
|
||
| .pf-c-wizard__toggle { | ||
| z-index: calc(var(--pf-global--ZIndex--xs) + 2); | ||
| } |
330 changes: 330 additions & 0 deletions
330
frontend/packages/kubevirt-plugin/src/components/create-vm-wizard/create-vm-wizard.tsx
This file contains hidden or 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,330 @@ | ||
| import * as React from 'react'; | ||
| import * as _ from 'lodash'; | ||
| import { connect } from 'react-redux'; | ||
| import { createVm, createVmTemplate } from 'kubevirt-web-ui-components'; | ||
| import { Wizard } from '@patternfly/react-core'; | ||
| import { | ||
| PersistentVolumeClaimModel, | ||
| StorageClassModel, | ||
| TemplateModel, | ||
| } from '@console/internal/models'; | ||
| import { | ||
| Firehose, | ||
| history, | ||
| makeQuery, | ||
| makeReduxID, | ||
| units, | ||
| } from '@console/internal/components/utils'; | ||
| import { withReduxID } from '../../utils/redux/common'; | ||
| import { | ||
| DataVolumeModel, | ||
| NetworkAttachmentDefinitionModel, | ||
| VirtualMachineModel, | ||
| } from '../../models'; | ||
| import { TEMPLATE_TYPE_BASE, TEMPLATE_TYPE_LABEL, TEMPLATE_TYPE_VM } from '../../constants/vm'; | ||
| import { getResource } from '../../utils'; | ||
| import { EnhancedK8sMethods } from '../../k8s/enhancedK8sMethods/enhancedK8sMethods'; | ||
| import { | ||
| cleanupAndGetResults, | ||
| errorsFirstSort, | ||
| getResults, | ||
| } from '../../k8s/enhancedK8sMethods/k8sMethodsUtils'; | ||
| import { | ||
| concatImmutableLists, | ||
| iGetIn, | ||
| iGetLoadedData, | ||
| immutableListToShallowJS, | ||
| } from '../../utils/immutable'; | ||
| import { getTemplateOperatingSystems } from '../../selectors/vm-template/advanced'; | ||
| import { | ||
| ChangedCommonData, | ||
| CommonData, | ||
| CreateVMWizardComponentProps, | ||
| DetectCommonDataChanges, | ||
| VMSettingsField, | ||
| VMWizardProps, | ||
| VMWizardTab, | ||
| } from './types'; | ||
| import { | ||
| CREATE_VM, | ||
| CREATE_VM_TEMPLATE, | ||
| REVIEW_AND_CREATE, | ||
| TabTitleResolver, | ||
| } from './strings/strings'; | ||
| import { vmWizardActions } from './redux/actions'; | ||
| import { ActionType } from './redux/types'; | ||
| import { iGetCommonData, iGetCreateVMWizardTabs } from './selectors/immutable/selectors'; | ||
| import { isStepLocked, isStepValid } from './selectors/immutable/wizard-selectors'; | ||
| import { VMSettingsTab } from './tabs/vm-settings-tab/vm-settings-tab'; | ||
| import { ResourceLoadErrors } from './resource-load-errors'; | ||
|
|
||
| import './create-vm-wizard.scss'; | ||
|
|
||
| export class CreateVMWizardComponent extends React.Component<CreateVMWizardComponentProps> { | ||
| private isClosed = false; | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
| props.onInitialize(); | ||
| } | ||
|
|
||
| componentDidUpdate(prevProps) { | ||
| if (this.isClosed) { | ||
| return; | ||
| } | ||
| const changedProps = [...DetectCommonDataChanges].reduce((changedPropsAcc, propName) => { | ||
| if (prevProps[propName] !== this.props[propName]) { | ||
| changedPropsAcc.add(propName); | ||
| } | ||
| return changedPropsAcc; | ||
| }, new Set()) as ChangedCommonData; | ||
|
|
||
| if (changedProps.size > 0) { | ||
| this.props.onCommonDataChanged( | ||
| { dataIDReferences: this.props.dataIDReferences }, | ||
| changedProps, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| onClose = () => { | ||
| this.isClosed = true; | ||
| this.props.onClose(); | ||
| }; | ||
|
|
||
| finish() { | ||
| const create = this.props.isCreateTemplate ? createVmTemplate : createVm; | ||
|
|
||
| const enhancedK8sMethods = new EnhancedK8sMethods(); | ||
| const vmSettings = iGetIn(this.props.stepData, [VMWizardTab.VM_SETTINGS, 'value']).toJS(); | ||
| const templates = immutableListToShallowJS( | ||
| concatImmutableLists( | ||
| iGetLoadedData(this.props[VMWizardProps.commonTemplates]), | ||
| iGetLoadedData(this.props[VMWizardProps.userTemplates]), | ||
| ), | ||
| ); | ||
|
|
||
| // TODO remove after moving create functions from kubevirt-web-ui-components | ||
| /** * | ||
| * BEGIN kubevirt-web-ui-components InterOP | ||
| */ | ||
| vmSettings.namespace = { value: this.props.activeNamespace }; | ||
| const operatingSystems = getTemplateOperatingSystems(templates); | ||
| const osField = vmSettings[VMSettingsField.OPERATING_SYSTEM]; | ||
| const osID = osField.value; | ||
| osField.value = operatingSystems.find(({ id }) => id === osID); | ||
| /** | ||
| * END kubevirt-web-ui-components InterOP | ||
| */ | ||
|
|
||
| create( | ||
| enhancedK8sMethods, | ||
| templates, | ||
| vmSettings, | ||
| iGetIn(this.props.stepData, [VMWizardTab.NETWORKS, 'value']).toJS(), | ||
| iGetIn(this.props.stepData, [VMWizardTab.STORAGE, 'value']).toJS(), | ||
| immutableListToShallowJS(iGetLoadedData(this.props[VMWizardProps.persistentVolumeClaims])), | ||
| units, | ||
| ) | ||
| .then(() => getResults(enhancedK8sMethods)) | ||
| .catch((error) => cleanupAndGetResults(enhancedK8sMethods, error)) | ||
| .then(({ results, valid }) => this.props.onResultsChanged(errorsFirstSort(results), valid)) // TODO should distinguish between errors and objects in redux | ||
| .catch((e) => console.error(e)); // eslint-disable-line no-console | ||
| } | ||
|
|
||
| render() { | ||
| const { isCreateTemplate, stepData } = this.props; | ||
| const createVmText = isCreateTemplate ? CREATE_VM_TEMPLATE : CREATE_VM; | ||
|
|
||
| if (this.isClosed) { | ||
| return null; | ||
| } | ||
|
|
||
| const steps = [ | ||
| { | ||
| id: VMWizardTab.VM_SETTINGS, | ||
| component: ( | ||
| <> | ||
| <ResourceLoadErrors wizardReduxID={this.props.reduxID} /> | ||
| <VMSettingsTab wizardReduxID={this.props.reduxID} /> | ||
| </> | ||
| ), | ||
| nextButtonText: REVIEW_AND_CREATE, | ||
| }, | ||
| // { | ||
| // id: VMWizardTab.NETWORKS, | ||
| // }, | ||
| // { | ||
| // id: VMWizardTab.STORAGE, | ||
| // }, | ||
| { | ||
| id: VMWizardTab.REVIEW, | ||
| nextButtonText: createVmText, | ||
| component: <>VM review</>, | ||
| }, | ||
| { | ||
| id: VMWizardTab.RESULT, | ||
| component: ( | ||
| <> | ||
| {isStepValid(stepData, VMWizardTab.RESULT) ? 'Created Successfully' : 'Creation Failed'} | ||
| </> | ||
| ), | ||
| isFinishedStep: isStepValid(stepData, VMWizardTab.RESULT), | ||
| }, | ||
| ]; | ||
|
|
||
| const isLocked = _.some(steps, ({ id }) => isStepLocked(stepData, id)); | ||
|
|
||
| return ( | ||
| <div className="kubevirt-create-vm-modal__container"> | ||
| {!isStepValid(stepData, VMWizardTab.RESULT) && ( | ||
| <div className="yaml-editor__header"> | ||
| <h1 className="yaml-editor__header-text">{createVmText}</h1> | ||
| </div> | ||
| )} | ||
| <Wizard | ||
| isInPage | ||
| className="kubevirt-create-vm-modal__wizard-content" | ||
| title={createVmText} | ||
| onClose={this.onClose} | ||
| onNext={({ id }) => { | ||
| if (id === VMWizardTab.RESULT) { | ||
| this.finish(); | ||
| } | ||
| }} | ||
| steps={steps.map((step, idx) => { | ||
| const valid = isStepValid(stepData, step.id); | ||
| const prevStepValid = idx === 0 ? true : isStepValid(stepData, steps[idx - 1].id); | ||
| return { | ||
| ...step, | ||
| name: TabTitleResolver[step.id], | ||
| enableNext: !isLocked && valid, | ||
| canJumpTo: !isLocked && prevStepValid && step.id !== VMWizardTab.RESULT, | ||
| hideBackButton: isLocked, | ||
| component: step.component, | ||
| }; | ||
| })} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| const wizardStateToProps = (state, { reduxID }) => ({ | ||
| stepData: iGetCreateVMWizardTabs(state, reduxID), | ||
| // fetch data from store to detect and fire changes | ||
| ...[...DetectCommonDataChanges].reduce((acc, propName) => { | ||
| acc[propName] = iGetCommonData(state, reduxID, propName); | ||
| return acc; | ||
| }, {}), | ||
| }); | ||
|
|
||
| const wizardDispatchToProps = (dispatch, props) => ({ | ||
| onInitialize: () => { | ||
| dispatch( | ||
| vmWizardActions[ActionType.Create](props.reduxID, { | ||
| data: { | ||
| isCreateTemplate: props.isCreateTemplate, | ||
| }, | ||
| dataIDReferences: props.dataIDReferences, | ||
| }), | ||
| ); | ||
| }, | ||
| onCommonDataChanged: (commonData: CommonData, changedCommonData: ChangedCommonData) => { | ||
| dispatch( | ||
| vmWizardActions[ActionType.UpdateCommonData](props.reduxID, commonData, changedCommonData), | ||
| ); | ||
| }, | ||
| onResultsChanged: (results, isValid) => { | ||
| dispatch(vmWizardActions[ActionType.SetResults](props.reduxID, results, isValid)); | ||
| }, | ||
| onClose: () => { | ||
| if (props.onClose) { | ||
| props.onClose(); | ||
| } | ||
| dispatch(vmWizardActions[ActionType.Dispose](props.reduxID, props)); | ||
| }, | ||
| }); | ||
|
|
||
| export const CreateVMWizard = connect( | ||
| wizardStateToProps, | ||
| wizardDispatchToProps, | ||
| )(CreateVMWizardComponent); | ||
|
|
||
| export const CreateVMWizardPageComponent: React.FC<CreateVMWizardPageComponentProps> = (props) => { | ||
| const { | ||
| reduxID, | ||
| match: { | ||
| params: { ns: activeNamespace }, | ||
| }, | ||
| } = props; | ||
| const resources = [ | ||
| getResource(VirtualMachineModel, { | ||
| namespace: activeNamespace, | ||
| prop: VMWizardProps.virtualMachines, | ||
| }), | ||
| getResource(TemplateModel, { | ||
| namespace: activeNamespace, | ||
| prop: VMWizardProps.userTemplates, | ||
| matchLabels: { [TEMPLATE_TYPE_LABEL]: TEMPLATE_TYPE_VM }, | ||
| }), | ||
| getResource(TemplateModel, { | ||
| namespace: 'openshift', | ||
| prop: VMWizardProps.commonTemplates, | ||
| matchLabels: { [TEMPLATE_TYPE_LABEL]: TEMPLATE_TYPE_BASE }, | ||
| }), | ||
| getResource(NetworkAttachmentDefinitionModel, { | ||
| namespace: activeNamespace, | ||
| prop: VMWizardProps.networkConfigs, | ||
| }), | ||
| getResource(StorageClassModel, { prop: VMWizardProps.storageClasses }), | ||
| getResource(PersistentVolumeClaimModel, { | ||
| namespace: activeNamespace, | ||
| prop: VMWizardProps.persistentVolumeClaims, | ||
| }), | ||
| getResource(DataVolumeModel, { | ||
| namespace: activeNamespace, | ||
| prop: VMWizardProps.dataVolumes, | ||
| }), | ||
| ]; | ||
|
|
||
| const dataIDReferences = resources.reduce((acc, resource) => { | ||
| const query = makeQuery( | ||
| resource.namespace, | ||
| resource.selector, | ||
| resource.fieldSelector, | ||
| resource.name, | ||
| ); | ||
| acc[resource.prop] = ['k8s', makeReduxID(resource.model, query)]; | ||
|
|
||
| return acc; | ||
| }, {}); | ||
|
|
||
| dataIDReferences[VMWizardProps.activeNamespace] = ['UI', 'activeNamespace']; | ||
|
|
||
| return ( | ||
| <Firehose resources={resources}> | ||
| <CreateVMWizard | ||
| isCreateTemplate={!props.match.path.includes('/virtualmachines/')} | ||
| dataIDReferences={dataIDReferences} | ||
| activeNamespace={activeNamespace} | ||
| reduxID={reduxID} | ||
| onClose={() => history.goBack()} | ||
| /> | ||
| </Firehose> | ||
| ); | ||
| }; | ||
|
|
||
| type CreateVMWizardPageComponentProps = { | ||
| match: { | ||
| params: { | ||
| ns: string; | ||
| }; | ||
| path: string; | ||
| isExact: boolean; | ||
| url: string; | ||
| }; | ||
| reduxID: string; | ||
| }; | ||
|
|
||
| export const CreateVMWizardPage = withReduxID(CreateVMWizardPageComponent); | ||
7 changes: 7 additions & 0 deletions
7
...tend/packages/kubevirt-plugin/src/components/create-vm-wizard/form/form-field-context.tsx
This file contains hidden or 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,7 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| export const FormFieldContext = React.createContext({ | ||
| field: null, | ||
| fieldType: null, | ||
| isLoading: false, | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
firehose injects
reduxIDsprops so you dont have to compute them yourselfThere 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.
That is true, but it is not enough. We need to pair the reference path with the prop. Please see:
This is done to get our desired prop even if the query and redux id changes (e.g. namespace change).