Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Add Advanced Options Step to Plan Wizard
Browse files Browse the repository at this point in the history
* Stub actions/reducer for fetching playbooks
* Copy and modify VMsStep table
* Copy and modify BootstrapSelect
  • Loading branch information
michaelkro committed Jun 14, 2018
1 parent 0a0fcc7 commit 65fb429
Show file tree
Hide file tree
Showing 25 changed files with 1,260 additions and 22 deletions.
9 changes: 9 additions & 0 deletions app/javascript/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MappingWizardResultsStepContainer from '../react/screens/App/Overview/scr
import PlanWizardVMStepContainer from '../react/screens/App/Overview/screens/PlanWizard/components/PlanWizardVMStep';
import PlanWizardResultsStepContainer from '../react/screens/App/Overview/screens/PlanWizard/components/PlanWizardResultsStep';
import PlanWizardContainer from '../react/screens/App/Overview/screens/PlanWizard';
import PlanWizardAdvancedOptionsStepContainer from '../react/screens/App/Overview/screens/PlanWizard/components/PlanWizardAdvancedOptionsStep';

import OverviewContainer from '../react/screens/App/Overview';
import PlanContainer from '../react/screens/App/Plan';
Expand Down Expand Up @@ -84,6 +85,14 @@ export const coreComponents = [
},
store: true
},
{
name: 'PlanWizardAdvancedOptionsStepContainer',
type: PlanWizardAdvancedOptionsStepContainer,
data: {
url: '/api/something'
},
store: true
},
{
name: 'OverviewContainer',
type: OverviewContainer,
Expand Down
1 change: 1 addition & 0 deletions app/javascript/react/screens/App/Overview/Overview.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './screens/MappingWizard/MappingWizard.scss';
@import './screens/PlanWizard/PlanWizard.scss';
@import './screens/PlanWizard/components/PlanWizardResultsStep/PlanWizardResultsStep.scss';
@import 'components/InfrastructureMappingsList/InfrastructureMappingsList.scss';
@import 'components/Migrations/Migrations.scss';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { MIGRATIONS_FILTERS } from '../../OverviewConstants';
const planWizardSteps = [
'planWizardGeneralStep',
'planWizardVMStep',
'planWizardOptionsStep',
'planWizardAdvancedOptionsStep',
'planWizardScheduleStep',
'planWizardResultsStep'
];

Expand All @@ -31,30 +32,30 @@ class PlanWizard extends React.Component {
const {
planWizardGeneralStep,
planWizardVMStep,
planWizardOptionsStep,
planWizardScheduleStep,
setPlansBodyAction,
setPlanScheduleAction,
setMigrationsFilterAction
} = this.props;

if (activeStepIndex === 2) {
if (activeStepIndex === 3) {
const plansBody = createMigrationPlans(
planWizardGeneralStep,
planWizardVMStep
);

setPlanScheduleAction(
planWizardOptionsStep.values.migration_plan_choice_radio
planWizardScheduleStep.values.migration_plan_choice_radio
);
setPlansBodyAction(plansBody);

if (
planWizardOptionsStep.values.migration_plan_choice_radio ===
planWizardScheduleStep.values.migration_plan_choice_radio ===
'migration_plan_now'
) {
setMigrationsFilterAction(MIGRATIONS_FILTERS.inProgress);
} else if (
planWizardOptionsStep.values.migration_plan_choice_radio ===
planWizardScheduleStep.values.migration_plan_choice_radio ===
'migration_plan_later'
) {
setMigrationsFilterAction(MIGRATIONS_FILTERS.notStarted);
Expand All @@ -77,7 +78,7 @@ class PlanWizard extends React.Component {
planWizardExitedAction,
planWizardGeneralStep,
planWizardVMStep,
planWizardOptionsStep
planWizardScheduleStep
} = this.props;

const { activeStepIndex, plansBody } = this.state;
Expand Down Expand Up @@ -116,7 +117,7 @@ class PlanWizard extends React.Component {
plansBody={plansBody}
planWizardGeneralStep={planWizardGeneralStep}
planWizardVMStep={planWizardVMStep}
planWizardOptionsStep={planWizardOptionsStep}
planWizardScheduleStep={planWizardScheduleStep}
/>
</Wizard.Body>

Expand All @@ -143,7 +144,7 @@ class PlanWizard extends React.Component {
>
{onFinalStep
? __('Close')
: activeStepIndex === 2
: activeStepIndex === 3
? __('Create')
: __('Next')}
<Icon type="fa" name="angle-right" />
Expand All @@ -159,7 +160,8 @@ PlanWizard.propTypes = {
planWizardExitedAction: PropTypes.func,
planWizardGeneralStep: PropTypes.object,
planWizardVMStep: PropTypes.object,
planWizardOptionsStep: PropTypes.object,
planWizardAdvancedOptionsStep: PropTypes.object, // eslint-disable-line react/no-unused-prop-types
planWizardScheduleStep: PropTypes.object,
setPlansBodyAction: PropTypes.func,
setPlanScheduleAction: PropTypes.func,
resetVmStepAction: PropTypes.func,
Expand All @@ -171,7 +173,8 @@ PlanWizard.defaultProps = {
planWizardExitedAction: noop,
planWizardGeneralStep: {},
planWizardVMStep: {},
planWizardOptionsStep: {},
planWizardAdvancedOptionsStep: {},
planWizardScheduleStep: {},
setPlansBodyAction: noop,
setPlanScheduleAction: noop,
resetVmStepAction: noop
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './components/PlanWizardAdvancedOptionsStep/PlanWizardAdvancedOptionsStep.scss';
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const planWizardExitedAction = () => dispatch => {
dispatch({
type: V2V_VM_STEP_RESET
});
dispatch(reset('planWizardOptionsStep'));
dispatch(reset('planWizardScheduleStep'));
dispatch(reset('planWizardAdvancedOptionsStep'));
};

export const setPlansBodyAction = body => dispatch => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { noop } from 'patternfly-react';
import ModalWizard from '../../components/ModalWizard';
import componentRegistry from '../../../../../../components/componentRegistry';
import PlanWizardGeneralStep from '../PlanWizard/components/PlanWizardGeneralStep';
import PlanWizardOptionsStep from '../PlanWizard/components/PlanWizardOptionsStep';
import PlanWizardScheduleStep from '../PlanWizard/components/PlanWizardScheduleStep';

class PlanWizardBody extends React.Component {
constructor(props) {
Expand All @@ -16,6 +16,9 @@ class PlanWizardBody extends React.Component {
this.planWizardResultsStepContainer = componentRegistry.markup(
'PlanWizardResultsStepContainer'
);
this.planWizardAdvancedOptionsStepContainer = componentRegistry.markup(
'PlanWizardAdvancedOptionsStepContainer'
);
}
shouldComponentUpdate(nextProps, nextState) {
return JSON.stringify(this.props) !== JSON.stringify(nextProps);
Expand All @@ -39,8 +42,13 @@ class PlanWizardBody extends React.Component {
disableGoto: !this.props.planWizardVMStep.values
},
{
title: __('Options'),
render: () => <PlanWizardOptionsStep />,
title: __('Advanced Options'),
render: () => this.planWizardAdvancedOptionsStepContainer,
disableGoto: true
},
{
title: __('Schedule'),
render: () => <PlanWizardScheduleStep />,
disableGoto: true
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export const planWizardOverviewFilter = overview => ({
export const planWizardFormFilter = form => ({
planWizardGeneralStep: form.planWizardGeneralStep,
planWizardVMStep: form.planWizardVMStep,
planWizardOptionsStep: form.planWizardOptionsStep
planWizardAdvancedOptionsStep: form.planWizardAdvancedOptionsStep,
planWizardScheduleStep: form.planWizardScheduleStep
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ exports[`Plan Wizard integration test should mount the PlanWizard with mapStateT
Object {
"hidePlanWizard": false,
"hidePlanWizardAction": [Function],
"planWizardAdvancedOptionsStep": Object {},
"planWizardExitedAction": [Function],
"planWizardGeneralStep": Object {},
"planWizardOptionsStep": Object {},
"planWizardScheduleStep": Object {},
"planWizardVMStep": Object {},
"resetVmStepAction": [Function],
"setMigrationsFilterAction": [Function],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook

export const playbooks = [
{
id: '1',
manager_id: '2',
manager_ref: 'openshift/cloudforms-automation/project-quota.yml',
name: 'openshift/cloudforms-automation/project-quota.yml',
description: 'This is an ansible playbook',
variables: null,
created_at: 'Thu, 18 Jan 2018 17:22:22 UTC +00:00',
updated_at: 'Thu, 18 Jan 2018 17:22:22 UTC +00:00',
survey_spec: null,
inventory_root_group_id: null,
type: 'ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook',
parent_id: null,
configuration_script_source_id: '21'
},
{
id: '10',
manager_id: '2',
manager_ref: 'plays/first.yml',
name: 'plays/first.yml',
description: 'This is also an ansible playbook',
variables: null,
created_at: 'Fri, 06 Oct 2017 17:03:07 UTC +00:00',
updated_at: 'Fri, 06 Oct 2017 17:03:07 UTC +00:00',
survey_spec: null,
inventory_root_group_id: null,
type: 'ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook',
parent_id: null,
configuration_script_source_id: '1'
},
{
id: '15',
manager_id: '2',
manager_ref: 'plays/post.yml',
name: 'plays/post.yml',
description: 'Yet another, ansible playbook',
variables: null,
created_at: 'Fri, 06 Oct 2017 17:03:07 UTC +00:00',
updated_at: 'Fri, 06 Oct 2017 17:03:07 UTC +00:00',
survey_spec: null,
inventory_root_group_id: null,
type: 'ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook',
parent_id: null,
configuration_script_source_id: '1'
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Field, reduxForm } from 'redux-form';
import { Form } from 'patternfly-react';

import PlanWizardAdvancedOptionsStepTable from './components/PlanWizardAdvancedOptionsStepTable/PlanWizardAdvancedOptionsStepTable';
import { PlaybooksBootstrapSelect } from './components/PlaybooksBootstrapSelect';

class PlanWizardAdvancedOptionsStep extends Component {
state = {
preMigrationPlaybook: '',
postMigrationPlaybook: ''
};

componentDidMount() {
const { getPlaybooksActionCreator } = this.props;
getPlaybooksActionCreator();
}

selectPreMigrationPlaybook = event => {
this.setState({ preMigrationPlaybook: event.target.value });
};

selectPostMigrationPlaybook = event => {
this.setState({ postMigrationPlaybook: event.target.value });
};

render() {
const {
valid_vms,
selectedVms,
playbooks,
isFetchingPlaybooks,
dirty
} = this.props;
const { preMigrationPlaybook, postMigrationPlaybook } = this.state;
const vms = valid_vms.filter(vm => selectedVms.includes(vm.id));

return (
<React.Fragment>
{!isFetchingPlaybooks && (
<Form className="playbook-selects">
<Field
name="preMigrationPlaybook"
component={PlaybooksBootstrapSelect}
options={playbooks}
option_key="id"
option_value="name"
label={__('Select pre-migration playbook service (optional)')}
onChange={this.selectPreMigrationPlaybook}
/>
<Field
name="postMigrationPlaybook"
component={PlaybooksBootstrapSelect}
options={playbooks}
option_key="id"
option_value="name"
label={__('Select post-migration playbook service (optional)')}
onChange={this.selectPostMigrationPlaybook}
/>
</Form>
)}
{dirty && (
<Field
name="playbookVms"
component={PlanWizardAdvancedOptionsStepTable}
rows={vms}
preMigrationPlaybook={preMigrationPlaybook}
postMigrationPlaybook={postMigrationPlaybook}
/>
)}
</React.Fragment>
);
}
}

PlanWizardAdvancedOptionsStep.propTypes = {
valid_vms: PropTypes.array,
selectedVms: PropTypes.array,
playbooks: PropTypes.array,
isFetchingPlaybooks: PropTypes.bool,
getPlaybooksActionCreator: PropTypes.func,
dirty: PropTypes.bool
};

export default reduxForm({
form: 'planWizardAdvancedOptionsStep',
initialValues: {
playbookVms: {
preMigration: [],
postMigration: []
},
preMigrationPlaybook: '',
postMigrationPlaybook: ''
},
destroyOnUnmount: false
})(PlanWizardAdvancedOptionsStep);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.table-view-pf-select.with-label {
width: 110px;
}

.table-view-pf-select-content {
display: flex;
flex-direction: column;
align-items: center;
}

.table-view-pf-footer {
background: #f5f5f5;
&-count {
font-weight: 600;
white-space: pre;
}
}

.bootstrap-select.btn-group.form-control.preMigrationPlaybook_select,
.bootstrap-select.btn-group.form-control.postMigrationPlaybook_select {
margin-bottom: 20px;
}

.playbook-services-toolbar .toolbar-pf {
background: #f5f5f5;
border: 1px solid #d1d1d1;
border-bottom: none;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { FETCH_V2V_PLAYBOOKS } from './PlanWizardAdvancedOptionsStepConstants';

import { playbooks } from './PlanWizardAdvancedOptionsStep.fixtures';

export const getPlaybooksActionCreator = () => dispatch =>
dispatch({
type: FETCH_V2V_PLAYBOOKS,
payload: Promise.resolve({ data: playbooks })
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const FETCH_V2V_PLAYBOOKS = 'FETCH_V2V_PLAYBOOKS';
Loading

0 comments on commit 65fb429

Please sign in to comment.