diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-06-10 17:37:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-10 17:37:21 +0200 |
commit | c6c7bf08a06b6884785cc12e5d39e20ed9b3a36b (patch) | |
tree | 856f132b1fff3687ef27d1fbca4f708884661521 /server/sonar-web/src/main/js/components/ui/Rating.js | |
parent | c321ee96905615ae8608e3047c5a5f0695e65bf2 (diff) | |
download | sonarqube-c6c7bf08a06b6884785cc12e5d39e20ed9b3a36b.tar.gz sonarqube-c6c7bf08a06b6884785cc12e5d39e20ed9b3a36b.zip |
refactor react components (#1033)
Diffstat (limited to 'server/sonar-web/src/main/js/components/ui/Rating.js')
-rw-r--r-- | server/sonar-web/src/main/js/components/ui/Rating.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/components/ui/Rating.js b/server/sonar-web/src/main/js/components/ui/Rating.js new file mode 100644 index 00000000000..90b0c75cc5e --- /dev/null +++ b/server/sonar-web/src/main/js/components/ui/Rating.js @@ -0,0 +1,40 @@ +/* + * 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 React from 'react'; +import { formatMeasure } from '../../helpers/measures'; + +export default class Rating extends React.Component { + static propTypes = { + 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}".`); + } + } + }; + + render () { + const formatted = formatMeasure(this.props.value, 'RATING'); + const className = 'rating rating-' + formatted; + return <span className={className}>{formatted}</span>; + } +} |