diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/background-tasks')
20 files changed, 88 insertions, 56 deletions
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js b/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js index 11ed4513129..0fa65014b61 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js @@ -17,10 +17,10 @@ * 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 shallowCompare from 'react-addons-shallow-compare'; import debounce from 'lodash/debounce'; -import { PropTypes as RouterPropTypes } from 'react-router'; import { DEFAULT_FILTERS, DEBOUNCE_DELAY, STATUSES, CURRENTS } from './../constants'; import Header from './Header'; @@ -30,6 +30,7 @@ import Search from '../components/Search'; import Tasks from '../components/Tasks'; import { getTypes, getActivity, getStatus, cancelAllTasks, cancelTask as cancelTaskAPI } from '../../../api/ce'; import { updateTask, mapFiltersToParameters } from '../utils'; +import { Task } from '../types'; import '../background-tasks.css'; export default class BackgroundTasksApp extends React.Component { @@ -39,10 +40,10 @@ export default class BackgroundTasksApp extends React.Component { static propTypes = { component: React.PropTypes.object, - location: RouterPropTypes.location.isRequired + location: React.PropTypes.object }; - state = { + state: any = { loading: true, tasks: [], @@ -67,11 +68,11 @@ export default class BackgroundTasksApp extends React.Component { }); } - shouldComponentUpdate (nextProps, nextState) { + shouldComponentUpdate (nextProps: any, nextState: any) { return shallowCompare(this, nextProps, nextState); } - componentDidUpdate (prevProps) { + componentDidUpdate (prevProps: any) { if (prevProps.component !== this.props.component || prevProps.location !== this.props.location) { this.loadTasksDebounced(); @@ -82,6 +83,9 @@ export default class BackgroundTasksApp extends React.Component { this.mounted = false; } + loadTasksDebounced: any; + mounted: boolean; + loadTasks () { this.setState({ loading: true }); @@ -93,7 +97,7 @@ export default class BackgroundTasksApp extends React.Component { const query = this.props.location.query.query || DEFAULT_FILTERS.query; const filters = { status, taskType, currents, minSubmittedAt, maxExecutedAt, query }; - const parameters = mapFiltersToParameters(filters); + const parameters: any = mapFiltersToParameters(filters); if (this.props.component) { parameters.componentId = this.props.component.id; @@ -120,7 +124,7 @@ export default class BackgroundTasksApp extends React.Component { }); } - handleFilterUpdate (nextState) { + handleFilterUpdate (nextState: any) { const nextQuery = { ...this.props.location.query, ...nextState }; // remove defaults @@ -131,12 +135,12 @@ export default class BackgroundTasksApp extends React.Component { }); this.context.router.push({ - pathname: '/', + pathname: this.props.location.pathname, query: nextQuery }); } - handleCancelTask (task) { + handleCancelTask (task: Task) { this.setState({ loading: true }); cancelTaskAPI(task.id).then(nextTask => { @@ -147,7 +151,7 @@ export default class BackgroundTasksApp extends React.Component { }); } - handleFilterTask (task) { + handleFilterTask (task: Task) { this.handleFilterUpdate({ query: task.componentKey }); } diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js b/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js index 855646a4966..f6cdd97a28b 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/CurrentsFilter.js @@ -17,12 +17,13 @@ * 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 Checkbox from '../../../components/controls/Checkbox'; import { CURRENTS } from '../constants'; -const CurrentsFilter = ({ value, onChange }) => { +const CurrentsFilter = ({ value, onChange } : { value: ?string, onChange: any }) => { function handleChange (value) { const newValue = value ? CURRENTS.ONLY_CURRENTS : CURRENTS.ALL; onChange(newValue); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/DateFilter.js b/server/sonar-web/src/main/js/apps/background-tasks/components/DateFilter.js index ace8d6e428d..bdebed1fcaf 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/DateFilter.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/DateFilter.js @@ -17,6 +17,7 @@ * 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 $ from 'jquery'; import moment from 'moment'; import React, { Component } from 'react'; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.js index b9fd65ca96e..60f2f5be872 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.js @@ -17,13 +17,14 @@ * 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 { Task } from '../types'; import { translateWithParameters } from '../../../helpers/l10n'; const LIMIT = 1000; -const Footer = ({ tasks }) => { +const Footer = ({ tasks }: { tasks: Task[] }) => { if (tasks.length < LIMIT) { return null; } diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Header.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Header.js index 8cc1f251797..a8dc2607fde 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Header.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Header.js @@ -17,6 +17,7 @@ * 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 { translate } from '../../../helpers/l10n'; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js index 9dd234a6207..1b03a3bbead 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Search.js @@ -17,6 +17,7 @@ * 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 StatusFilter from './StatusFilter'; @@ -37,32 +38,32 @@ export default class Search extends React.Component { onReload: React.PropTypes.func.isRequired }; - handleStatusChange (status) { + handleStatusChange (status: string) { this.props.onFilterUpdate({ status }); } - handleTypeChange (taskType) { + handleTypeChange (taskType: string) { this.props.onFilterUpdate({ taskType }); } - handleCurrentsChange (currents) { + handleCurrentsChange (currents: string) { this.props.onFilterUpdate({ currents }); } - handleDateChange (date) { + handleDateChange (date: string) { this.props.onFilterUpdate(date); } - handleQueryChange (query) { + handleQueryChange (query: string) { this.props.onFilterUpdate({ query }); } - handleReload (e) { + handleReload (e: any) { e.target.blur(); this.props.onReload(); } - handleReset (e) { + handleReset (e: any) { e.preventDefault(); e.target.blur(); this.props.onFilterUpdate(DEFAULT_FILTERS); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js index 46da2cbc416..a7f6ffe3e29 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js @@ -17,6 +17,7 @@ * 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 shallowCompare from 'react-addons-shallow-compare'; @@ -30,17 +31,17 @@ export default class Stats extends React.Component { onCancelAllPending: React.PropTypes.func.isRequired }; - shouldComponentUpdate (nextProps, nextState) { + shouldComponentUpdate (nextProps: any, nextState: any) { return shallowCompare(this, nextProps, nextState); } - handleCancelAllPending (e) { + handleCancelAllPending (e: any) { e.preventDefault(); e.target.blur(); this.props.onCancelAllPending(); } - handleShowFailing (e) { + handleShowFailing (e: any) { e.preventDefault(); e.target.blur(); this.props.onShowFailing(); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.js b/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.js index 5228ad42f16..f0693466bd6 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.js @@ -17,13 +17,14 @@ * 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 Select from 'react-select'; import { STATUSES } from '../constants'; import { translate } from '../../../helpers/l10n'; -const StatusFilter = ({ value, onChange }) => { +const StatusFilter = ({ value, onChange }: { value: ?string, onChange: any }) => { const options = [ { value: STATUSES.ALL, label: translate('background_task.status.ALL') }, { value: STATUSES.ALL_EXCEPT_PENDING, label: translate('background_task.status.ALL_EXCEPT_PENDING') }, diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.js index ddced30d774..cdbf6650c7e 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.js @@ -17,13 +17,15 @@ * 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 TaskType from './TaskType'; import { getComponentUrl } from '../../../helpers/urls'; import QualifierIcon from '../../../components/shared/qualifier-icon'; +import { Task } from '../types'; -const TaskComponent = ({ task, types }) => { +const TaskComponent = ({ task, types }: { task: Task, types: string[] }) => { if (!task.componentKey) { return ( <td> diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.js index 581f5250d18..c1ff060a676 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDate.js @@ -17,10 +17,11 @@ * 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 moment from 'moment'; import React from 'react'; -const TaskDate = ({ date, baseDate, format }) => { +const TaskDate = ({ date, baseDate, format }: { date: string, baseDate: string, format: string }) => { const m = moment(date); const baseM = moment(baseDate); const diff = (date && baseDate) ? m.diff(baseM, 'days') : 0; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.js index 60972ebf86a..c7275f1668e 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskDay.js @@ -17,14 +17,16 @@ * 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 moment from 'moment'; import React from 'react'; +import { Task } from '../types'; function isAnotherDay (a, b) { return !moment(a).isSame(moment(b), 'day'); } -const TaskDay = ({ task, prevTask }) => { +const TaskDay = ({ task, prevTask } : { task: Task, prevTask: ?Task }) => { const shouldDisplay = !prevTask || isAnotherDay(task.submittedAt, prevTask.submittedAt); return ( diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.js index 98173c1af04..e0d12d09b7a 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskExecutionTime.js @@ -17,10 +17,12 @@ * 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 { formatDuration } from '../utils'; +import { Task } from '../types'; -const TaskExecutionTime = ({ task }) => { +const TaskExecutionTime = ({ task } : { task: Task }) => { return ( <td className="thin nowrap text-right"> {formatDuration(task.executionTimeMs)} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.js index 69e4ad97cf1..89e925590fe 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.js @@ -17,13 +17,15 @@ * 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 { STATUSES } from './../constants'; import PendingIcon from '../../../components/shared/pending-icon'; import { translate } from '../../../helpers/l10n'; +import { Task } from '../types'; -const TaskStatus = ({ task }) => { +const TaskStatus = ({ task }: { task: Task }) => { let inner; switch (task.status) { diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js index ed10f60f62b..0174bdbe0b0 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskType.js @@ -17,11 +17,12 @@ * 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 { Task } from '../types'; import { translate } from '../../../helpers/l10n'; -const TaskType = ({ task }) => { +const TaskType = ({ task }: { task: Task }) => { return ( <span className="note nowrap spacer-left"> {'['} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js index d6a9633354f..d696d47f9a2 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.js @@ -17,6 +17,7 @@ * 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 shallowCompare from 'react-addons-shallow-compare'; import classNames from 'classnames'; @@ -34,7 +35,7 @@ export default class Tasks extends React.Component { onFilterTask: React.PropTypes.func.isRequired }; - shouldComponentUpdate (nextProps, nextState) { + shouldComponentUpdate (nextProps: any, nextState: any) { return shallowCompare(this, nextProps, nextState); } diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TypesFilter.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TypesFilter.js index 825ba90fb6a..d167e23a0f6 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TypesFilter.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TypesFilter.js @@ -17,13 +17,14 @@ * 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 Select from 'react-select'; import { ALL_TYPES } from '../constants'; import { translate } from '../../../helpers/l10n'; -const TypesFilter = ({ value, onChange, types }) => { +const TypesFilter = ({ value, onChange, types }: { value: string, onChange: any, types: string[] }) => { const options = types.map(t => { return { value: t, diff --git a/server/sonar-web/src/main/js/apps/background-tasks/constants.js b/server/sonar-web/src/main/js/apps/background-tasks/constants.js index ed5f571d2a8..813f359ba32 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/constants.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/constants.js @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + /* @flow */ export const STATUSES = { ALL: '__ALL__', ALL_EXCEPT_PENDING: '__ALL_EXCEPT_PENDING__', diff --git a/server/sonar-web/src/main/js/apps/background-tasks/app.js b/server/sonar-web/src/main/js/apps/background-tasks/routes.js index c5ed780faa5..5bbcd616795 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/app.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/routes.js @@ -18,25 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import ReactDOM from 'react-dom'; -import { Router, Route, Redirect, useRouterHistory } from 'react-router'; -import { createHistory } from 'history'; - +import { IndexRoute } from 'react-router'; import BackgroundTasksApp from './components/BackgroundTasksApp'; -window.sonarqube.appStarted.then(options => { - const el = document.querySelector(options.el); - - const history = useRouterHistory(createHistory)({ - basename: window.baseUrl + (options.component ? '/project/background_tasks' : '/background_tasks') - }); - - const App = props => <BackgroundTasksApp {...props} component={options.component}/>; - - ReactDOM.render(( - <Router history={history}> - <Redirect from="/index" to="/"/> - <Route path="/" component={App}/> - </Router> - ), el); -}); +export default ( + <IndexRoute component={BackgroundTasksApp}/> +); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/types.js b/server/sonar-web/src/main/js/apps/background-tasks/types.js new file mode 100644 index 00000000000..00c000fd0c8 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/types.js @@ -0,0 +1,22 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 type Task = { + id: string; +}; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/utils.js b/server/sonar-web/src/main/js/apps/background-tasks/utils.js index 97207fa9864..cf0c4c89b8b 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/utils.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/utils.js @@ -17,13 +17,15 @@ * 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 { Task } from './types'; -export function updateTask (tasks, newTask) { +export function updateTask (tasks: Task[], newTask: Task) { return tasks.map(task => task.id === newTask.id ? newTask : task); } -export function mapFiltersToParameters (filters = {}) { +export function mapFiltersToParameters (filters: any = {}) { const parameters = {}; if (filters.status === STATUSES.ALL) { @@ -79,7 +81,7 @@ function format (int, suffix) { return `${int}${suffix}`; } -export function formatDuration (value) { +export function formatDuration (value: ?number) { if (!value) { return ''; } |