-
Notifications
You must be signed in to change notification settings - Fork 42
[#641] Add EditPlanNameModal for editing name and description of completed plans #663
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { V2V_POST_EDIT_PLAN_NAME } from './EditPlanNameConstants'; | ||
import API from '../../../../../../common/API'; | ||
|
||
export { fetchTransformationPlansAction } from '../../OverviewActions'; | ||
|
||
const _editMigrationPlansActionCreator = (url, planId, migrationPlans) => dispatch => { | ||
const body = { | ||
action: 'edit', | ||
resource: { ...migrationPlans } | ||
}; | ||
return dispatch({ | ||
type: V2V_POST_EDIT_PLAN_NAME, | ||
payload: API.post(`${url}/${planId}`, body) | ||
}); | ||
}; | ||
|
||
export const editMigrationPlansAction = (url, planId, migrationPlans) => | ||
_editMigrationPlansActionCreator(url, planId, migrationPlans); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const V2V_POST_EDIT_PLAN_NAME = 'V2V_POST_EDIT_PLAN_NAME'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Field, reduxForm } from 'redux-form'; | ||
import { required } from 'redux-form-validators'; | ||
import { Modal, Button, Form, Spinner, noop } from 'patternfly-react'; | ||
import { FormField } from '../../../common/forms/FormField'; | ||
import { validation } from '../../../../../../common/constants'; | ||
import { asyncValidate, onChange } from '../../screens/PlanWizard/components/PlanWizardGeneralStep/helpers'; | ||
|
||
class EditPlanNameModal extends React.Component { | ||
onSubmit = () => { | ||
const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 6 locations. Consider refactoring. |
||
editPlanNameModal, | ||
editingPlan, | ||
editMigrationPlansAction, | ||
editMigrationPlansUrl, | ||
hideEditPlanNameModalAction, | ||
fetchTransformationPlansAction, | ||
fetchTransformationPlansUrl, | ||
fetchArchivedTransformationPlansUrl | ||
} = this.props; | ||
const { | ||
values: { name, description } | ||
} = editPlanNameModal; | ||
const resource = { name, description }; | ||
editMigrationPlansAction(editMigrationPlansUrl, editingPlan.id, resource).then(() => { | ||
hideEditPlanNameModalAction(); | ||
fetchTransformationPlansAction({ | ||
url: fetchTransformationPlansUrl, | ||
archived: false | ||
}); | ||
fetchTransformationPlansAction({ | ||
url: fetchArchivedTransformationPlansUrl, | ||
archived: true | ||
}); | ||
}); | ||
}; | ||
|
||
render() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
const { editPlanNameModalVisible, hideEditPlanNameModalAction, editPlanNameModal, savingPlan } = this.props; | ||
|
||
const disableConfirmButton = savingPlan || !!editPlanNameModal.syncErrors || !!editPlanNameModal.asyncErrors; | ||
|
||
const formBody = ( | ||
<Form horizontal> | ||
<Field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identical blocks of code found in 3 locations. Consider refactoring. |
||
name="name" | ||
label={__('Name')} | ||
required | ||
component={FormField} | ||
type="text" | ||
help={validation.name.help} | ||
maxLength={validation.name.maxLength} | ||
maxLengthWarning={validation.name.maxLengthWarning} | ||
validate={[ | ||
required({ | ||
msg: validation.name.requiredMessage | ||
}) | ||
]} | ||
/> | ||
<Field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identical blocks of code found in 3 locations. Consider refactoring. |
||
name="description" | ||
label={__('Description')} | ||
component={FormField} | ||
type="textarea" | ||
help={validation.description.help} | ||
maxLength={validation.description.maxLength} | ||
maxLengthWarning={validation.description.maxLengthWarning} | ||
/> | ||
</Form> | ||
); | ||
|
||
const spinner = ( | ||
<div style={{ marginTop: 15 }}> | ||
<Spinner loading size="lg" /> | ||
<h2 style={{ textAlign: 'center' }}>{__('Saving...')}</h2> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Modal show={editPlanNameModalVisible} onHide={hideEditPlanNameModalAction}> | ||
<Modal.Header> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 3 locations. Consider refactoring. |
||
<Modal.CloseButton onClick={hideEditPlanNameModalAction} /> | ||
<Modal.Title>{__('Edit Migration Plan')}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body>{!savingPlan ? formBody : spinner}</Modal.Body> | ||
<Modal.Footer> | ||
<Button bsStyle="default" className="btn-cancel" onClick={hideEditPlanNameModalAction}> | ||
{__('Cancel')} | ||
</Button> | ||
<Button bsStyle="primary" onClick={this.onSubmit} disabled={disableConfirmButton}> | ||
{__('Save')} | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
EditPlanNameModal.propTypes = { | ||
editPlanNameModalVisible: PropTypes.bool, | ||
hideEditPlanNameModalAction: PropTypes.func, | ||
editPlanNameModal: PropTypes.object, | ||
editingPlan: PropTypes.object, | ||
editMigrationPlansAction: PropTypes.func, | ||
editMigrationPlansUrl: PropTypes.string, | ||
savingPlan: PropTypes.bool.isRequired, | ||
fetchTransformationPlansAction: PropTypes.func, | ||
fetchTransformationPlansUrl: PropTypes.string, | ||
fetchArchivedTransformationPlansUrl: PropTypes.string | ||
}; | ||
|
||
EditPlanNameModal.defaultProps = { | ||
editPlanNameModalVisible: false, | ||
hideEditPlanNameModalAction: noop, | ||
editPlanNameModal: {}, | ||
editMigrationPlansUrl: '/api/service_templates' | ||
}; | ||
|
||
export default reduxForm({ | ||
form: 'editPlanNameModal', | ||
asyncValidate, | ||
asyncBlurFields: ['name'], | ||
onChange | ||
})(EditPlanNameModal); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Immutable from 'seamless-immutable'; | ||
import { | ||
V2V_EDIT_PLAN_TITLE_SHOW_ALERT, | ||
V2V_EDIT_PLAN_TITLE_HIDE_ALERT, | ||
V2V_POST_EDIT_PLAN_NAME | ||
} from './EditPlanNameConstants'; | ||
|
||
const initialState = Immutable({ | ||
alertText: '', | ||
savingPlan: false, | ||
savingPlanRejected: false, | ||
savingPlanError: null | ||
}); | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case V2V_EDIT_PLAN_TITLE_SHOW_ALERT: | ||
return Immutable.merge(state, action.payload); | ||
case V2V_EDIT_PLAN_TITLE_HIDE_ALERT: | ||
return state.set('alertText', ''); | ||
case `${V2V_POST_EDIT_PLAN_NAME}_PENDING`: | ||
return state | ||
.set('savingPlan', true) | ||
.set('savingPlanRejected', false) | ||
.set('savingPlanError', null); | ||
case `${V2V_POST_EDIT_PLAN_NAME}_FULFILLED`: | ||
return state | ||
.set('savingPlan', false) | ||
.set('savingPlanRejected', false) | ||
.set('savingPlanError', null); | ||
case `${V2V_POST_EDIT_PLAN_NAME}_REJECTED`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 6 locations. Consider refactoring. |
||
return state | ||
.set('savingPlan', false) | ||
.set('savingPlanRejected', true) | ||
.set('savingPlanError', action.payload); | ||
default: | ||
return state; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { connect } from 'react-redux'; | ||
import EditPlanNameModal from './EditPlanNameModal'; | ||
import { findEditingPlan } from '../../screens/PlanWizard/PlanWizardSelectors'; | ||
import * as EditPlanNameActions from './EditPlanNameActions'; | ||
|
||
import reducer from './EditPlanNameReducer'; | ||
|
||
export const reducers = { editPlanName: reducer }; | ||
|
||
const mapStateToProps = ({ editPlanName, overview, form }) => { | ||
const plans = [...overview.transformationPlans, ...overview.archivedTransformationPlans]; | ||
const editingPlan = findEditingPlan(plans, overview.editingPlanId); | ||
return { | ||
...editPlanName, | ||
editPlanNameModal: form && form.editPlanNameModal, | ||
initialValues: { | ||
name: editingPlan ? editingPlan.name : '', | ||
description: editingPlan ? editingPlan.description : '' | ||
}, | ||
enableReinitialize: true, | ||
editingPlan | ||
}; | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
EditPlanNameActions | ||
)(EditPlanNameModal); |
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.
Similar blocks of code found in 4 locations. Consider refactoring.