]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10178 Pending notification should not filter tasks
authorStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 9 Jan 2018 09:09:03 +0000 (10:09 +0100)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 9 Jan 2018 19:16:51 +0000 (20:16 +0100)
server/sonar-web/src/main/js/api/ce.ts
server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap
server/sonar-web/src/main/js/apps/tutorials/onboarding/ProjectWatcher.js
server/sonar-web/src/main/js/helpers/urls.ts

index 31ae8e100468f054796c791eceeb3898d576e9bc..c9c16350492a7252d168ddde19b15f4ad556f7ac 100644 (file)
@@ -90,11 +90,8 @@ export function cancelAllTasks(): Promise<any> {
 
 export function getTasksForComponent(
   componentKey: string
-): Promise<{
-  queue: PendingTask[];
-  current: Task;
-}> {
-  return getJSON('/api/ce/component', { componentKey });
+): Promise<{ queue: PendingTask[]; current: Task }> {
+  return getJSON('/api/ce/component', { componentKey }).catch(throwGlobalError);
 }
 
 export function getTypes(): Promise<any> {
index 7d4cd23592515a822cb0d2c2765657b14f4c328f..39925c34c99fd04073d541aaa675f76adba905ee 100644 (file)
@@ -75,7 +75,8 @@ export default class ComponentNav extends React.PureComponent<Props, State> {
             isPending: r.queue.some(task => task.status === STATUSES.PENDING)
           });
         }
-      }
+      },
+      () => {}
     );
   };
 
index 5b906826ecc7fda2692dff3320fae3ddf0a63ff3..9680f0e1c9b96042bbad0ebc6769c8ecb24cb879 100644 (file)
@@ -41,11 +41,11 @@ export default class ComponentNavBgTaskNotif extends React.PureComponent<Props>
     canAdmin: PropTypes.bool.isRequired
   };
 
-  renderMessage(messageKey: string) {
+  renderMessage(messageKey: string, status?: string) {
     const { component } = this.props;
     const canSeeBackgroundTasks =
-      component.configuration !== undefined && component.configuration.showBackgroundTasks;
-    const bgTaskUrl = getComponentBackgroundTaskUrl(component.key);
+      component.configuration && component.configuration.showBackgroundTasks;
+    const bgTaskUrl = getComponentBackgroundTaskUrl(component.key, status);
 
     if (canSeeBackgroundTasks) {
       return (
@@ -76,7 +76,7 @@ export default class ComponentNavBgTaskNotif extends React.PureComponent<Props>
       return (
         <NavBarNotif className="alert alert-info">
           <PendingIcon className="spacer-right" />
-          {this.renderMessage('component_navigation.status.pending')}
+          {this.renderMessage('component_navigation.status.pending', STATUSES.ALL)}
         </NavBarNotif>
       );
     } else if (currentTask && currentTask.status === STATUSES.FAILED) {
index e5441faa51fb5315ad7b4460a6d9d1175ed7f318..c149ae037b8b97ef6bab945f1690bd27332e3b76 100644 (file)
@@ -47,6 +47,15 @@ it('renders background task pending info correctly', () => {
   expect(getWrapper({ isPending: true })).toMatchSnapshot();
 });
 
+it('renders background task pending info correctly for admin', () => {
+  expect(
+    getWrapper({
+      component: { ...component, configuration: { showBackgroundTasks: true } },
+      isPending: true
+    })
+  ).toMatchSnapshot();
+});
+
 it('renders background task in progress info correctly', () => {
   expect(getWrapper({ isInProgress: true, isPending: true })).toMatchSnapshot();
 });
index 679067cb000c8a2e8022ff7caaa716a5627c643a..bb69e51c46d330324f127f3e5877cba165940a32 100644 (file)
@@ -54,3 +54,36 @@ exports[`renders background task pending info correctly 1`] = `
   </span>
 </NavBarNotif>
 `;
+
+exports[`renders background task pending info correctly for admin 1`] = `
+<NavBarNotif
+  className="alert alert-info"
+>
+  <PendingIcon
+    className="spacer-right"
+  />
+  <FormattedMessage
+    defaultMessage="component_navigation.status.pending.admin"
+    id="component_navigation.status.pending.admin"
+    values={
+      Object {
+        "url": <Link
+          onlyActiveOnIndex={false}
+          style={Object {}}
+          to={
+            Object {
+              "pathname": "/project/background_tasks",
+              "query": Object {
+                "id": "foo",
+                "status": "__ALL__",
+              },
+            }
+          }
+        >
+          background_tasks.page
+        </Link>,
+      }
+    }
+  />
+</NavBarNotif>
+`;
index 252fdbb7f6cff8ece290c1559d1a818d2df24e44..86813dca37dd5ebaa0853a58131a6eb78e3833b7 100644 (file)
@@ -67,23 +67,26 @@ export default class ProjectWatcher extends React.PureComponent {
 
   checkProject = () => {
     const { projectKey } = this.props;
-    getTasksForComponent(projectKey).then(response => {
-      if (response.queue.length > 0) {
-        this.setState({ inQueue: true });
-      }
+    getTasksForComponent(projectKey).then(
+      response => {
+        if (response.queue.length > 0) {
+          this.setState({ inQueue: true });
+        }
 
-      if (response.current != null) {
-        const { status } = response.current;
-        this.setState({ status });
-        if (status === STATUSES.SUCCESS) {
-          this.props.onFinish();
-        } else if (status === STATUSES.PENDING || status === STATUSES.IN_PROGRESS) {
+        if (response.current != null) {
+          const { status } = response.current;
+          this.setState({ status });
+          if (status === STATUSES.SUCCESS) {
+            this.props.onFinish();
+          } else if (status === STATUSES.PENDING || status === STATUSES.IN_PROGRESS) {
+            this.watch();
+          }
+        } else {
           this.watch();
         }
-      } else {
-        this.watch();
-      }
-    });
+      },
+      () => {}
+    );
   };
 
   render() {
index d15cee6a3e7525b7275499c1106e89ba16cc6e6d..323b519b7e586e95f020e81800ddcc0186797803 100644 (file)
@@ -64,8 +64,8 @@ export function getProjectUrl(key: string, branch?: string): Location {
   return { pathname: '/dashboard', query: { id: key, branch } };
 }
 
-export function getComponentBackgroundTaskUrl(componentKey: string): Location {
-  return { pathname: '/project/background_tasks', query: { id: componentKey } };
+export function getComponentBackgroundTaskUrl(componentKey: string, status?: string): Location {
+  return { pathname: '/project/background_tasks', query: { id: componentKey, status } };
 }
 
 export function getProjectBranchUrl(key: string, branch: Branch): Location {