Skip to content

Commit

Permalink
Abstracts migration buttons into component, adds scheduling to completed
Browse files Browse the repository at this point in the history
List components share buttons rather than duplicating in each
  • Loading branch information
AllenBW committed Jul 27, 2018
1 parent 85699b7 commit 7ac47fb
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 273 deletions.
6 changes: 3 additions & 3 deletions app/javascript/react/screens/App/Overview/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Overview extends React.Component {
isRejectedDatastores,
toggleScheduleMigrationModal,
scheduleMigrationModal,
scheduleMigrationPlanId,
scheduleMigrationPlan,
scheduleMigration
} = this.props;

Expand Down Expand Up @@ -324,7 +324,7 @@ class Overview extends React.Component {
addNotificationAction={addNotificationAction}
toggleScheduleMigrationModal={toggleScheduleMigrationModal}
scheduleMigrationModal={scheduleMigrationModal}
scheduleMigrationPlanId={scheduleMigrationPlanId}
scheduleMigrationPlan={scheduleMigrationPlan}
scheduleMigration={scheduleMigration}
/>
)}
Expand Down Expand Up @@ -452,7 +452,7 @@ Overview.propTypes = {
fetchDatastoresAction: PropTypes.func,
toggleScheduleMigrationModal: PropTypes.func,
scheduleMigrationModal: PropTypes.bool,
scheduleMigrationPlanId: PropTypes.string,
scheduleMigrationPlan: PropTypes.string,
scheduleMigration: PropTypes.func
};
export default Overview;
25 changes: 17 additions & 8 deletions app/javascript/react/screens/App/Overview/OverviewActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
V2V_TOGGLE_SCHEDULE_MIGRATION_MODAL,
YES_TO_DELETE_AND_HIDE_DELETE_CONFIRMATION_MODAL
} from './OverviewConstants';
import moment from 'moment/moment';

export const showConfirmModalAction = modalOptions => ({
type: SHOW_CONFIRM_MODAL,
Expand Down Expand Up @@ -233,31 +234,39 @@ export const archiveTransformationPlanAction = (url, id) => {
return _archiveTransformationPlanActionCreator(uri.toString());
};

export const toggleScheduleMigrationModal = planId => ({
export const toggleScheduleMigrationModal = plan => ({
type: V2V_TOGGLE_SCHEDULE_MIGRATION_MODAL,
payload: planId
payload: plan
});

export const scheduleMigration = payload => dispatch =>
dispatch({
type: V2V_SCHEDULE_MIGRATION,
payload: new Promise((resolve, reject) => {
let url = `/api/service_templates/${payload.planId}`;
const planId = payload.plan.id;
const scheduleId = (payload.plan.schedules && payload.plan.schedules[0].id) || null;
const scheduleTime = payload.scheduleTime;
let url = `/api/service_templates/${planId}`;
let body = {
action: 'order',
resource: {
schedule_time: payload.scheduleTime
schedule_time: scheduleTime
}
};
if (payload.scheduleId) {
url = `${url}/schedules/${payload.scheduleId}`;
body = { action: 'delete' };
if (scheduleId) {
url = `${url}/schedules/${scheduleId}`;
body = scheduleTime
? {
action: 'edit',
resource: { run_at: { ...payload.plan.schedules[0].run_at, start_time: scheduleTime } }
}
: { action: 'delete' };
}
return API.post(url, body)
.then(response => {
resolve(response);
let msg = __('Migration successfully unscheduled');
if (payload.scheduleTime) {
if (scheduleTime) {
msg = sprintf(
__('Migration successfully scheduled for %s'),
formatDateTime(response.data.run_at.start_time)
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/react/screens/App/Overview/OverviewReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const initialState = Immutable({
isFetchingNetworks: false,
isRejectedNetworks: false,
scheduleMigrationModal: false,
scheduleMigrationPlanId: null,
scheduleMigrationPlan: {},
isSchedulingMigration: false,
isRejectedSchedulingMigration: false,
errorSchedulingMigration: false
Expand Down Expand Up @@ -362,10 +362,10 @@ export default (state = initialState, action) => {
case V2V_TOGGLE_SCHEDULE_MIGRATION_MODAL:
if (action.payload !== undefined) {
return state
.set('scheduleMigrationPlanId', action.payload.planId)
.set('scheduleMigrationPlan', action.payload.plan)
.set('scheduleMigrationModal', !state.scheduleMigrationModal);
}
return state.set('scheduleMigrationPlanId', null).set('scheduleMigrationModal', !state.scheduleMigrationModal);
return state.set('scheduleMigrationPlan', null).set('scheduleMigrationModal', !state.scheduleMigrationModal);
case `${V2V_SCHEDULE_MIGRATION}_PENDING`:
return state.set('isSchedulingMigration', true).set('isRejectedSchedulingMigration', false);
case `${V2V_SCHEDULE_MIGRATION}_FULFILLED`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Migrations = ({
addNotificationAction,
toggleScheduleMigrationModal,
scheduleMigrationModal,
scheduleMigrationPlanId,
scheduleMigrationPlan,
scheduleMigration
}) => {
const filterOptions = [
Expand Down Expand Up @@ -112,7 +112,7 @@ const Migrations = ({
hideConfirmModalAction={hideConfirmModalAction}
toggleScheduleMigrationModal={toggleScheduleMigrationModal}
scheduleMigrationModal={scheduleMigrationModal}
scheduleMigrationPlanId={scheduleMigrationPlanId}
scheduleMigrationPlan={scheduleMigrationPlan}
scheduleMigration={scheduleMigration}
fetchTransformationPlansAction={fetchTransformationPlansAction}
fetchTransformationPlansUrl={fetchTransformationPlansUrl}
Expand Down Expand Up @@ -141,6 +141,10 @@ const Migrations = ({
fetchTransformationPlansAction={fetchTransformationPlansAction}
fetchTransformationPlansUrl={fetchTransformationPlansUrl}
addNotificationAction={addNotificationAction}
toggleScheduleMigrationModal={toggleScheduleMigrationModal}
scheduleMigrationModal={scheduleMigrationModal}
scheduleMigrationPlan={scheduleMigrationPlan}
scheduleMigration={scheduleMigration}
/>
)}
{activeFilter === MIGRATIONS_FILTERS.archived && (
Expand Down Expand Up @@ -184,7 +188,7 @@ Migrations.propTypes = {
addNotificationAction: PropTypes.func,
toggleScheduleMigrationModal: PropTypes.func,
scheduleMigrationModal: PropTypes.bool,
scheduleMigrationPlanId: PropTypes.string,
scheduleMigrationPlan: PropTypes.string,
scheduleMigration: PropTypes.func
};
Migrations.defaultProps = {
Expand Down
Loading

0 comments on commit 7ac47fb

Please sign in to comment.