From 9266050ff354fe508082c7930538d5a2702fcd26 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Mon, 8 Jun 2020 14:46:55 +0200 Subject: [PATCH] SONAR-13355 Deleting an Application should redirect to the homepage --- .../src/main/js/apps/projectDeletion/Form.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projectDeletion/Form.tsx b/server/sonar-web/src/main/js/apps/projectDeletion/Form.tsx index 86af7437951..f179ec2fed2 100644 --- a/server/sonar-web/src/main/js/apps/projectDeletion/Form.tsx +++ b/server/sonar-web/src/main/js/apps/projectDeletion/Form.tsx @@ -24,6 +24,7 @@ import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n import { deletePortfolio, deleteProject } from '../../api/components'; import addGlobalSuccessMessage from '../../app/utils/addGlobalSuccessMessage'; import { Router, withRouter } from '../../components/hoc/withRouter'; +import { ComponentQualifier, isPortfolioLike } from '../../types/component'; interface Props { component: Pick; @@ -31,17 +32,18 @@ interface Props { } export class Form extends React.PureComponent { - handleDelete = () => { + handleDelete = async () => { const { component } = this.props; - const isProject = component.qualifier === 'TRK'; - const deleteMethod = isProject ? deleteProject : deletePortfolio; - const redirectTo = isProject ? '/' : '/portfolios'; - return deleteMethod(component.key).then(() => { - addGlobalSuccessMessage( - translateWithParameters('project_deletion.resource_deleted', component.name) - ); - this.props.router.replace(redirectTo); - }); + const deleteMethod = + component.qualifier === ComponentQualifier.Project ? deleteProject : deletePortfolio; + const redirectTo = isPortfolioLike(component.qualifier) ? '/portfolios' : '/'; + + await deleteMethod(component.key); + + addGlobalSuccessMessage( + translateWithParameters('project_deletion.resource_deleted', component.name) + ); + this.props.router.replace(redirectTo); }; render() { -- 2.39.5