From: David Cho-Lerat Date: Thu, 23 Nov 2023 14:26:09 +0000 (+0100) Subject: SONAR-21017 Automatic batching change: setState calls are now batched at the end... X-Git-Tag: 10.4.0.87286~407 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2ee783369a7ff0eb39b524b480434f6e74132064;p=sonarqube.git SONAR-21017 Automatic batching change: setState calls are now batched at the end of the scope (see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#automatic-batching) --- diff --git a/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx index bf418da89e3..a68399b7ea4 100644 --- a/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx @@ -223,10 +223,12 @@ export default class AzureProjectCreate extends React.PureComponent { - this.setState({ showPersonalAccessTokenForm: false }); + handlePersonalAccessTokenCreate = () => { this.cleanUrl(); - await this.fetchData(); + + this.setState({ showPersonalAccessTokenForm: false }, () => { + this.fetchData(); + }); }; onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => { diff --git a/server/sonar-web/src/main/js/apps/create/project/BitbucketCloud/BitbucketCloudProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/BitbucketCloud/BitbucketCloudProjectCreate.tsx index 870ffe5c33b..fea934a0bbd 100644 --- a/server/sonar-web/src/main/js/apps/create/project/BitbucketCloud/BitbucketCloudProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/BitbucketCloud/BitbucketCloudProjectCreate.tsx @@ -84,12 +84,16 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent { - this.setState({ showPersonalAccessTokenForm: false }); + handlePersonalAccessTokenCreated = () => { this.cleanUrl(); - this.setState({ loading: true }); - await this.fetchData(); - this.setState({ loading: false }); + + this.setState({ loading: true, showPersonalAccessTokenForm: false }, () => { + this.fetchData() + .then(() => this.setState({ loading: false })) + .catch(() => { + /* noop */ + }); + }); }; cleanUrl = () => { diff --git a/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx index d6f7d6815bb..ecd53c02ba9 100644 --- a/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx @@ -174,10 +174,12 @@ export default class BitbucketProjectCreate extends React.PureComponent { - this.setState({ showPersonalAccessTokenForm: false }); + handlePersonalAccessTokenCreated = () => { this.cleanUrl(); - await this.fetchInitialData(); + + this.setState({ showPersonalAccessTokenForm: false }, () => { + this.fetchInitialData(); + }); }; handleImportRepository = (selectedRepository: BitbucketRepository) => { diff --git a/server/sonar-web/src/main/js/apps/create/project/Gitlab/GitlabProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/Gitlab/GitlabProjectCreate.tsx index e2032788c0f..6bb0c1cbc5c 100644 --- a/server/sonar-web/src/main/js/apps/create/project/Gitlab/GitlabProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/Gitlab/GitlabProjectCreate.tsx @@ -185,10 +185,11 @@ export default class GitlabProjectCreate extends React.PureComponent { - this.setState({ showPersonalAccessTokenForm: false, resetPat: false }); + handlePersonalAccessTokenCreated = () => { this.cleanUrl(); - await this.fetchInitialData(); + this.setState({ showPersonalAccessTokenForm: false, resetPat: false }, () => { + this.fetchInitialData(); + }); }; onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => { diff --git a/server/sonar-web/src/main/js/components/controls/clipboard.tsx b/server/sonar-web/src/main/js/components/controls/clipboard.tsx index f7f4204a07e..db2623aa978 100644 --- a/server/sonar-web/src/main/js/components/controls/clipboard.tsx +++ b/server/sonar-web/src/main/js/components/controls/clipboard.tsx @@ -22,8 +22,8 @@ import Clipboard from 'clipboard'; import * as React from 'react'; import { translate } from '../../helpers/l10n'; import CopyIcon from '../icons/CopyIcon'; -import { Button, ButtonIcon } from './buttons'; import Tooltip from './Tooltip'; +import { Button, ButtonIcon } from './buttons'; export interface State { copySuccess: boolean; @@ -75,15 +75,16 @@ export class ClipboardBase extends React.PureComponent { handleSuccessCopy = () => { if (this.mounted) { - this.setState({ copySuccess: true }); - if (this.copyButton) { - this.copyButton.focus(); - } - setTimeout(() => { - if (this.mounted) { - this.setState({ copySuccess: false }); + this.setState({ copySuccess: true }, () => { + if (this.copyButton) { + this.copyButton.focus(); } - }, 1000); + setTimeout(() => { + if (this.mounted) { + this.setState({ copySuccess: false }); + } + }, 1000); + }); } };