]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Fix some bugs and code smells
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>
Wed, 14 Jun 2023 15:03:04 +0000 (17:03 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 15 Jun 2023 20:03:01 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/permissions/global/components/PermissionsGlobalApp.tsx
server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx
server/sonar-web/src/main/js/components/activity-graph/AddGraphMetricPopup.tsx

index e6b1563d1858f9e491a78f46f607d95d0140074b..ffe8ae439a3d23617d59dab6ddef6c6f4e3c7ec9 100644 (file)
@@ -97,7 +97,8 @@ class PermissionsGlobalApp extends React.PureComponent<Props, State> {
 
   loadHolders = () => {
     this.setState({ loading: true });
-    return this.loadUsersAndGroups().then(([usersResponse, groupsResponse]) => {
+
+    this.loadUsersAndGroups().then(([usersResponse, groupsResponse]) => {
       if (this.mounted) {
         this.setState({
           groups: groupsResponse.groups,
@@ -113,7 +114,8 @@ class PermissionsGlobalApp extends React.PureComponent<Props, State> {
   handleLoadMore = () => {
     const { usersPaging, groupsPaging } = this.state;
     this.setState({ loading: true });
-    return this.loadUsersAndGroups(
+
+    this.loadUsersAndGroups(
       usersPaging ? usersPaging.pageIndex + 1 : 1,
       groupsPaging ? groupsPaging.pageIndex + 1 : 1
     ).then(([usersResponse, groupsResponse]) => {
index 8850f8c033b3efb53f2f2cb0f7a25c53ddfc7804..fa2da7b9afbb9756764a0a136b1290b41a9135a5 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { without } from 'lodash';
+import { noop, without } from 'lodash';
 import * as React from 'react';
 import { Helmet } from 'react-helmet-async';
 import * as api from '../../../../api/permissions';
@@ -27,8 +27,8 @@ import AllHoldersList from '../../../../components/permissions/AllHoldersList';
 import { FilterOption } from '../../../../components/permissions/SearchForm';
 import { translate } from '../../../../helpers/l10n';
 import {
-  convertToPermissionDefinitions,
   PERMISSIONS_ORDER_BY_QUALIFIER,
+  convertToPermissionDefinitions,
 } from '../../../../helpers/permissions';
 import { ComponentContextShape, Visibility } from '../../../../types/component';
 import { Permissions } from '../../../../types/permissions';
@@ -106,7 +106,8 @@ class PermissionsProjectApp extends React.PureComponent<Props, State> {
 
   loadHolders = () => {
     this.setState({ loading: true });
-    return this.loadUsersAndGroups().then(([usersResponse, groupsResponse]) => {
+
+    this.loadUsersAndGroups().then(([usersResponse, groupsResponse]) => {
       if (this.mounted) {
         this.setState({
           groups: groupsResponse.groups,
@@ -122,7 +123,8 @@ class PermissionsProjectApp extends React.PureComponent<Props, State> {
   handleLoadMore = () => {
     const { usersPaging, groupsPaging } = this.state;
     this.setState({ loading: true });
-    return this.loadUsersAndGroups(
+
+    this.loadUsersAndGroups(
       usersPaging ? usersPaging.pageIndex + 1 : 1,
       groupsPaging ? groupsPaging.pageIndex + 1 : 1
     ).then(([usersResponse, groupsResponse]) => {
@@ -276,18 +278,26 @@ class PermissionsProjectApp extends React.PureComponent<Props, State> {
 
   handleTurnProjectToPublic = () => {
     this.setState({ loading: true });
-    return api.changeProjectVisibility(this.props.component.key, Visibility.Public).then(() => {
-      this.props.onComponentChange({ visibility: Visibility.Public });
-      this.loadHolders();
-    });
+
+    api
+      .changeProjectVisibility(this.props.component.key, Visibility.Public)
+      .then(() => {
+        this.props.onComponentChange({ visibility: Visibility.Public });
+        this.loadHolders();
+      })
+      .catch(noop);
   };
 
   turnProjectToPrivate = () => {
     this.setState({ loading: true });
-    return api.changeProjectVisibility(this.props.component.key, Visibility.Private).then(() => {
-      this.props.onComponentChange({ visibility: Visibility.Private });
-      this.loadHolders();
-    });
+
+    api
+      .changeProjectVisibility(this.props.component.key, Visibility.Private)
+      .then(() => {
+        this.props.onComponentChange({ visibility: Visibility.Private });
+        this.loadHolders();
+      })
+      .catch(noop);
   };
 
   openDisclaimer = () => {
index 0c3bf80f84f715dfd17e5a2b8cd1881312f1ee40..086602f12d38f063973847b98628c05d464508fc 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+import { noop } from 'lodash';
 import * as React from 'react';
 import {
   countBoundProjects,
@@ -176,7 +177,7 @@ export class AlmIntegration extends React.PureComponent<Props, State> {
       });
   };
 
-  handleCheck = async (definitionKey: string, alertSuccess = true) => {
+  handleCheck = (definitionKey: string, alertSuccess = true) => {
     this.setState(({ definitionStatus }) => {
       definitionStatus[definitionKey] = {
         ...definitionStatus[definitionKey],
@@ -186,29 +187,31 @@ export class AlmIntegration extends React.PureComponent<Props, State> {
       return { definitionStatus: { ...definitionStatus } };
     });
 
-    let type: AlmSettingsBindingStatusType;
-    let failureMessage = '';
-
-    try {
-      failureMessage = await validateAlmSettings(definitionKey);
-      type = failureMessage
-        ? AlmSettingsBindingStatusType.Failure
-        : AlmSettingsBindingStatusType.Success;
-    } catch (_) {
-      type = AlmSettingsBindingStatusType.Warning;
-    }
-
-    if (this.mounted) {
-      this.setState(({ definitionStatus }) => {
-        definitionStatus[definitionKey] = {
-          alertSuccess,
-          failureMessage,
-          type,
-        };
-
-        return { definitionStatus: { ...definitionStatus } };
-      });
-    }
+    validateAlmSettings(definitionKey)
+      .then(
+        (failureMessage) => {
+          const type = failureMessage
+            ? AlmSettingsBindingStatusType.Failure
+            : AlmSettingsBindingStatusType.Success;
+
+          return { type, failureMessage };
+        },
+        () => ({ type: AlmSettingsBindingStatusType.Warning, failureMessage: '' })
+      )
+      .then(({ type, failureMessage }) => {
+        if (this.mounted) {
+          this.setState(({ definitionStatus }) => {
+            definitionStatus[definitionKey] = {
+              alertSuccess,
+              failureMessage,
+              type,
+            };
+
+            return { definitionStatus: { ...definitionStatus } };
+          });
+        }
+      })
+      .catch(noop);
   };
 
   render() {
index 1ee9f58319d8a5420b0d8f03c99af8ef1628ba66..583b849a2f4ef35d232b5f76acf83994e62a1b01 100644 (file)
@@ -54,7 +54,7 @@ export default function AddGraphMetricPopup({
           'project_activity.graphs.custom.type_x_message',
           metricsTypeFilter
             .map((type: string) => translate('metric.type', type))
-            .sort()
+            .sort((a, b) => a.localeCompare(b))
             .join(', ')
         )}
       </Alert>