diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-08-29 13:05:49 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-09-13 13:53:58 +0200 |
commit | 361d9c3e6c2f2dbf10b1412789bed2095f25edcc (patch) | |
tree | 532480cb28ec553e89b9fe9d53dd001f8a68dc58 /server/sonar-web/src/main/js/components/ui | |
parent | 77bd653967bee376b0e3ff3be0e6f7a5be32699e (diff) | |
download | sonarqube-361d9c3e6c2f2dbf10b1412789bed2095f25edcc.tar.gz sonarqube-361d9c3e6c2f2dbf10b1412789bed2095f25edcc.zip |
rewrite projects app
Diffstat (limited to 'server/sonar-web/src/main/js/components/ui')
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/CoverageRating.js | 70 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/CoverageRating.tsx | 48 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/DuplicationsRating.js | 55 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/DuplicationsRating.tsx | 45 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/OrganizationLink.tsx (renamed from server/sonar-web/src/main/js/components/ui/OrganizationLink.js) | 18 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/Rating.js | 58 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/Rating.tsx | 45 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/SizeRating.js | 66 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/SizeRating.tsx | 55 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/__tests__/OrganizationLink-test.tsx | 26 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/OrganizationLink-test.tsx.snap | 9 |
11 files changed, 236 insertions, 259 deletions
diff --git a/server/sonar-web/src/main/js/components/ui/CoverageRating.js b/server/sonar-web/src/main/js/components/ui/CoverageRating.js deleted file mode 100644 index 6fe1c7cc09e..00000000000 --- a/server/sonar-web/src/main/js/components/ui/CoverageRating.js +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 { DonutChart } from '../charts/donut-chart'; - -const SIZE_TO_WIDTH_MAPPING = { - small: 16, - normal: 24, - big: 40, - huge: 60 -}; - -const SIZE_TO_THICKNESS_MAPPING = { - small: 2, - normal: 3, - big: 3, - huge: 4 -}; - -export default class CoverageRating extends React.PureComponent { - /*:: props: { - value: number | string, - size?: 'small' | 'normal' | 'big' | 'huge', - muted?: boolean - }; -*/ - - static defaultProps = { - size: 'normal', - muted: false - }; - - render() { - let data = [{ value: 100, fill: '#ccc ' }]; - - if (this.props.value != null) { - const value = Number(this.props.value); - data = [ - { value, fill: this.props.muted ? '#bdbdbd' : '#00aa00' }, - { value: 100 - value, fill: this.props.muted ? '#f3f3f3' : '#d4333f' } - ]; - } - - // $FlowFixMe - const size = SIZE_TO_WIDTH_MAPPING[this.props.size]; - - // $FlowFixMe - const thickness = SIZE_TO_THICKNESS_MAPPING[this.props.size]; - - return <DonutChart data={data} width={size} height={size} thickness={thickness} />; - } -} diff --git a/server/sonar-web/src/main/js/components/ui/CoverageRating.tsx b/server/sonar-web/src/main/js/components/ui/CoverageRating.tsx new file mode 100644 index 00000000000..e7eda495d7f --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/CoverageRating.tsx @@ -0,0 +1,48 @@ +/* + * 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 * as React from 'react'; +import { DonutChart } from '../charts/donut-chart'; + +const SIZE_TO_WIDTH_MAPPING = { small: 16, normal: 24, big: 40, huge: 60 }; + +const SIZE_TO_THICKNESS_MAPPING = { small: 2, normal: 3, big: 3, huge: 4 }; + +interface Props { + muted?: boolean; + size?: 'small' | 'normal' | 'big' | 'huge'; + value: number | string | null | undefined; +} + +export default function CoverageRating({ muted = false, size = 'normal', value }: Props) { + let data = [{ value: 100, fill: '#ccc ' }]; + + if (value != null) { + const numberValue = Number(value); + data = [ + { value: numberValue, fill: muted ? '#bdbdbd' : '#00aa00' }, + { value: 100 - numberValue, fill: muted ? '#f3f3f3' : '#d4333f' } + ]; + } + + const width = SIZE_TO_WIDTH_MAPPING[size]; + const thickness = SIZE_TO_THICKNESS_MAPPING[size]; + + return <DonutChart data={data} width={width} height={width} thickness={thickness} />; +} diff --git a/server/sonar-web/src/main/js/components/ui/DuplicationsRating.js b/server/sonar-web/src/main/js/components/ui/DuplicationsRating.js deleted file mode 100644 index 628adac1d1b..00000000000 --- a/server/sonar-web/src/main/js/components/ui/DuplicationsRating.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 classNames from 'classnames'; -import { inRange } from 'lodash'; -import './DuplicationsRating.css'; - -export default class DuplicationsRating extends React.PureComponent { - /*:: props: { - value: number, - size?: 'small' | 'normal' | 'big' | 'huge', - muted?: boolean - }; -*/ - - static defaultProps = { - small: false, - muted: false - }; - - render() { - const { value, size, muted } = this.props; - const className = classNames('duplications-rating', { - 'duplications-rating-small': size === 'small', - 'duplications-rating-big': size === 'big', - 'duplications-rating-huge': size === 'huge', - 'duplications-rating-muted': muted, - 'duplications-rating-A': inRange(value, 0, 3), - 'duplications-rating-B': inRange(value, 3, 5), - 'duplications-rating-C': inRange(value, 5, 10), - 'duplications-rating-D': inRange(value, 10, 20), - 'duplications-rating-E': value >= 20 - }); - - return <div className={className} />; - } -} diff --git a/server/sonar-web/src/main/js/components/ui/DuplicationsRating.tsx b/server/sonar-web/src/main/js/components/ui/DuplicationsRating.tsx new file mode 100644 index 00000000000..01703bafa31 --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/DuplicationsRating.tsx @@ -0,0 +1,45 @@ +/* + * 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 * as React from 'react'; +import * as classNames from 'classnames'; +import { inRange } from 'lodash'; +import './DuplicationsRating.css'; + +interface Props { + muted?: boolean; + size?: 'small' | 'normal' | 'big' | 'huge'; + value: number; +} + +export default function DuplicationsRating({ muted = false, size = 'normal', value }: Props) { + const className = classNames('duplications-rating', { + 'duplications-rating-small': size === 'small', + 'duplications-rating-big': size === 'big', + 'duplications-rating-huge': size === 'huge', + 'duplications-rating-muted': muted, + 'duplications-rating-A': inRange(value, 0, 3), + 'duplications-rating-B': inRange(value, 3, 5), + 'duplications-rating-C': inRange(value, 5, 10), + 'duplications-rating-D': inRange(value, 10, 20), + 'duplications-rating-E': value >= 20 + }); + + return <div className={className} />; +} diff --git a/server/sonar-web/src/main/js/components/ui/OrganizationLink.js b/server/sonar-web/src/main/js/components/ui/OrganizationLink.tsx index 9251d1ae863..a5cc9d56804 100644 --- a/server/sonar-web/src/main/js/components/ui/OrganizationLink.js +++ b/server/sonar-web/src/main/js/components/ui/OrganizationLink.tsx @@ -17,18 +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 React from 'react'; +import * as React from 'react'; import { Link } from 'react-router'; -export default function OrganizationLink( - props /*: { - children?: React.Element<*>, - organization: { - key: string - } -} */ -) { +interface Props { + children?: React.ReactNode; + organization: { key: string }; + [x: string]: any; +} + +export default function OrganizationLink(props: Props) { const { children, organization, ...other } = props; return ( diff --git a/server/sonar-web/src/main/js/components/ui/Rating.js b/server/sonar-web/src/main/js/components/ui/Rating.js deleted file mode 100644 index 0ec18df9e7c..00000000000 --- a/server/sonar-web/src/main/js/components/ui/Rating.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 PropTypes from 'prop-types'; -import classNames from 'classnames'; -import { formatMeasure } from '../../helpers/measures'; -import './Rating.css'; - -export default class Rating extends React.PureComponent { - static propTypes = { - className: PropTypes.string, - value: (props, propName, componentName) => { - // allow both numbers and strings - const numberValue = Number(props[propName]); - if (numberValue < 1 || numberValue > 5) { - throw new Error(`Invalid prop "${propName}" passed to "${componentName}".`); - } - }, - small: PropTypes.bool, - muted: PropTypes.bool - }; - - static defaultProps = { - small: false, - muted: false - }; - - render() { - const formatted = formatMeasure(this.props.value, 'RATING'); - const className = classNames( - 'rating', - 'rating-' + formatted, - { - 'rating-small': this.props.small, - 'rating-muted': this.props.muted - }, - this.props.className - ); - return <span className={className}>{formatted}</span>; - } -} diff --git a/server/sonar-web/src/main/js/components/ui/Rating.tsx b/server/sonar-web/src/main/js/components/ui/Rating.tsx new file mode 100644 index 00000000000..67abfe61782 --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/Rating.tsx @@ -0,0 +1,45 @@ +/* + * 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 * as React from 'react'; +import * as classNames from 'classnames'; +import { formatMeasure } from '../../helpers/measures'; +import './Rating.css'; + +interface Props { + className?: string; + muted?: boolean; + small?: boolean; + value: string | number; +} + +export default function Rating({ className, muted = false, small = false, value }: Props) { + const formatted = formatMeasure(value, 'RATING'); + return ( + <span + className={classNames( + 'rating', + 'rating-' + formatted, + { 'rating-small': small, 'rating-muted': muted }, + className + )}> + {formatted} + </span> + ); +} diff --git a/server/sonar-web/src/main/js/components/ui/SizeRating.js b/server/sonar-web/src/main/js/components/ui/SizeRating.js deleted file mode 100644 index 3518c901225..00000000000 --- a/server/sonar-web/src/main/js/components/ui/SizeRating.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 classNames from 'classnames'; -import { inRange } from 'lodash'; -import './SizeRating.css'; - -export default class SizeRating extends React.PureComponent { - /*:: props: { - value: number, - small?: boolean, - muted?: boolean - }; -*/ - - static defaultProps = { - small: false, - muted: false - }; - - render() { - const { value } = this.props; - - if (value == null) { - return <div className="size-rating size-rating-muted"> </div>; - } - - let letter; - if (inRange(value, 0, 1000)) { - letter = 'XS'; - } else if (inRange(value, 1000, 10000)) { - letter = 'S'; - } else if (inRange(value, 10000, 100000)) { - letter = 'M'; - } else if (inRange(value, 100000, 500000)) { - letter = 'L'; - } else if (value >= 500000) { - letter = 'XL'; - } - - const className = classNames('size-rating', { - 'size-rating-small': this.props.small, - 'size-rating-muted': this.props.muted - }); - - return <div className={className}>{letter}</div>; - } -} diff --git a/server/sonar-web/src/main/js/components/ui/SizeRating.tsx b/server/sonar-web/src/main/js/components/ui/SizeRating.tsx new file mode 100644 index 00000000000..d4a657676c0 --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/SizeRating.tsx @@ -0,0 +1,55 @@ +/* + * 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 * as React from 'react'; +import * as classNames from 'classnames'; +import { inRange } from 'lodash'; +import './SizeRating.css'; + +interface Props { + muted?: boolean; + small?: boolean; + value: number | null | undefined; +} + +export default function SizeRating({ small = false, muted = false, value }: Props) { + if (value == null) { + return <div className="size-rating size-rating-muted"> </div>; + } + + let letter; + if (inRange(value, 0, 1000)) { + letter = 'XS'; + } else if (inRange(value, 1000, 10000)) { + letter = 'S'; + } else if (inRange(value, 10000, 100000)) { + letter = 'M'; + } else if (inRange(value, 100000, 500000)) { + letter = 'L'; + } else if (value >= 500000) { + letter = 'XL'; + } + + const className = classNames('size-rating', { + 'size-rating-small': small, + 'size-rating-muted': muted + }); + + return <div className={className}>{letter}</div>; +} diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/OrganizationLink-test.tsx b/server/sonar-web/src/main/js/components/ui/__tests__/OrganizationLink-test.tsx new file mode 100644 index 00000000000..feffbe8c87f --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/__tests__/OrganizationLink-test.tsx @@ -0,0 +1,26 @@ +/* + * 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. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import OrganizationLink from '../OrganizationLink'; + +it('renders', () => { + expect(shallow(<OrganizationLink organization={{ key: 'org' }} />)).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/OrganizationLink-test.tsx.snap b/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/OrganizationLink-test.tsx.snap new file mode 100644 index 00000000000..147ffccb64f --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/OrganizationLink-test.tsx.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` +<Link + onlyActiveOnIndex={false} + style={Object {}} + to="/organizations/org" +/> +`; |