]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13355 Deleting an Application should redirect to the homepage
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Mon, 8 Jun 2020 12:46:55 +0000 (14:46 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 15 Jun 2020 20:05:15 +0000 (20:05 +0000)
server/sonar-web/src/main/js/apps/projectDeletion/Form.tsx

index 86af7437951b3c955732a8d7c7c68777e1e36e62..f179ec2fed2f9a7b2383bc1957c2b2fff38b3222 100644 (file)
@@ -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<T.Component, 'key' | 'name' | 'qualifier'>;
@@ -31,17 +32,18 @@ interface Props {
 }
 
 export class Form extends React.PureComponent<Props> {
-  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() {