From: Wouter Admiraal Date: Mon, 24 Dec 2018 11:35:10 +0000 (+0100) Subject: SONAR-10649 Add Markdown format for badges X-Git-Tag: 7.6~196 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea6102e599b37a73cce37675bff9456338c1f75f;p=sonarqube.git SONAR-10649 Add Markdown format for badges --- diff --git a/server/sonar-web/src/main/js/apps/overview/badges/BadgeParams.tsx b/server/sonar-web/src/main/js/apps/overview/badges/BadgeParams.tsx index ddb7de1f365..5a0041ef106 100644 --- a/server/sonar-web/src/main/js/apps/overview/badges/BadgeParams.tsx +++ b/server/sonar-web/src/main/js/apps/overview/badges/BadgeParams.tsx @@ -18,7 +18,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import { BadgeColors, BadgeType, BadgeOptions } from './utils'; +import * as classNames from 'classnames'; +import { BadgeColors, BadgeType, BadgeOptions, BadgeFormats } from './utils'; import Select from '../../../components/controls/Select'; import { fetchWebApi } from '../../../api/web-api'; import { getLocalizedMetricName, translate } from '../../../helpers/l10n'; @@ -65,66 +66,105 @@ export default class BadgeParams extends React.PureComponent { ); } - getColorOptions = () => - ['white', 'black', 'orange'].map(color => ({ + getColorOptions = () => { + return ['white', 'black', 'orange'].map(color => ({ label: translate('overview.badges.options.colors', color), value: color })); + }; - getMetricOptions = () => - this.state.badgeMetrics.map(key => { + getFormatOptions = () => { + return ['md', 'url'].map(format => ({ + label: translate('overview.badges.options.formats', format), + value: format + })); + }; + + getMetricOptions = () => { + return this.state.badgeMetrics.map(key => { const metric = this.props.metrics[key]; return { value: key, label: metric ? getLocalizedMetricName(metric) : key }; }); + }; - handleColorChange = ({ value }: { value: BadgeColors }) => + handleColorChange = ({ value }: { value: BadgeColors }) => { this.props.updateOptions({ color: value }); + }; - handleMetricChange = ({ value }: { value: string }) => + handleFormatChange = ({ value }: { value: BadgeFormats }) => { + this.props.updateOptions({ format: value }); + }; + + handleMetricChange = ({ value }: { value: string }) => { this.props.updateOptions({ metric: value }); + }; + + renderBadgeType = (type: BadgeType, options: BadgeOptions) => { + if (type === BadgeType.marketing) { + return ( + <> + + + + ); + } else { + return null; + } + }; render() { const { className, options, type } = this.props; - switch (type) { - case BadgeType.marketing: - return ( -
- - -
- ); - default: - return null; - } + return ( +
+ {this.renderBadgeType(type, options)} + + + + + + +
`; diff --git a/server/sonar-web/src/main/js/apps/overview/badges/__tests__/__snapshots__/BadgesModal-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/badges/__tests__/__snapshots__/BadgesModal-test.tsx.snap index 012ed7da821..43a0e7f7638 100644 --- a/server/sonar-web/src/main/js/apps/overview/badges/__tests__/__snapshots__/BadgesModal-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/badges/__tests__/__snapshots__/BadgesModal-test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should display the modal after click on sonar cloud 1`] = ` +exports[`should display the modal after click on sonarcloud 1`] = `
@@ -13,7 +13,7 @@ exports[`should display the modal after click on sonar cloud 1`] = `
`; -exports[`should display the modal after click on sonar cloud 2`] = ` +exports[`should display the modal after click on sonarcloud 2`] = `