]> source.dussan.org Git - sonarqube.git/commitdiff
move Task type to app/types
authorStas Vilchik <stas.vilchik@sonarsource.com>
Thu, 30 Aug 2018 09:54:03 +0000 (11:54 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 10 Oct 2018 07:23:03 +0000 (09:23 +0200)
22 files changed:
server/sonar-web/src/main/js/api/ce.ts
server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx
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/ComponentNavLicenseNotif.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__/ComponentNavLicenseNotif-test.tsx
server/sonar-web/src/main/js/app/types.ts
server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js
server/sonar-web/src/main/js/apps/background-tasks/components/Footer.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap
server/sonar-web/src/main/js/apps/background-tasks/types.ts [deleted file]
server/sonar-web/src/main/js/apps/background-tasks/utils.js

index 21eaff0990df1cbb37734f3487fb8b26eb2eb17b..b72d148873e23e91f9c76b665ec4eb297d62def4 100644 (file)
  */
 import { getJSON, post, RequestData } from '../helpers/request';
 import throwGlobalError from '../app/utils/throwGlobalError';
-
-export interface PendingTask {
-  branch?: string;
-  branchType?: string;
-  componentKey: string;
-  componentName: string;
-  componentQualifier: string;
-  id: string;
-  logs: boolean;
-  organization: string;
-  pullRequest?: string;
-  pullRequestTitle?: string;
-  status: string;
-  submittedAt: Date;
-  submitterLogin?: string;
-  type: string;
-}
-
-export interface Task extends PendingTask {
-  analysisId?: string;
-  errorMessage?: string;
-  errorType?: string;
-  executionTimeMs: number;
-  executedAt: Date;
-  hasErrorStacktrace: boolean;
-  hasScannerContext: boolean;
-  startedAt: Date;
-}
+import { Task } from '../app/types';
 
 export function getActivity(data: RequestData): Promise<any> {
   return getJSON('/api/ce/activity', data);
@@ -74,7 +47,7 @@ export function cancelAllTasks(): Promise<any> {
 
 export function getTasksForComponent(
   componentKey: string
-): Promise<{ queue: PendingTask[]; current: Task }> {
+): Promise<{ queue: Task[]; current: Task }> {
   return getJSON('/api/ce/component', { componentKey }).catch(throwGlobalError);
 }
 
index 346a52d154d6e02e3a5cbf8e5c4d7f5d9ad71502..cf3781a495a305a2fe2fe0501bdf83443d7e590e 100644 (file)
@@ -23,10 +23,10 @@ import { connect } from 'react-redux';
 import { differenceBy } from 'lodash';
 import ComponentContainerNotFound from './ComponentContainerNotFound';
 import ComponentNav from './nav/component/ComponentNav';
-import { Component, BranchLike, Measure } from '../types';
+import { Component, BranchLike, Measure, Task } from '../types';
 import handleRequiredAuthorization from '../utils/handleRequiredAuthorization';
 import { getBranches, getPullRequests } from '../../api/branches';
-import { Task, getTasksForComponent, PendingTask } from '../../api/ce';
+import { getTasksForComponent } from '../../api/ce';
 import { getComponentData } from '../../api/components';
 import { getMeasures } from '../../api/measures';
 import { getComponentNavigation } from '../../api/nav';
@@ -57,7 +57,7 @@ interface State {
   currentTask?: Task;
   isPending: boolean;
   loading: boolean;
-  tasksInProgress?: PendingTask[];
+  tasksInProgress?: Task[];
 }
 
 const FETCH_STATUS_WAIT_TIME = 3000;
@@ -271,12 +271,12 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
       : undefined;
   };
 
-  getPendingTasks = (pendingTasks: PendingTask[], branchLike?: BranchLike) => {
+  getPendingTasks = (pendingTasks: Task[], branchLike?: BranchLike) => {
     return pendingTasks.filter(task => this.isSameBranch(task, branchLike));
   };
 
   isSameBranch = (
-    task: Pick<PendingTask, 'branch' | 'branchType' | 'pullRequest'>,
+    task: Pick<Task, 'branch' | 'branchType' | 'pullRequest'>,
     branchLike?: BranchLike
   ) => {
     if (branchLike && !isMainBranch(branchLike)) {
index 18a71ecb3e8b25668d0db49ad862e141c10f781d..7d5ca616c2fe0d771c68a82e789d4cb5c2c84242 100644 (file)
@@ -21,7 +21,7 @@ import * as React from 'react';
 import { shallow, mount } from 'enzyme';
 import { ComponentContainer } from '../ComponentContainer';
 import { getBranches, getPullRequests } from '../../../api/branches';
-import { getTasksForComponent, Task } from '../../../api/ce';
+import { getTasksForComponent } from '../../../api/ce';
 import { getComponentData } from '../../../api/components';
 import { getComponentNavigation } from '../../../api/nav';
 import {
@@ -30,7 +30,8 @@ import {
   LongLivingBranch,
   PullRequest,
   BranchType,
-  Visibility
+  Visibility,
+  Task
 } from '../../types';
 import { STATUSES } from '../../../apps/background-tasks/constants';
 import { waitAndUpdate } from '../../../helpers/testUtils';
index 7024131f79bfc1e86b8b136a8083cfce35c9d4f3..b99e3f10d6120ba3a7d2e8126c4af96e00887e7f 100644 (file)
@@ -24,9 +24,8 @@ import ComponentNavMenu from './ComponentNavMenu';
 import ComponentNavBgTaskNotif from './ComponentNavBgTaskNotif';
 import RecentHistory from '../../RecentHistory';
 import * as theme from '../../../theme';
-import { BranchLike, Component, Measure } from '../../../types';
+import { BranchLike, Component, Measure, Task } from '../../../types';
 import ContextNavBar from '../../../../components/nav/ContextNavBar';
-import { Task } from '../../../../api/ce';
 import { STATUSES } from '../../../../apps/background-tasks/constants';
 import './ComponentNav.css';
 
index 3ec723505178200ca5d1df76610cb2ae5abc25aa..14d5573d875aa589d201f5a856f22d9581614498 100644 (file)
@@ -23,11 +23,10 @@ import { FormattedMessage } from 'react-intl';
 import ComponentNavLicenseNotif from './ComponentNavLicenseNotif';
 import NavBarNotif from '../../../../components/nav/NavBarNotif';
 import PendingIcon from '../../../../components/icons-components/PendingIcon';
-import { Component } from '../../../types';
+import { Component, Task } from '../../../types';
 import { STATUSES } from '../../../../apps/background-tasks/constants';
 import { getComponentBackgroundTaskUrl } from '../../../../helpers/urls';
 import { hasMessage, translate } from '../../../../helpers/l10n';
-import { Task } from '../../../../api/ce';
 
 interface Props {
   component: Component;
index 9a251ce316db1d3673178e8fc511abab6c9831e4..112158e5b2fcc70077748a228c41c376da6e9ddf 100644 (file)
@@ -22,8 +22,8 @@ import { Link } from 'react-router';
 import * as PropTypes from 'prop-types';
 import NavBarNotif from '../../../../components/nav/NavBarNotif';
 import { translate } from '../../../../helpers/l10n';
-import { Task } from '../../../../api/ce';
 import { isValidLicense } from '../../../../api/marketplace';
+import { Task } from '../../../types';
 
 interface Props {
   currentTask?: Task;
index b027ea1fcb9604abd613021f449afeb50b3344c3..07fece7737de79dc788c060cbc2bd3f86a345875 100644 (file)
@@ -27,7 +27,7 @@ jest.mock('../../../../../helpers/l10n', () => {
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import ComponentNavBgTaskNotif from '../ComponentNavBgTaskNotif';
-import { Task } from '../../../../../api/ce';
+import { Task } from '../../../../types';
 
 const component = {
   analysisDate: '2017-01-02T00:00:00.000Z',
index 4fb9cb4214bbb15abd9d58fc148c036c192d29f9..c2440b8e1974fcda08ae3060aa40b6c3d371dc8b 100644 (file)
@@ -20,9 +20,9 @@
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import ComponentNavLicenseNotif from '../ComponentNavLicenseNotif';
-import { Task } from '../../../../../api/ce';
 import { isValidLicense } from '../../../../../api/marketplace';
 import { waitAndUpdate } from '../../../../../helpers/testUtils';
+import { Task } from '../../../../types';
 
 jest.mock('../../../../../helpers/l10n', () => {
   const l10n = require.requireActual('../../../../../helpers/l10n');
index 435f7206b0f4de5012e6c986bc3758b8fb379e8a..6d6965e1fce93136ac666ad4fc148f8885c542f1 100644 (file)
@@ -720,6 +720,31 @@ export interface SubscriptionPlan {
   price: number;
 }
 
+export interface Task {
+  analysisId?: string;
+  branch?: string;
+  branchType?: string;
+  componentKey?: string;
+  componentName?: string;
+  componentQualifier?: string;
+  errorMessage?: string;
+  errorType?: string;
+  executedAt?: string;
+  executionTimeMs?: number;
+  hasErrorStacktrace?: boolean;
+  hasScannerContext?: boolean;
+  id: string;
+  logs?: boolean;
+  organization: string;
+  pullRequest?: string;
+  pullRequestTitle?: string;
+  startedAt?: string;
+  status: string;
+  submittedAt: string;
+  submitterLogin?: string;
+  type: string;
+}
+
 export interface TestCase {
   coveredLines: number;
   durationInMs: number;
index 20329eafbaf06ebdb3c189c5ef8de11588da3cab..50b47f89b62ba489b9da8735a72e7e419baf537f 100644 (file)
@@ -42,7 +42,6 @@ import { fetchOrganizations } from '../../../store/rootActions';
 import { translate } from '../../../helpers/l10n';
 import { parseAsDate } from '../../../helpers/query';
 import { toShortNotSoISOString } from '../../../helpers/dates';
-/*:: import type { Task } from '../types'; */
 import '../background-tasks.css';
 
 /*::
@@ -174,7 +173,7 @@ class BackgroundTasksApp extends React.PureComponent {
     });
   }
 
-  handleCancelTask(task /*: Task */) {
+  handleCancelTask(task) {
     this.setState({ loading: true });
 
     cancelTaskAPI(task.id).then(nextTask => {
@@ -185,7 +184,7 @@ class BackgroundTasksApp extends React.PureComponent {
     });
   }
 
-  handleFilterTask(task /*: Task */) {
+  handleFilterTask(task) {
     this.handleFilterUpdate({ query: task.componentKey });
   }
 
index 3d7f0fc682de15042a6bffef02fe187957aa5c8c..4242bb2b3e391abfed4016e0494ad67a006183a1 100644 (file)
@@ -19,7 +19,7 @@
  */
 import * as React from 'react';
 import { translateWithParameters } from '../../../helpers/l10n';
-import { Task } from '../types';
+import { Task } from '../../../app/types';
 
 const LIMIT = 1000;
 
index 7e66a3e007e37186962aaadc94366c54aeff67d1..6fc2bb4e920cc704ea4d3158204871cabd4cf059 100644 (file)
 import * as React from 'react';
 import { getTask } from '../../../api/ce';
 import { translate } from '../../../helpers/l10n';
-import { Task } from '../types';
 import Modal from '../../../components/controls/Modal';
+import { Task } from '../../../app/types';
 
 interface Props {
   onClose: () => void;
-  task: Task;
+  task: Pick<Task, 'componentName' | 'id' | 'type'>;
 }
 
 interface State {
index 21cdf7ec937dc61ccff75ddf60bd9c6ee70ebb08..51d2c99875b5bf5afb014c866a9d3e6f9c5ea0a3 100644 (file)
@@ -21,11 +21,11 @@ import * as React from 'react';
 import { getTask } from '../../../api/ce';
 import { translate } from '../../../helpers/l10n';
 import Modal from '../../../components/controls/Modal';
-import { Task } from '../types';
+import { Task } from '../../../app/types';
 
 interface Props {
   onClose: () => void;
-  task: Task;
+  task: Pick<Task, 'componentName' | 'errorMessage' | 'id' | 'type'>;
 }
 
 interface State {
index aec464679312fa5dfbf8b2a3fb5f3666505ba186..c51a705688bda80ac213fd64dd1997a373d18ed7 100644 (file)
@@ -26,14 +26,14 @@ import TaskDate from './TaskDate';
 import TaskId from './TaskId';
 import TaskStatus from './TaskStatus';
 import TaskSubmitter from './TaskSubmitter';
-import { Task as ITask } from '../types';
+import { Task as TaskType } from '../../../app/types';
 
 interface Props {
   component?: {};
-  onCancelTask: (task: ITask) => void;
-  onFilterTask: (task: ITask) => void;
-  task: ITask;
-  previousTask?: ITask;
+  onCancelTask: (task: TaskType) => void;
+  onFilterTask: (task: TaskType) => void;
+  task: TaskType;
+  previousTask?: TaskType;
 }
 
 export default function Task(props: Props) {
index 02b367047bfdbb3e338c303549402ba23375af3d..68587cd0ad9748ebea4ce46e52e9e7794262f856 100644 (file)
@@ -22,8 +22,8 @@ import ScannerContext from './ScannerContext';
 import Stacktrace from './Stacktrace';
 import { STATUSES } from '../constants';
 import { translate, translateWithParameters } from '../../../helpers/l10n';
-import { Task } from '../types';
 import ActionsDropdown, { ActionsDropdownItem } from '../../../components/controls/ActionsDropdown';
+import { Task } from '../../../app/types';
 
 interface Props {
   component?: {};
index c3afacc324ab0b7c9d4bafc4551aec5a8491687e..363fb4eae7aa707a7b9c9e2703f43889283af8b2 100644 (file)
@@ -20,7 +20,6 @@
 import * as React from 'react';
 import { Link } from 'react-router';
 import TaskType from './TaskType';
-import { Task } from '../types';
 import QualifierIcon from '../../../components/icons-components/QualifierIcon';
 import Organization from '../../../components/shared/Organization';
 import {
@@ -32,6 +31,7 @@ import {
 import ShortLivingBranchIcon from '../../../components/icons-components/ShortLivingBranchIcon';
 import LongLivingBranchIcon from '../../../components/icons-components/LongLivingBranchIcon';
 import PullRequestIcon from '../../../components/icons-components/PullRequestIcon';
+import { Task } from '../../../app/types';
 
 interface Props {
   task: Task;
index e2fb32157e2e837cb34c065ebad1ca6b1a901a7b..6e6e8e6f53b543aaf662a719d667ba42f54f1057 100644 (file)
@@ -31,10 +31,7 @@ const getTask = require('../../../../api/ce').getTask as jest.Mock<any>;
 
 const task = {
   componentName: 'foo',
-  status: 'PENDING',
   id: '123',
-  submittedAt: '2017-01-01',
-  submitterLogin: 'yoda',
   type: 'REPORT'
 };
 
index 96ccc7077d0ca3b361bd5d4da7ac3dab0e75effc..d68d7afc07bea6d80da2173191893fd06674e9d0 100644 (file)
@@ -31,10 +31,7 @@ const getTask = require('../../../../api/ce').getTask as jest.Mock<any>;
 
 const task = {
   componentName: 'foo',
-  status: 'PENDING',
   id: '123',
-  submittedAt: '2017-01-01',
-  submitterLogin: 'yoda',
   type: 'REPORT'
 };
 
index 9ff179bbe1796a86413364cf3271d7d64c938fad..5108d020db1fedd2b7af06ef6f3cecf28cffb260 100644 (file)
@@ -29,8 +29,9 @@ it('renders', () => {
         onFilterTask={jest.fn()}
         task={{
           componentName: 'foo',
-          status: 'PENDING',
           id: '123',
+          organization: 'org',
+          status: 'PENDING',
           submittedAt: '2017-01-01',
           submitterLogin: 'yoda',
           type: 'REPORT'
index 0fffe27edc9d18e59fcdcb5141fa11299b9eaef4..fc95e82d35c74ab941cea426a39e0df29b53a537 100644 (file)
@@ -10,6 +10,7 @@ exports[`renders 1`] = `
       Object {
         "componentName": "foo",
         "id": "123",
+        "organization": "org",
         "status": "PENDING",
         "submittedAt": "2017-01-01",
         "submitterLogin": "yoda",
@@ -43,6 +44,7 @@ exports[`renders 1`] = `
       Object {
         "componentName": "foo",
         "id": "123",
+        "organization": "org",
         "status": "PENDING",
         "submittedAt": "2017-01-01",
         "submitterLogin": "yoda",
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/types.ts b/server/sonar-web/src/main/js/apps/background-tasks/types.ts
deleted file mode 100644 (file)
index 2202403..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 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.
- */
-export interface Task {
-  branch?: string;
-  branchType?: string;
-  componentKey?: string;
-  componentName?: string;
-  componentQualifier?: string;
-  errorMessage?: string;
-  executedAt?: string;
-  executionTimeMs?: number;
-  hasScannerContext?: boolean;
-  id: string;
-  organization?: string;
-  pullRequest?: string;
-  pullRequestTitle?: string;
-  startedAt?: string;
-  status: string;
-  submittedAt: string;
-  submitterLogin?: string;
-  type: string;
-}
index 4f92fa752db16e3f013761b7023cea7bcadd8d51..a023e7176e66af86a507a0df88df7295f3d66f5b 100644 (file)
  * 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 { STATUSES, ALL_TYPES, CURRENTS } from './constants';
 import { toShortNotSoISOString } from '../../helpers/dates';
-/*:: import type { Task } from './types'; */
 
-export function updateTask(tasks /*: Task[] */, newTask /*: Task */) {
+export function updateTask(tasks, newTask) {
   return tasks.map(task => (task.id === newTask.id ? newTask : task));
 }