diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2017-03-27 14:00:14 +0200 |
---|---|---|
committer | Stas Vilchik <stas-vilchik@users.noreply.github.com> | 2017-04-03 10:38:52 +0200 |
commit | 32a73efa05cb12056a93f08b9124e647213f1f02 (patch) | |
tree | 89c545631a613d2041383b5143afb0e040c327e0 /server/sonar-web/src/main/js/apps/quality-profiles/changelog | |
parent | be8738ea1e0322d81e238c4462c7ec6f22d2177c (diff) | |
download | sonarqube-32a73efa05cb12056a93f08b9124e647213f1f02.tar.gz sonarqube-32a73efa05cb12056a93f08b9124e647213f1f02.zip |
SONAR-9008 support quality profiles for organizations
Diffstat (limited to 'server/sonar-web/src/main/js/apps/quality-profiles/changelog')
7 files changed, 100 insertions, 58 deletions
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.js index cd70278214d..2e84e64d2a3 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/Changelog.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 { Link } from 'react-router'; import moment from 'moment'; @@ -24,10 +25,19 @@ import ChangesList from './ChangesList'; import { translate } from '../../../helpers/l10n'; import { getRulesUrl } from '../../../helpers/urls'; -export default class Changelog extends React.Component { - static propTypes = { - events: React.PropTypes.array.isRequired - }; +type Props = { + events: Array<{ + action: string, + authorName: string, + date: string, + params?: {}, + ruleKey: string, + ruleName: string + }> +}; + +export default class Changelog extends React.PureComponent { + props: Props; render() { let isEvenRow = false; diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.js index 8de4383ca42..c7ea2d89572 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.js @@ -17,40 +17,52 @@ * 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 Changelog from './Changelog'; import ChangelogSearch from './ChangelogSearch'; import ChangelogEmpty from './ChangelogEmpty'; import { getProfileChangelog } from '../../../api/quality-profiles'; -import { ProfileType } from '../propTypes'; import { translate } from '../../../helpers/l10n'; - -export default class ChangelogContainer extends React.Component { - static propTypes = { - location: React.PropTypes.object.isRequired, - profile: ProfileType - }; +import { getProfileChangelogPath } from '../utils'; +import type { Profile } from '../propTypes'; + +type Props = { + location: { + query: { + since?: string, + to?: string + } + }, + organization: ?string, + profile: Profile +}; + +type State = { + events?: Array<*>, + loading: boolean, + page?: number, + total?: number +}; + +export default class ChangelogContainer extends React.PureComponent { + mounted: boolean; + props: Props; static contextTypes = { router: React.PropTypes.object }; - state = { + state: State = { loading: true }; - componentWillMount() { - this.handleFromDateChange = this.handleFromDateChange.bind(this); - this.handleToDateChange = this.handleToDateChange.bind(this); - this.handleReset = this.handleReset.bind(this); - } - componentDidMount() { this.mounted = true; this.loadChangelog(); } - componentDidUpdate(prevProps) { + componentDidUpdate(prevProps: Props) { if (prevProps.location !== this.props.location) { this.loadChangelog(); } @@ -63,7 +75,7 @@ export default class ChangelogContainer extends React.Component { loadChangelog() { this.setState({ loading: true }); const { query } = this.props.location; - const data = { profileKey: this.props.profile.key }; + const data: Object = { profileKey: this.props.profile.key }; if (query.since) { data.since = query.since; } @@ -83,13 +95,13 @@ export default class ChangelogContainer extends React.Component { }); } - loadMore(e) { + loadMore(e: SyntheticInputEvent) { e.preventDefault(); e.target.blur(); this.setState({ loading: true }); const { query } = this.props.location; - const data = { + const data: Object = { profileKey: this.props.profile.key, p: this.state.page + 1 }; @@ -101,7 +113,7 @@ export default class ChangelogContainer extends React.Component { } getProfileChangelog(data).then(r => { - if (this.mounted) { + if (this.mounted && this.state.events) { this.setState({ events: [...this.state.events, ...r.events], total: r.total, @@ -112,25 +124,32 @@ export default class ChangelogContainer extends React.Component { }); } - handleFromDateChange(fromDate) { - const query = { ...this.props.location.query, since: fromDate }; - this.context.router.push({ pathname: '/profiles/changelog', query }); - } + handleFromDateChange = (fromDate?: string) => { + const path = getProfileChangelogPath(this.props.profile.key, this.props.organization, { + since: fromDate, + to: this.props.location.query.to + }); + this.context.router.push(path); + }; - handleToDateChange(toDate) { - const query = { ...this.props.location.query, to: toDate }; - this.context.router.push({ pathname: '/profiles/changelog', query }); - } + handleToDateChange = (toDate?: string) => { + const path = getProfileChangelogPath(this.props.profile.key, this.props.organization, { + since: this.props.location.query.since, + to: toDate + }); + this.context.router.push(path); + }; - handleReset() { - const query = { key: this.props.profile.key }; - this.context.router.push({ pathname: '/profiles/changelog', query }); - } + handleReset = () => { + const path = getProfileChangelogPath(this.props.profile.key, this.props.organization); + this.context.router.push(path); + }; render() { const { query } = this.props.location; const shouldDisplayFooter = this.state.events != null && + this.state.total != null && this.state.events.length < this.state.total; return ( diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogEmpty.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogEmpty.js index 1baf1d73e4f..96db0d8c8eb 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogEmpty.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogEmpty.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 React from 'react'; import { translate } from '../../../helpers/l10n'; -export default class ChangelogEmpty extends React.Component { +export default class ChangelogEmpty extends React.PureComponent { render() { return ( <div className="big-spacer-top"> diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogSearch.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogSearch.js index 1106ba94b34..89d2099a229 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogSearch.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogSearch.js @@ -17,20 +17,23 @@ * 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 DateInput from '../../../components/controls/DateInput'; import { translate } from '../../../helpers/l10n'; -export default class ChangelogSearch extends React.Component { - static propTypes = { - fromDate: React.PropTypes.string, - toDate: React.PropTypes.string, - onFromDateChange: React.PropTypes.func.isRequired, - onToDateChange: React.PropTypes.func.isRequired, - onReset: React.PropTypes.func.isRequired - }; +type Props = { + fromDate?: string, + toDate?: string, + onFromDateChange: () => void, + onReset: () => void, + onToDateChange: () => void +}; - handleResetClick(e) { +export default class ChangelogSearch extends React.PureComponent { + props: Props; + + handleResetClick(e: SyntheticInputEvent) { e.preventDefault(); e.target.blur(); this.props.onReset(); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangesList.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangesList.js index 9ec1807227a..6377b4f3799 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangesList.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangesList.js @@ -17,14 +17,17 @@ * 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 SeverityChange from './SeverityChange'; import ParameterChange from './ParameterChange'; -export default class ChangesList extends React.Component { - static propTypes = { - changes: React.PropTypes.object.isRequired - }; +type Props = { + changes: { [string]: ?string } +}; + +export default class ChangesList extends React.PureComponent { + props: Props; render() { const { changes } = this.props; diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ParameterChange.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ParameterChange.js index 7b4e0168979..d4e01d55b72 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ParameterChange.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ParameterChange.js @@ -17,14 +17,17 @@ * 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 { translateWithParameters } from '../../../helpers/l10n'; -export default class ParameterChange extends React.Component { - static propTypes = { - name: React.PropTypes.string.isRequired, - value: React.PropTypes.any - }; +type Props = { + name: string, + value: ?string +}; + +export default class ParameterChange extends React.PureComponent { + props: Props; render() { const { name, value } = this.props; diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.js b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.js index c6e20846d83..5497d9ad0fb 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.js @@ -17,14 +17,17 @@ * 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 SeverityHelper from '../../../components/shared/severity-helper'; import { translate } from '../../../helpers/l10n'; -export default class SeverityChange extends React.Component { - static propTypes = { - severity: React.PropTypes.string.isRequired - }; +type Props = { + severity: ?string +}; + +export default class SeverityChange extends React.PureComponent { + props: Props; render() { return ( |