]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12292 Do not debounce the fetchBranchStatus root action
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Wed, 17 Jul 2019 07:40:55 +0000 (09:40 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 2 Aug 2019 18:21:14 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/code/components/App.tsx
server/sonar-web/src/main/js/apps/component-measures/components/App.tsx
server/sonar-web/src/main/js/apps/issues/components/App.tsx
server/sonar-web/src/main/js/components/workspace/WorkspaceComponentViewer.tsx
server/sonar-web/src/main/js/store/__tests__/rootActions-test.tsx
server/sonar-web/src/main/js/store/rootActions.ts

index 226abca45d48877bc90e78028919d8eacda2c4f0..ce34389013df587cced53e4c543c23feb349c890 100644 (file)
@@ -19,6 +19,7 @@
  */
 import * as classNames from 'classnames';
 import { Location } from 'history';
+import { debounce } from 'lodash';
 import * as React from 'react';
 import Helmet from 'react-helmet';
 import { connect } from 'react-redux';
@@ -71,12 +72,18 @@ interface State {
 
 export class App extends React.PureComponent<Props, State> {
   mounted = false;
-  state: State = {
-    breadcrumbs: [],
-    loading: true,
-    page: 0,
-    total: 0
-  };
+  state: State;
+
+  constructor(props: Props) {
+    super(props);
+    this.state = {
+      breadcrumbs: [],
+      loading: true,
+      page: 0,
+      total: 0
+    };
+    this.refreshBranchStatus = debounce(this.refreshBranchStatus, 1000);
+  }
 
   componentDidMount() {
     this.mounted = true;
index c4a1ca98825e216484fa9a2ce6f9663e66e04bdc..71e0c6f3c84b3973532495b48f71539ea1dad640 100644 (file)
@@ -18,7 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import * as key from 'keymaster';
-import { keyBy } from 'lodash';
+import { debounce, keyBy } from 'lodash';
 import * as React from 'react';
 import Helmet from 'react-helmet';
 import { connect } from 'react-redux';
@@ -82,11 +82,17 @@ interface State {
 
 export class App extends React.PureComponent<Props, State> {
   mounted = false;
-  state: State = {
-    loading: true,
-    measures: [],
-    metrics: {}
-  };
+  state: State;
+
+  constructor(props: Props) {
+    super(props);
+    this.state = {
+      loading: true,
+      measures: [],
+      metrics: {}
+    };
+    this.refreshBranchStatus = debounce(this.refreshBranchStatus, 1000);
+  }
 
   componentDidMount() {
     this.mounted = true;
index 8885d0ec8b89d41db24dcd4bb55093e96d44642c..aeab5a9b2b884c7acba1d8a963d51f7da59a8969 100644 (file)
@@ -18,7 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import * as key from 'keymaster';
-import { keyBy, omit, without } from 'lodash';
+import { debounce, keyBy, omit, without } from 'lodash';
 import * as React from 'react';
 import Helmet from 'react-helmet';
 import { FormattedMessage } from 'react-intl';
@@ -175,6 +175,7 @@ export class App extends React.PureComponent<Props, State> {
       referencedUsers: {},
       selected: getOpen(props.location.query)
     };
+    this.refreshBranchStatus = debounce(this.refreshBranchStatus, 1000);
   }
 
   componentDidMount() {
index 23f0ab0d42dd86bd9d6228a0278471b81b9a4cba..e33e921db80f433303c36e1b70eef992cc190310 100644 (file)
@@ -19,6 +19,7 @@
  */
 import * as React from 'react';
 import { connect } from 'react-redux';
+import { debounce } from 'lodash';
 import { scrollToElement } from 'sonar-ui-common/helpers/scrolling';
 import { getParents } from '../../api/components';
 import { isPullRequest, isShortLivingBranch } from '../../helpers/branches';
@@ -39,6 +40,11 @@ export interface Props extends T.Omit<WorkspaceHeaderProps, 'children' | 'onClos
 export class WorkspaceComponentViewer extends React.PureComponent<Props> {
   container?: HTMLElement | null;
 
+  constructor(props: Props) {
+    super(props);
+    this.refreshBranchStatus = debounce(this.refreshBranchStatus, 1000);
+  }
+
   componentDidMount() {
     if (document.documentElement) {
       document.documentElement.classList.add('with-workspace');
index 4828f7559f0b7be7c7adfc702d024104c87f875a..d4f9c887b64b94793b73b93ec723e57577c06aa3 100644 (file)
@@ -21,8 +21,6 @@ import { mockLongLivingBranch, mockQualityGateStatusCondition } from '../../help
 import { registerBranchStatusAction } from '../branches';
 import { fetchBranchStatus, registerBranchStatus } from '../rootActions';
 
-jest.useFakeTimers();
-
 jest.mock('../branches', () => ({
   ...require.requireActual('../branches'),
   registerBranchStatusAction: jest.fn()
@@ -65,8 +63,6 @@ describe('branch store actions', () => {
     const dispatch = jest.fn();
 
     fetchBranchStatus(branchLike, component)(dispatch);
-
-    jest.runAllTimers();
     await new Promise(setImmediate);
 
     expect(registerBranchStatusAction).toBeCalledWith(
index f7ffb9022cb7c3dd6283afe3da0c310134bf60bc..f77391118cbcf5eb19e0715d7756212f7fffc3cf 100644 (file)
@@ -17,7 +17,6 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { debounce } from 'lodash';
 import { InjectedRouter } from 'react-router';
 import { Dispatch } from 'redux';
 import * as auth from '../api/auth';
@@ -67,7 +66,7 @@ export const fetchOrganization = (key: string) => (dispatch: Dispatch) => {
 };
 
 export function fetchBranchStatus(branchLike: T.BranchLike, projectKey: string) {
-  return debounce((dispatch: Dispatch<any>) => {
+  return (dispatch: Dispatch<any>) => {
     getQualityGateProjectStatus({ projectKey, ...getBranchLikeQuery(branchLike) }).then(
       projectStatus => {
         const { ignoredConditions, status } = projectStatus;
@@ -80,7 +79,7 @@ export function fetchBranchStatus(branchLike: T.BranchLike, projectKey: string)
         dispatch(addGlobalErrorMessage('Fetching Quality Gate status failed'));
       }
     );
-  }, 1000);
+  };
 }
 
 export function doLogin(login: string, password: string) {