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

Commit

Permalink
Filter denied requests into views properly, implement acknowledge den…
Browse files Browse the repository at this point in the history
…ial action
  • Loading branch information
mturley committed Nov 20, 2018
1 parent 4c04f74 commit 70bd78b
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 22 deletions.
12 changes: 10 additions & 2 deletions app/javascript/react/screens/App/Overview/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ class Overview extends React.Component {
fetchTransformationMappingsAction,
openMappingWizardOnTransitionAction,
setMigrationsFilterAction,
initialMigrationsFilterSet
initialMigrationsFilterSet,
acknowledgeDeniedPlanRequestAction,
isEditingPlanRequest
} = this.props;

const mainContent = (
Expand Down Expand Up @@ -311,7 +313,9 @@ class Overview extends React.Component {
fetchTransformationPlansAction={fetchTransformationPlansAction}
fetchTransformationPlansUrl={fetchTransformationPlansUrl}
fetchArchivedTransformationPlansUrl={fetchArchivedTransformationPlansUrl}
isFetchingTransformationPlans={isFetchingTransformationPlans}
isFetchingArchivedTransformationPlans={isFetchingArchivedTransformationPlans}
isFetchingAllRequestsWithTasks={isFetchingAllRequestsWithTasks}
archiveTransformationPlanAction={archiveTransformationPlanAction}
archiveTransformationPlanUrl={archiveTransformationPlanUrl}
deleteTransformationPlanAction={deleteTransformationPlanAction}
Expand All @@ -325,6 +329,8 @@ class Overview extends React.Component {
fetchTransformationMappingsUrl={fetchTransformationMappingsUrl}
fetchTransformationMappingsAction={fetchTransformationMappingsAction}
showEditPlanNameModalAction={showEditPlanNameModalAction}
acknowledgeDeniedPlanRequestAction={acknowledgeDeniedPlanRequestAction}
isEditingPlanRequest={isEditingPlanRequest}
/>
) : (
<ShowWizardEmptyState
Expand Down Expand Up @@ -471,7 +477,9 @@ Overview.propTypes = {
serviceTemplatePlaybooks: PropTypes.array,
redirectTo: PropTypes.func.isRequired,
openMappingWizardOnTransitionAction: PropTypes.func,
initialMigrationsFilterSet: PropTypes.bool
initialMigrationsFilterSet: PropTypes.bool,
acknowledgeDeniedPlanRequestAction: PropTypes.func,
isEditingPlanRequest: PropTypes.bool
};

Overview.defaultProps = {
Expand Down
38 changes: 37 additions & 1 deletion app/javascript/react/screens/App/Overview/OverviewActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
V2V_SCHEDULE_MIGRATION,
V2V_SET_MIGRATIONS_FILTER,
V2V_TOGGLE_SCHEDULE_MIGRATION_MODAL,
SHOW_PLAN_WIZARD_EDIT_MODE
SHOW_PLAN_WIZARD_EDIT_MODE,
V2V_EDIT_PLAN_REQUEST
} from './OverviewConstants';

import { OPEN_V2V_MAPPING_WIZARD_ON_MOUNT } from '../Mappings/MappingsConstants';
Expand Down Expand Up @@ -252,3 +253,38 @@ export const scheduleMigration = payload => dispatch =>
});

export const openMappingWizardOnTransitionAction = () => ({ type: OPEN_V2V_MAPPING_WIZARD_ON_MOUNT });

const _editPlanRequestActionCreator = ({ planRequestUrl, plansUrl, resource }) => dispatch =>
dispatch({
type: V2V_EDIT_PLAN_REQUEST,
payload: new Promise((resolve, reject) =>
API.post(planRequestUrl, { action: 'edit', resource })
.then(response => {
resolve(response);
fetchTransformationPlansAction({
url: plansUrl,
archived: false
})(dispatch);
})
.catch(e => reject(e))
)
});

export const editPlanRequestAction = ({ planRequestUrl, plansUrl, resource }) =>
_editPlanRequestActionCreator({
planRequestUrl: new URI(planRequestUrl).toString(),
plansUrl: new URI(plansUrl).toString(),
resource
});

export const acknowledgeDeniedPlanRequestAction = ({ plansUrl, planRequest }) =>
editPlanRequestAction({
planRequestUrl: planRequest.href,
plansUrl,
resource: {
options: {
...planRequest.options,
denial_acknowledged: true
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const V2V_AUTO_SET_MIGRATIONS_FILTER = 'V2V_AUTO_SET_MIGRATIONS_FILTER';
export const V2V_RETRY_MIGRATION = 'V2V_RETRY_MIGRATION';
export const V2V_TOGGLE_SCHEDULE_MIGRATION_MODAL = 'V2V_TOGGLE_SCHEDULE_MIGRATION_MODAL';
export const V2V_SCHEDULE_MIGRATION = 'V2V_SCHEDULE_MIGRATION';
export const V2V_EDIT_PLAN_REQUEST = 'V2V_EDIT_PLAN_REQUEST';
export const SHOW_CONFIRM_MODAL = 'SHOW_CONFIRM_MODAL';
export const HIDE_CONFIRM_MODAL = 'HIDE_CONFIRM_MODAL';
export const ARCHIVE_TRANSFORMATION_PLAN = 'ARCHIVE_TRANSFORMATION_PLAN';
Expand Down
24 changes: 22 additions & 2 deletions app/javascript/react/screens/App/Overview/OverviewReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
ARCHIVE_TRANSFORMATION_PLAN,
V2V_TOGGLE_SCHEDULE_MIGRATION_MODAL,
V2V_SCHEDULE_MIGRATION,
SHOW_PLAN_WIZARD_EDIT_MODE
SHOW_PLAN_WIZARD_EDIT_MODE,
V2V_EDIT_PLAN_REQUEST
} from './OverviewConstants';

import { planTransmutation, sufficientProviders } from './helpers';
Expand Down Expand Up @@ -88,7 +89,10 @@ export const initialState = Immutable({
isFetchingServiceTemplatePlaybooks: false,
isRejectedServiceTemplatePlaybooks: false,
errorServiceTemplatePlaybooks: null,
initialMigrationsFilterSet: false
initialMigrationsFilterSet: false,
isEditingPlanRequest: false,
isRejectedEditingPlanRequest: false,
errorEditingPlanRequest: null
});

export default (state = initialState, action) => {
Expand Down Expand Up @@ -304,6 +308,22 @@ export default (state = initialState, action) => {
case V2V_AUTO_SET_MIGRATIONS_FILTER:
return state.set('initialMigrationsFilterSet', true);

case `${V2V_EDIT_PLAN_REQUEST}_PENDING`:
return state
.set('isEditingPlanRequest', true)
.set('isRejectedEditingPlanRequest', false)
.set('errorEditingPlanRequest', null);
case `${V2V_EDIT_PLAN_REQUEST}_FULFILLED`:
return state
.set('isEditingPlanRequest', false)
.set('isRejectedEditingPlanRequest', false)
.set('errorEditingPlanRequest', null);
case `${V2V_EDIT_PLAN_REQUEST}_REJECTED`:
return state
.set('isEditingPlanRequest', false)
.set('isRejectedEditingPlanRequest', true)
.set('errorEditingPlanRequest', action.payload);

default:
return state;
}
Expand Down
17 changes: 14 additions & 3 deletions app/javascript/react/screens/App/Overview/OverviewSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const activeTransformationPlansFilter = (transformationPlans, planId) =>
}
if (transformationPlan.miq_requests.length > 0) {
const mostRecentRequest = getMostRecentRequest(transformationPlan.miq_requests);
return mostRecentRequest.request_state === 'active' || mostRecentRequest.request_state === 'pending';
return (
mostRecentRequest.request_state === 'active' ||
mostRecentRequest.request_state === 'pending' ||
(mostRecentRequest.approval_state === 'denied' && !mostRecentRequest.options.denial_acknowledged)
);
}
return false;
});
Expand All @@ -19,7 +23,11 @@ export const finishedTransformationPlansFilter = transformationPlans =>
transformationPlans.filter(transformationPlan => {
if (transformationPlan.miq_requests.length > 0) {
const mostRecentRequest = getMostRecentRequest(transformationPlan.miq_requests);
return mostRecentRequest.request_state === 'finished' || mostRecentRequest.request_state === 'failed';
return (
(mostRecentRequest.request_state === 'finished' && mostRecentRequest.approval_state !== 'denied') ||
mostRecentRequest.request_state === 'failed' ||
(mostRecentRequest.approval_state === 'denied' && mostRecentRequest.options.denial_acknowledged)
);
}
return false;
});
Expand All @@ -28,7 +36,10 @@ export const finishedWithErrorTransformationPlansFilter = transformationPlans =>
transformationPlans.filter(transformationPlan => {
if (transformationPlan.miq_requests.length > 0) {
const mostRecentRequest = getMostRecentRequest(transformationPlan.miq_requests);
return mostRecentRequest.request_state === 'finished' && mostRecentRequest.status === 'Error';
return (
(mostRecentRequest.request_state === 'finished' && mostRecentRequest.status === 'Error') ||
mostRecentRequest.approval_state === 'denied'
);
}
return false;
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class Migrations extends React.Component {
fetchTransformationPlansAction,
fetchTransformationPlansUrl,
fetchArchivedTransformationPlansUrl,
isFetchingTransformationPlans,
isFetchingArchivedTransformationPlans,
isFetchingAllRequestsWithTasks,
archivedTransformationPlans,
allArchivedPlanRequestsWithTasks,
archiveTransformationPlanAction,
Expand All @@ -66,7 +68,9 @@ class Migrations extends React.Component {
showPlanWizardEditModeAction,
fetchTransformationMappingsUrl,
fetchTransformationMappingsAction,
showEditPlanNameModalAction
showEditPlanNameModalAction,
acknowledgeDeniedPlanRequestAction,
isEditingPlanRequest
} = this.props;

const plansExist = transformationPlans.length > 0 || archivedTransformationPlans.length > 0;
Expand Down Expand Up @@ -137,6 +141,11 @@ class Migrations extends React.Component {
reloadCard={reloadCard}
loading={isCreatingTransformationPlanRequest !== null}
redirectTo={redirectTo}
fetchTransformationPlansUrl={fetchTransformationPlansUrl}
acknowledgeDeniedPlanRequestAction={acknowledgeDeniedPlanRequestAction}
isEditingPlanRequest={isEditingPlanRequest}
isFetchingTransformationPlans={isFetchingTransformationPlans}
isFetchingAllRequestsWithTasks={isFetchingAllRequestsWithTasks}
/>
)}
{activeFilter === MIGRATIONS_FILTERS.completed && (
Expand Down Expand Up @@ -214,7 +223,9 @@ Migrations.propTypes = {
fetchArchivedTransformationPlansUrl: PropTypes.string,
archivedTransformationPlans: PropTypes.array,
allArchivedPlanRequestsWithTasks: PropTypes.array,
isFetchingTransformationPlans: PropTypes.bool,
isFetchingArchivedTransformationPlans: PropTypes.string,
isFetchingAllRequestsWithTasks: PropTypes.bool,
archiveTransformationPlanAction: PropTypes.func,
archiveTransformationPlanUrl: PropTypes.string,
deleteTransformationPlanAction: PropTypes.func,
Expand All @@ -227,7 +238,9 @@ Migrations.propTypes = {
showPlanWizardEditModeAction: PropTypes.func,
fetchTransformationMappingsAction: PropTypes.func,
fetchTransformationMappingsUrl: PropTypes.string,
showEditPlanNameModalAction: PropTypes.func
showEditPlanNameModalAction: PropTypes.func,
acknowledgeDeniedPlanRequestAction: PropTypes.func,
isEditingPlanRequest: PropTypes.bool
};
Migrations.defaultProps = {
transformationPlans: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ const MigrationsInProgressCard = ({
serviceTemplatePlaybooks,
allRequestsWithTasks,
reloadCard,
handleClick
handleClick,
fetchTransformationPlansUrl,
acknowledgeDeniedPlanRequestAction,
isEditingPlanRequest,
isFetchingTransformationPlans,
isFetchingAllRequestsWithTasks
}) => {
const requestsOfAssociatedPlan = allRequestsWithTasks.filter(request => request.source_id === plan.id);
const mostRecentRequest = requestsOfAssociatedPlan.length > 0 && getMostRecentRequest(requestsOfAssociatedPlan);
Expand All @@ -47,22 +52,30 @@ const MigrationsInProgressCard = ({
);
}

// TODO: remove plan.name condition here
if (mostRecentRequest.approval_state === 'denied' || plan.name === 'test-denied-state') {
if (mostRecentRequest.approval_state === 'denied') {
const cardEmptyState = (
<EmptyState>
<EmptyState.Icon type="pf" name="error-circle-o" />
<EmptyState.Info style={{ marginTop: 10 }}>
{__('Unable to migrate VMs because no conversion host was configured at the time of the attempted migration.')}{' '}
<a href={DOCS_URL_CONFIGURE_CONVERSION_HOSTS} target="_blank">
{__('Unable to migrate VMs because no conversion host was configured at the time of the attempted migration.') /* prettier-ignore */}{' '}
<a href={DOCS_URL_CONFIGURE_CONVERSION_HOSTS} target="_blank" rel="noopener noreferrer">
{__('See the product documentation for information on configuring conversion hosts.')}
</a>
</EmptyState.Info>
</EmptyState>
);
const cardFooter = (
<Card.Footer style={{ position: 'relative', top: '-2px' }}>
<Button style={{ position: 'relative', top: '-5px' }} onClick={() => alert('TODO: handle cancel')}>
<Button
style={{ position: 'relative', top: '-5px' }}
onClick={() =>
acknowledgeDeniedPlanRequestAction({
plansUrl: fetchTransformationPlansUrl,
planRequest: mostRecentRequest
})
}
disabled={isEditingPlanRequest || isFetchingTransformationPlans || isFetchingAllRequestsWithTasks}
>
{__('Cancel Migration')}
</Button>
</Card.Footer>
Expand Down Expand Up @@ -281,7 +294,12 @@ MigrationsInProgressCard.propTypes = {
serviceTemplatePlaybooks: PropTypes.array,
allRequestsWithTasks: PropTypes.array,
reloadCard: PropTypes.bool,
handleClick: PropTypes.func
handleClick: PropTypes.func,
fetchTransformationPlansUrl: PropTypes.string,
acknowledgeDeniedPlanRequestAction: PropTypes.func,
isEditingPlanRequest: PropTypes.bool,
isFetchingTransformationPlans: PropTypes.bool,
isFetchingAllRequestsWithTasks: PropTypes.bool
};

export default MigrationsInProgressCard;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ const MigrationsInProgressCards = ({
allRequestsWithTasks,
reloadCard,
loading,
redirectTo
redirectTo,
fetchTransformationPlansUrl,
acknowledgeDeniedPlanRequestAction,
isEditingPlanRequest,
isFetchingTransformationPlans,
isFetchingAllRequestsWithTasks
}) => (
<div className="row-cards-pf">
<Grid.Row>
Expand All @@ -29,6 +34,11 @@ const MigrationsInProgressCards = ({
reloadCard={reloadCard}
key={plan.id}
handleClick={redirectTo}
fetchTransformationPlansUrl={fetchTransformationPlansUrl}
acknowledgeDeniedPlanRequestAction={acknowledgeDeniedPlanRequestAction}
isEditingPlanRequest={isEditingPlanRequest}
isFetchingTransformationPlans={isFetchingTransformationPlans}
isFetchingAllRequestsWithTasks={isFetchingAllRequestsWithTasks}
/>
))
) : (
Expand All @@ -52,7 +62,12 @@ MigrationsInProgressCards.propTypes = {
allRequestsWithTasks: PropTypes.array,
reloadCard: PropTypes.bool,
loading: PropTypes.bool,
redirectTo: PropTypes.func
redirectTo: PropTypes.func,
fetchTransformationPlansUrl: PropTypes.string,
acknowledgeDeniedPlanRequestAction: PropTypes.func,
isEditingPlanRequest: PropTypes.bool,
isFetchingTransformationPlans: PropTypes.bool,
isFetchingAllRequestsWithTasks: PropTypes.bool
};

MigrationsInProgressCards.defaultProps = {
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/react/screens/App/Plan/Plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ class Plan extends React.Component {
iconName="error-circle-o"
description={
<React.Fragment>
{__('Unable to migrate VMs because no conversion host was configured at the time of the attempted migration.')}{' '}
<a href={DOCS_URL_CONFIGURE_CONVERSION_HOSTS} target="_blank">
{__('Unable to migrate VMs because no conversion host was configured at the time of the attempted migration.') /* prettier-ignore */}{' '}
<a href={DOCS_URL_CONFIGURE_CONVERSION_HOSTS} target="_blank" rel="noopener noreferrer">
{__('See the product documentation for information on configuring conversion hosts.')}
</a>
</React.Fragment>
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/react/screens/App/Plan/PlanConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ STATUS_MESSAGES[STATUS_MESSAGE_KEYS.CANCELLED] = __('VM cancelled');
export { STATUS_MESSAGES as V2V_MIGRATION_STATUS_MESSAGES };

// TODO FIXME this is a 404:
export const DOCS_URL_CONFIGURE_CONVERSION_HOSTS = "https://access.redhat.com/documentation/en-us/red_hat_infrastructure_migration_solution/1.0/html/infrastructure_migration_solution_guide/installation#rhv_conversion_hosts";
export const DOCS_URL_CONFIGURE_CONVERSION_HOSTS =
'https://access.redhat.com/documentation/en-us/red_hat_infrastructure_migration_solution/1.0/html/infrastructure_migration_solution_guide/installation#rhv_conversion_hosts';

0 comments on commit 70bd78b

Please sign in to comment.