]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9708 Display incremental analysis badge in UI (#2352)
authorStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 14 Aug 2017 12:29:45 +0000 (14:29 +0200)
committerGitHub <noreply@github.com>
Mon, 14 Aug 2017 12:29:45 +0000 (14:29 +0200)
13 files changed:
server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.js
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.js
server/sonar-web/src/main/js/app/components/nav/component/IncrementalBadge.js [new file with mode: 0644]
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.js [new file with mode: 0644]
server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.js [new file with mode: 0644]
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.js.snap [new file with mode: 0644]
server/sonar-web/src/main/js/apps/background-tasks/types.js
server/sonar-web/src/main/js/apps/coding-rules/templates/rule/coding-rules-rule-profile.hbs
server/sonar-web/src/main/js/apps/quality-profiles/components/BuiltInBadge.js
server/sonar-web/src/main/js/components/common/PrivateBadge.js
server/sonar-web/src/main/less/components/badges.less
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 61738902ee9f830e178ca6217b956efd02996541..811cf2b73976b1d3ff353307e52cd27a212d3ecf 100644 (file)
@@ -47,7 +47,8 @@ export default class ComponentNav extends React.PureComponent {
         this.setState({
           isPending: r.queue.some(task => task.status === STATUSES.PENDING),
           isInProgress: r.queue.some(task => task.status === STATUSES.IN_PROGRESS),
-          isFailed: r.current && r.current.status === STATUSES.FAILED
+          isFailed: r.current && r.current.status === STATUSES.FAILED,
+          incremental: r.current && r.current.incremental
         });
       }
     });
index fdad7ec0280d943be7d509252bb1ab3a3a089daa..15b086e9b3cb0b5f047eb9384776c9527a8ef506 100644 (file)
  */
 import moment from 'moment';
 import React from 'react';
+import IncrementalBadge from './IncrementalBadge';
 import PendingIcon from '../../../../components/shared/pending-icon';
 import { translate, translateWithParameters } from '../../../../helpers/l10n';
 
