From 46a70239fa534545b84c3b057a48891f9a441eef Mon Sep 17 00:00:00 2001 From: Guillaume Peoc'h Date: Wed, 30 Mar 2022 11:53:05 +0200 Subject: [PATCH] SONAR-16092 Update SelectLegacy in app and component --- .../projectInformation/badges/BadgeParams.tsx | 28 +++++----- .../__snapshots__/BadgeParams-test.tsx.snap | 37 ++++++------- .../activity-graph/GraphsHeader.tsx | 9 ++-- .../main/js/components/controls/DateInput.tsx | 52 ++++++++++++------- .../controls/OutsideClickHandler.tsx | 6 ++- .../__tests__/OutsideClickHandler-test.tsx | 1 + .../__snapshots__/DateInput-test.tsx.snap | 18 +++++-- .../main/js/components/controls/styles.css | 4 +- 8 files changed, 92 insertions(+), 63 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/BadgeParams.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/BadgeParams.tsx index 97a10e3e5c6..e663e2482f2 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/BadgeParams.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/BadgeParams.tsx @@ -20,7 +20,7 @@ import classNames from 'classnames'; import * as React from 'react'; import { fetchWebApi } from '../../../../../../api/web-api'; -import SelectLegacy from '../../../../../../components/controls/SelectLegacy'; +import Select from '../../../../../../components/controls/Select'; import { getLocalizedMetricName, translate } from '../../../../../../helpers/l10n'; import { Dict, Metric } from '../../../../../../types/types'; import withMetricsContext from '../../../../metrics/withMetricsContext'; @@ -78,7 +78,7 @@ export class BadgeParams extends React.PureComponent { getFormatOptions = () => { return ['md', 'url'].map(format => ({ label: translate('overview.badges.options.formats', format), - value: format + value: format as BadgeFormats })); }; @@ -102,20 +102,19 @@ export class BadgeParams extends React.PureComponent { renderBadgeType = (type: BadgeType, options: BadgeOptions) => { if (type === BadgeType.measure) { + const metricOptions = this.getMetricOptions(); return ( <> - o.value === options.metric)} /> ); @@ -125,6 +124,7 @@ export class BadgeParams extends React.PureComponent { render() { const { className, options, type } = this.props; + const formatOptions = this.getFormatOptions(); return (
{this.renderBadgeType(type, options)} @@ -136,14 +136,14 @@ export class BadgeParams extends React.PureComponent { htmlFor="badge-format"> {translate('format')}: - o.value === options.format)} + defaultValue={formatOptions.find(o => o.value === 'md')} />
); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/__tests__/__snapshots__/BadgeParams-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/__tests__/__snapshots__/BadgeParams-test.tsx.snap index a9a46bf033a..5134dcb90da 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/__tests__/__snapshots__/BadgeParams-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/badges/__tests__/__snapshots__/BadgeParams-test.tsx.snap @@ -9,19 +9,12 @@ exports[`should display measure badge params 1`] = ` overview.badges.metric : - - `; diff --git a/server/sonar-web/src/main/js/components/activity-graph/GraphsHeader.tsx b/server/sonar-web/src/main/js/components/activity-graph/GraphsHeader.tsx index 357cb797eef..1d0faa676e3 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/GraphsHeader.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/GraphsHeader.tsx @@ -22,7 +22,7 @@ import * as React from 'react'; import { translate } from '../../helpers/l10n'; import { GraphType } from '../../types/project-activity'; import { Metric } from '../../types/types'; -import SelectLegacy from '../controls/SelectLegacy'; +import Select from '../controls/Select'; import AddGraphMetric from './AddGraphMetric'; import './styles.css'; import { getGraphTypes, isCustomGraph } from './utils'; @@ -65,13 +65,12 @@ export default class GraphsHeader extends React.PureComponent { return (
- option.value === graph)} /> {isCustomGraph(graph) && addCustomMetric !== undefined && diff --git a/server/sonar-web/src/main/js/components/controls/DateInput.tsx b/server/sonar-web/src/main/js/components/controls/DateInput.tsx index 90414acaf87..4658ac4eb58 100644 --- a/server/sonar-web/src/main/js/components/controls/DateInput.tsx +++ b/server/sonar-web/src/main/js/components/controls/DateInput.tsx @@ -31,7 +31,7 @@ import ChevronRightIcon from '../../components/icons/ChevronRightIcon'; import { getShortMonthName, getShortWeekDayName, getWeekDayName } from '../../helpers/l10n'; import { lazyLoadComponent } from '../lazyLoadComponent'; import './DayPicker.css'; -import SelectLegacy from './SelectLegacy'; +import Select from './Select'; import './styles.css'; const DayPicker = lazyLoadComponent(() => import('react-day-picker'), 'DayPicker'); @@ -118,8 +118,17 @@ export default class DateInput extends React.PureComponent { }; render() { - const { highlightFrom, highlightTo, minDate, value } = this.props; - const { lastHovered } = this.state; + const { + highlightFrom, + highlightTo, + minDate, + value, + name, + className, + inputClassName, + placeholder + } = this.props; + const { lastHovered, currentMonth, open } = this.state; const after = this.props.maxDate || new Date(); @@ -142,50 +151,53 @@ export default class DateInput extends React.PureComponent { const weekdaysLong = range(7).map(getWeekDayName) as Week; const weekdaysShort = range(7).map(getShortWeekDayName) as Week; + const monthOptions = months.map(month => ({ + label: getShortMonthName(month), + value: month + })); + const yearOptions = years.map(year => ({ label: String(year), value: year })); + return ( - + (this.input = node)} - name={this.props.name} + name={name} onFocus={this.openCalendar} - placeholder={this.props.placeholder} + placeholder={placeholder} readOnly={true} type="text" value={value} /> - {this.props.value !== undefined && ( + {value !== undefined && ( )} - {this.state.open && ( + {open && (