]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Improve alm error handling UI
authorMathieu Suen <mathieu.suen@sonarsource.com>
Wed, 25 Jan 2023 10:20:28 +0000 (11:20 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 27 Jan 2023 20:03:16 +0000 (20:03 +0000)
Signed-off-by: Mathieu Suen <mathieu.suen@sonarsource.com>
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx

index 507cd0d1feb6d1278c6713778fa9f78af1fd21a2..2987ee7c7d61fd51e6e949e1d25eb0a684cc62d7 100644 (file)
@@ -96,7 +96,7 @@ export class AlmIntegration extends React.PureComponent<Props, State> {
           AlmKeys.GitHub,
           AlmKeys.GitLab,
         ].forEach((alm) => {
-          this.state.definitions[alm].forEach((def: AlmBindingDefinitionBase) =>
+          definitions[alm].forEach((def: AlmBindingDefinitionBase) =>
             this.handleCheck(def.key, false)
           );
         });
@@ -115,33 +115,34 @@ export class AlmIntegration extends React.PureComponent<Props, State> {
     this.mounted = false;
   }
 
-  handleConfirmDelete = (definitionKey: string) => {
-    return deleteConfiguration(definitionKey)
-      .then(() => {
-        if (this.mounted) {
-          this.setState({ definitionKeyForDeletion: undefined, projectCount: undefined });
-        }
-      })
-      .then(this.fetchPullRequestDecorationSetting);
+  handleConfirmDelete = async (definitionKey: string) => {
+    try {
+      await deleteConfiguration(definitionKey);
+      await this.fetchPullRequestDecorationSetting();
+    } finally {
+      if (this.mounted) {
+        this.setState({ definitionKeyForDeletion: undefined, projectCount: undefined });
+      }
+    }
   };
 
-  fetchPullRequestDecorationSetting = () => {
+  fetchPullRequestDecorationSetting = async () => {
     this.setState({ loadingAlmDefinitions: true });
-    return getAlmDefinitions()
-      .then((definitions) => {
-        if (this.mounted) {
-          this.setState({
-            definitions,
-            loadingAlmDefinitions: false,
-          });
-          return definitions;
-        }
-      })
-      .catch(() => {
-        if (this.mounted) {
-          this.setState({ loadingAlmDefinitions: false });
-        }
-      });
+    try {
+      const definitions = await getAlmDefinitions();
+
+      if (this.mounted) {
+        this.setState({
+          definitions,
+          loadingAlmDefinitions: false,
+        });
+      }
+      return definitions;
+    } catch {
+      if (this.mounted) {
+        this.setState({ loadingAlmDefinitions: false });
+      }
+    }
   };
 
   handleSelectAlm = (currentAlmTab: AlmTabs) => {