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

Commit

Permalink
[WIP] Fetch playbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkro committed Jun 25, 2018
1 parent c227b34 commit 8a2a6ad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
5 changes: 4 additions & 1 deletion app/javascript/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export const coreComponents = [
name: 'PlanWizardAdvancedOptionsStepContainer',
type: PlanWizardAdvancedOptionsStepContainer,
data: {
url: '/api/something'
fetchPlaybooksUrl:
'/api/service_templates/?' +
"filter[]=type='ServiceTemplateAnsiblePlaybook'" +
'&expand=resources'
},
store: true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Field, reduxForm } from 'redux-form';
import { Form } from 'patternfly-react';
import { Form, Spinner } from 'patternfly-react';

import PlanWizardAdvancedOptionsStepTable from './components/PlanWizardAdvancedOptionsStepTable/PlanWizardAdvancedOptionsStepTable';
import { BootstrapSelect } from '../../../../../common/forms/BootstrapSelect';
Expand All @@ -16,8 +16,8 @@ class PlanWizardAdvancedOptionsStep extends Component {
}

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

onSelectChange = (event, scheduleType) => {
Expand All @@ -38,35 +38,33 @@ class PlanWizardAdvancedOptionsStep extends Component {
} = this.props;

return (
<React.Fragment>
{!isFetchingPlaybooks && (
<Form className="playbook-selects">
<Field
name="preMigrationPlaybook"
component={BootstrapSelect}
options={playbooks}
option_key="id"
option_value="name"
label={__('Select pre-migration playbook service (optional)')}
stacked_label
controlWidth={12}
allowClear
onChange={event => this.onSelectChange(event, 'preMigration')}
/>
<Field
name="postMigrationPlaybook"
component={BootstrapSelect}
options={playbooks}
option_key="id"
option_value="name"
label={__('Select post-migration playbook service (optional)')}
stacked_label
controlWidth={12}
allowClear
onChange={event => this.onSelectChange(event, 'postMigration')}
/>
</Form>
)}
<Spinner loading={isFetchingPlaybooks}>
<Form className="playbook-selects">
<Field
name="preMigrationPlaybook"
component={BootstrapSelect}
options={playbooks}
option_key="id"
option_value="name"
label={__('Select pre-migration playbook service (optional)')}
stacked_label
controlWidth={12}
allowClear
onChange={event => this.onSelectChange(event, 'preMigration')}
/>
<Field
name="postMigrationPlaybook"
component={BootstrapSelect}
options={playbooks}
option_key="id"
option_value="name"
label={__('Select post-migration playbook service (optional)')}
stacked_label
controlWidth={12}
allowClear
onChange={event => this.onSelectChange(event, 'postMigration')}
/>
</Form>
<Field
name="playbookVms"
component={PlanWizardAdvancedOptionsStepTable}
Expand All @@ -89,7 +87,7 @@ class PlanWizardAdvancedOptionsStep extends Component {
advancedOptionsStepForm.values.playbookVms.postMigration
}
/>
</React.Fragment>
</Spinner>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import URI from 'urijs';
import API from '../../../../../../../../common/API';

import {
FETCH_V2V_PLAYBOOKS,
SET_V2V_ADVANCED_OPTIONS_STEP_VMS,
Expand All @@ -6,12 +9,17 @@ import {

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

export const getPlaybooksActionCreator = () => dispatch =>
export const _getPlaybooksActionCreator = url => dispatch =>
dispatch({
type: FETCH_V2V_PLAYBOOKS,
payload: Promise.resolve({ data: playbooks })
payload: API.get(url)
});

export const fetchPlaybooksAction = url => {
const uri = new URI(url);
return _getPlaybooksActionCreator(uri.toString());
};

export const setVmsAction = vms => ({
type: SET_V2V_ADVANCED_OPTIONS_STEP_VMS,
payload: vms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default (state = initialState, action) => {
.set('isRejectedPlaybooks', false);
case `${FETCH_V2V_PLAYBOOKS}_FULFILLED`:
return state
.set('playbooks', action.payload.data)
.set('playbooks', action.payload.data.resources)
.set('isFetchingPlaybooks', false)
.set('isRejectedPlaybooks', false)
.set('errorPlaybooks', null);
Expand Down

0 comments on commit 8a2a6ad

Please sign in to comment.