]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21017 Automatic batching change: setState calls are now batched at the end...
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>
Thu, 23 Nov 2023 14:26:09 +0000 (15:26 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 24 Nov 2023 20:02:45 +0000 (20:02 +0000)
(see https://react.dev/blog/2022/03/08/react-18-upgrade-guide#automatic-batching)

server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx
server/sonar-web/src/main/js/apps/create/project/BitbucketCloud/BitbucketCloudProjectCreate.tsx
server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx
server/sonar-web/src/main/js/apps/create/project/Gitlab/GitlabProjectCreate.tsx
server/sonar-web/src/main/js/components/controls/clipboard.tsx

index bf418da89e310465d506b9a832ffaf0b1a1e6957..a68399b7ea4b24f4d9da049f56f9d53c760344c3 100644 (file)
@@ -223,10 +223,12 @@ export default class AzureProjectCreate extends React.PureComponent<Props, State
     }
   };
 
-  handlePersonalAccessTokenCreate = async () => {
-    this.setState({ showPersonalAccessTokenForm: false });
+  handlePersonalAccessTokenCreate = () => {
     this.cleanUrl();
-    await this.fetchData();
+
+    this.setState({ showPersonalAccessTokenForm: false }, () => {
+      this.fetchData();
+    });
   };
 
   onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => {
index 870ffe5c33b2a47f8b6b033d33e05b3e1f72c5f8..fea934a0bbd1d1abd999bdf6599afdaa6f610d38 100644 (file)
@@ -84,12 +84,16 @@ export default class BitbucketCloudProjectCreate extends React.PureComponent<Pro
     }
   }
 
-  handlePersonalAccessTokenCreated = async () => {
-    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 = () => {
index d6f7d6815bbfb39bed2d293183924cfbf91c24ed..ecd53c02ba9a4e4a5dff28c8613fd26863f62854 100644 (file)
@@ -174,10 +174,12 @@ export default class BitbucketProjectCreate extends React.PureComponent<Props, S
     router.replace(location);
   };
 
-  handlePersonalAccessTokenCreated = async () => {
-    this.setState({ showPersonalAccessTokenForm: false });
+  handlePersonalAccessTokenCreated = () => {
     this.cleanUrl();
-    await this.fetchInitialData();
+
+    this.setState({ showPersonalAccessTokenForm: false }, () => {
+      this.fetchInitialData();
+    });
   };
 
   handleImportRepository = (selectedRepository: BitbucketRepository) => {
index e2032788c0fe61c94652bf5e10f7fb5d047b11e8..6bb0c1cbc5c322bfa640774d61aa8c511015e5c1 100644 (file)
@@ -185,10 +185,11 @@ export default class GitlabProjectCreate extends React.PureComponent<Props, Stat
     router.replace(location);
   };
 
-  handlePersonalAccessTokenCreated = async () => {
-    this.setState({ showPersonalAccessTokenForm: false, resetPat: false });
+  handlePersonalAccessTokenCreated = () => {
     this.cleanUrl();
-    await this.fetchInitialData();
+    this.setState({ showPersonalAccessTokenForm: false, resetPat: false }, () => {
+      this.fetchInitialData();
+    });
   };
 
   onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => {
index f7f4204a07eecdbdd44e0d6ebe2df07dc681e1c4..db2623aa978ca3954b284b316a66ff88e0ad71ea 100644 (file)
@@ -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<Props, State> {
 
   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);
+      });
     }
   };