From: David Cho-Lerat Date: Wed, 14 Jun 2023 15:03:04 +0000 (+0200) Subject: [NO JIRA] Fix some bugs and code smells X-Git-Tag: 10.1.0.73491~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=122d7acf757fefe990c6d855183e9a0dd68d502a;p=sonarqube.git [NO JIRA] Fix some bugs and code smells --- diff --git a/server/sonar-web/src/main/js/apps/permissions/global/components/PermissionsGlobalApp.tsx b/server/sonar-web/src/main/js/apps/permissions/global/components/PermissionsGlobalApp.tsx index e6b1563d185..ffe8ae439a3 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/components/PermissionsGlobalApp.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/global/components/PermissionsGlobalApp.tsx @@ -97,7 +97,8 @@ class PermissionsGlobalApp extends React.PureComponent { 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 { 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]) => { diff --git a/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx b/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx index 8850f8c033b..fa2da7b9afb 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/project/components/PermissionsProjectApp.tsx @@ -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 { 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 { 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 { 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 = () => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx index 0c3bf80f84f..086602f12d3 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx @@ -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 { }); }; - 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 { 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() { diff --git a/server/sonar-web/src/main/js/components/activity-graph/AddGraphMetricPopup.tsx b/server/sonar-web/src/main/js/components/activity-graph/AddGraphMetricPopup.tsx index 1ee9f58319d..583b849a2f4 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/AddGraphMetricPopup.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/AddGraphMetricPopup.tsx @@ -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(', ') )}