-export default class ComponentNavMeta extends React.PureComponent {
-  render() {
-    const metaList = [];
-    const canSeeBackgroundTasks = this.props.conf.showBackgroundTasks;
-    const backgroundTasksUrl =
-      window.baseUrl +
-      `/project/background_tasks?id=${encodeURIComponent(this.props.component.key)}`;
+export default function ComponentNavMeta(props) {
+  const metaList = [];
+  const canSeeBackgroundTasks = props.conf.showBackgroundTasks;
+  const backgroundTasksUrl =
+    window.baseUrl + `/project/background_tasks?id=${encodeURIComponent(props.component.key)}`;
 
-    if (this.props.isInProgress) {
-      const tooltip = canSeeBackgroundTasks
-        ? translateWithParameters(
-            'component_navigation.status.in_progress.admin',
-            backgroundTasksUrl
-          )
-        : translate('component_navigation.status.in_progress');
-      metaList.push(
-        <li key="isInProgress" data-toggle="tooltip" title={tooltip}>
-          <i className="spinner" style={{ marginTop: '-1px' }} />{' '}
-          <span className="text-info">{translate('background_task.status.IN_PROGRESS')}</span>
-        </li>
-      );
-    } else if (this.props.isPending) {
-      const tooltip = canSeeBackgroundTasks
-        ? translateWithParameters('component_navigation.status.pending.admin', backgroundTasksUrl)
-        : translate('component_navigation.status.pending');
-      metaList.push(
-        <li key="isPending" data-toggle="tooltip" title={tooltip}>
-          <PendingIcon /> <span>{translate('background_task.status.PENDING')}</span>
-        </li>
-      );
-    } else if (this.props.isFailed) {
-      const tooltip = canSeeBackgroundTasks
-        ? translateWithParameters('component_navigation.status.failed.admin', backgroundTasksUrl)
-        : translate('component_navigation.status.failed');
-      metaList.push(
-        <li key="isFailed" data-toggle="tooltip" title={tooltip}>
-          <span className="badge badge-danger">
-            {translate('background_task.status.FAILED')}
-          </span>
-        </li>
-      );
-    }
+  if (props.isInProgress) {
+    const tooltip = canSeeBackgroundTasks
+      ? translateWithParameters('component_navigation.status.in_progress.admin', backgroundTasksUrl)
+      : translate('component_navigation.status.in_progress');
+    metaList.push(
+      <li key="isInProgress" data-toggle="tooltip" title={tooltip}>
+        <i className="spinner" style={{ marginTop: '-1px' }} />{' '}
+        <span className="text-info">{translate('background_task.status.IN_PROGRESS')}</span>
+      </li>
+    );
+  } else if (props.isPending) {
+    const tooltip = canSeeBackgroundTasks
+      ? translateWithParameters('component_navigation.status.pending.admin', backgroundTasksUrl)
+      : translate('component_navigation.status.pending');
+    metaList.push(
+      <li key="isPending" data-toggle="tooltip" title={tooltip}>
+        <PendingIcon /> <span>{translate('background_task.status.PENDING')}</span>
+      </li>
+    );
+  } else if (props.isFailed) {
+    const tooltip = canSeeBackgroundTasks
+      ? translateWithParameters('component_navigation.status.failed.admin', backgroundTasksUrl)
+      : translate('component_navigation.status.failed');
+    metaList.push(
+      <li key="isFailed" data-toggle="tooltip" title={tooltip}>
+        <span className="badge badge-danger">
+          {translate('background_task.status.FAILED')}
+        </span>
+      </li>
+    );
+  }
 
-    if (this.props.analysisDate) {
-      metaList.push(
-        <li key="analysisDate">
-          {moment(this.props.analysisDate).format('LLL')}
-        </li>
-      );
-    }
+  if (props.analysisDate) {
+    metaList.push(
+      <li key="analysisDate">
+        {moment(props.analysisDate).format('LLL')}
+      </li>
+    );
+  }
 
-    if (this.props.version) {
-      metaList.push(
-        <li key="version">
-          Version {this.props.version}
-        </li>
-      );
-    }
+  if (props.version) {
+    metaList.push(
+      <li key="version">
+        Version {props.version}
+      </li>
+    );
+  }
 
-    return (
-      <div className="navbar-context-meta">
-        <ul className="list-inline">
-          {metaList}
-        </ul>
-      </div>
+  if (props.incremental) {
+    metaList.push(
+      <li key="incremental">
+        <IncrementalBadge />
+      </li>
     );
   }
+
+  return (
+    <div className="navbar-context-meta">
+      <ul className="list-inline">
+        {metaList}
+      </ul>
+    </div>
+  );
 }
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/IncrementalBadge.js b/server/sonar-web/src/main/js/app/components/nav/component/IncrementalBadge.js
new file mode 100644 (file)
index 0000000..2692360
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import React from 'react';
+import Tooltip from '../../../../components/controls/Tooltip';
+import { translate } from '../../../../helpers/l10n';
+
+export default function IncrementalBadge() {
+  return (
+    <Tooltip overlay={translate('incremental.project_tooltip')}>
+      <div className="outline-badge">
+        {translate('incremental')}
+      </div>
+    </Tooltip>
+  );
+}
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.js b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.js
new file mode 100644 (file)
index 0000000..fd99e28
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import React from 'react';
+import { shallow } from 'enzyme';
+import ComponentNavMeta from '../ComponentNavMeta';
+
+it('renders incremental badge', () => {
+  check(true);
+  check(false);
+
+  function check(incremental) {
+    expect(
+      shallow(
+        <ComponentNavMeta component={{ key: 'foo' }} conf={{}} incremental={incremental} />
+      ).find('IncrementalBadge')
+    ).toHaveLength(incremental ? 1 : 0);
+  }
+});
index 11957d7dcf26a4764bbfe6e8cc68a9a3809930b4..a06c44a7793b30060bcdd3456604f19adbda8a96 100644 (file)
@@ -27,6 +27,7 @@ const TaskType = ({ task }: { task: Task }) => {
     <span className="note nowrap spacer-left">
       {'['}
       {translate('background_task.type', task.type)}
+      {task.incremental && ` - ${translate('incremental')}`}
       {']'}
     </span>
   );
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.js b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskType-test.js
new file mode 100644 (file)
index 0000000..ed32df3
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+/* @flow */
+import React from 'react';
+import { shallow } from 'enzyme';
+import TaskType from '../TaskType';
+
+it('renders', () => {
+  expect(shallow(<TaskType task={{ id: 'foo' }} />)).toMatchSnapshot();
+  expect(shallow(<TaskType task={{ incremental: true, id: 'foo' }} />)).toMatchSnapshot();
+});
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.js.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskType-test.js.snap
new file mode 100644 (file)
index 0000000..92b09f7
--- /dev/null
@@ -0,0 +1,22 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`renders 1`] = `
+<span
+  className="note nowrap spacer-left"
+>
+  [
+  background_task.type.
+  ]
+</span>
+`;
+
+exports[`renders 2`] = `
+<span
+  className="note nowrap spacer-left"
+>
+  [
+  background_task.type.
+   - incremental
+  ]
+</span>
+`;
index 725c3e2bf88cb32d33023bccf67ad6f3a7eff56d..48ad0c98f5c8c789c508e396aef5f18139b8b920 100644 (file)
@@ -18,5 +18,6 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 export type Task = {
+  incremental: boolean,
   id: string
 };
index ad1e984f5b32211330d0af5d6ff93f2ed589a21d..00a1c8054118798be39ec77f8b13bfa771c701f4 100644 (file)
@@ -3,7 +3,7 @@
     {{name}}
   </a>
   {{#if isBuiltIn}}
-    <span class="built-in-badge spacer-left" data-toggle="tooltip"  data-placement="bottom"
+    <span class="outline-badge spacer-left" data-toggle="tooltip"  data-placement="bottom"
           title="{{t 'quality_profiles.built_in.description.1'}} {{t 'quality_profiles.built_in.description.2'}}">
       {{t 'quality_profiles.built_in'}}
     </span>
index 8df1be7a80dcb5873383f220c5d5fc5497b9def5..1e85d72c4738321ac132c92ad4a403900bdd2087 100644 (file)
@@ -30,7 +30,7 @@ type Props = {|
 
 export default function BuiltInBadge(props: Props) {
   const badge = (
-    <div className={classNames('built-in-badge', props.className)}>
+    <div className={classNames('outline-badge', props.className)}>
       {translate('quality_profiles.built_in')}
     </div>
   );
index cee6b2f3ffd047b690b3233351ee43845394717e..301391d19bf9981af2067f604832ed0d299a25ba 100644 (file)
@@ -31,7 +31,7 @@ type Props = {
 export default function PrivateBadge({ className, tooltipPlacement = 'bottom' }: Props) {
   return (
     <Tooltip overlay={translate('visibility.private.description')} placement={tooltipPlacement}>
-      <div className={classNames('private-badge', className)}>
+      <div className={classNames('outline-badge', className)}>
         {translate('visibility.private')}
       </div>
     </Tooltip>
index d31a9ca7bb746de449e1aeb9e8c647749b0816eb..3ba90d024b10bd6e57b0bcd30407cb03c43cdf88 100644 (file)
   background-color: @middleGrey;
 }
 
-.private-badge,
-.built-in-badge {
+.outline-badge {
   display: inline-block;
   vertical-align: middle;
   height: 20px;
index 3a54da8e687f5fb2732bea08109e4604e9c4ac9b..f45218ea69ba7c8d3edff246f82c43a704b2baff 100644 (file)
@@ -81,6 +81,8 @@ hide=Hide
 identifier_abbreviated=Id
 inactive=Inactive
 including_abbreviated=incl.
+incremental=Incremental
+incrementa.project_tooltip=Overall project status could be incomplete: incremental mode was used in the last analysis, so only changed files were examined.
 info=Info
 issue=Issue
 issues=Issues