* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
import classNames from 'classnames';
import { difference } from 'lodash';
import React, { PureComponent } from 'react';
interface DefaultProps {
filterSelected: (query: string, selectedElements: string[]) => string[];
+ renderAriaLabel: (element: string) => string;
renderLabel: (element: string) => React.ReactNode;
validateSearchInput: (value: string) => string;
}
searchInput?: HTMLInputElement | null;
mounted = false;
- static defaultProps: DefaultProps = {
+ static readonly defaultProps: DefaultProps = {
filterSelected: (query: string, selectedElements: string[]) =>
selectedElements.filter((elem) => elem.includes(query)),
+ renderAriaLabel: (element: string) => element,
renderLabel: (element: string) => element,
validateSearchInput: (value: string) => value,
};
elementsDisabled,
renderTooltip,
} = this.props;
- const { renderLabel } = this.props as PropsWithDefault;
+ const { renderAriaLabel, renderLabel } = this.props as PropsWithDefault;
const { query, activeIdx, selectedElements, unselectedElements } = this.state;
const activeElement = this.getAllElements(this.props, this.state)[activeIdx];
key={element}
onHover={this.handleElementHover}
onSelectChange={this.handleSelectChange}
+ renderAriaLabel={renderAriaLabel}
renderLabel={renderLabel}
renderTooltip={renderTooltip}
selected
key={element}
onHover={this.handleElementHover}
onSelectChange={this.handleSelectChange}
+ renderAriaLabel={renderAriaLabel}
renderLabel={renderLabel}
renderTooltip={renderTooltip}
/>
key={element}
onHover={this.handleElementHover}
onSelectChange={this.handleSelectChange}
+ renderAriaLabel={renderAriaLabel}
renderLabel={renderLabel}
renderTooltip={renderTooltip}
/>
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
import classNames from 'classnames';
import { identity } from 'lodash';
import { PopupPlacement } from '../../helpers';
element: string;
onHover: (element: string) => void;
onSelectChange: (selected: boolean, element: string) => void;
+ renderAriaLabel?: (element: string) => string;
renderLabel?: (element: string) => React.ReactNode;
renderTooltip?: (element: string, disabled: boolean) => React.ReactNode;
selected?: boolean;
}
-export function MultiSelectMenuOption(props: MultiSelectOptionProps) {
+export function MultiSelectMenuOption(props: Readonly<MultiSelectOptionProps>) {
const {
active,
createElementLabel,
disabled = false,
element,
onSelectChange,
- selected,
+ renderAriaLabel = identity,
renderLabel = identity,
renderTooltip,
+ selected,
} = props;
const onHover = () => {
props.onHover(element);
};
+ const ariaLabel = renderAriaLabel(element);
const label = renderLabel(element);
return (
className={classNames('sw-flex sw-py-2 sw-px-4', { active })}
disabled={disabled}
id={element}
- label={element}
+ label={ariaLabel}
onCheck={onSelectChange}
onFocus={onHover}
onPointerEnter={onHover}
import { ProjectActivityServiceMock } from '../../../../api/mocks/ProjectActivityServiceMock';
import { TimeMachineServiceMock } from '../../../../api/mocks/TimeMachineServiceMock';
import { mockBranchList } from '../../../../api/mocks/data/branches';
+import { DEPRECATED_ACTIVITY_METRICS } from '../../../../helpers/constants';
import { parseDate } from '../../../../helpers/dates';
import { mockComponent } from '../../../../helpers/mocks/component';
import {
// Add metrics.
addMetricBtn: byRole('button', { name: 'project_activity.graphs.custom.add' }),
- metricCheckbox: (name: MetricKey) => byRole('checkbox', { name }),
+ metricCheckbox: (name: MetricKey) =>
+ byRole('checkbox', {
+ name: DEPRECATED_ACTIVITY_METRICS.includes(name) ? `${name} (deprecated)` : name,
+ }),
// Graph legend.
newCodeLegend: byText('hotspot.filters.period.since_leak_period'),
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
import { Badge, FlagMessage, MultiSelectMenu } from 'design-system';
import * as React from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
elements,
metricsTypeFilter,
...props
-}: AddGraphMetricPopupProps) {
+}: Readonly<AddGraphMetricPopupProps>) {
const intl = useIntl();
let footerNode: React.ReactNode = '';
);
}
+ const renderAriaLabel = (key: MetricKey) => {
+ const metricName = getLocalizedMetricName({ key });
+ const isDeprecated = DEPRECATED_ACTIVITY_METRICS.includes(key);
+
+ return isDeprecated
+ ? `${metricName} (${intl.formatMessage({ id: 'deprecated' })})`
+ : metricName;
+ };
+
const renderLabel = (key: MetricKey) => {
const metricName = getLocalizedMetricName({ key });
const isDeprecated = DEPRECATED_ACTIVITY_METRICS.includes(key);
onSelect={(item: string) => elements.includes(item) && props.onSelect(item)}
onUnselect={props.onUnselect}
placeholder={translate('search.search_for_metrics')}
+ renderAriaLabel={renderAriaLabel}
renderLabel={renderLabel}
renderTooltip={renderTooltip}
selectedElements={props.selectedElements}
byText,
} from '~sonar-aligned/helpers/testSelector';
import { MetricKey, MetricType } from '~sonar-aligned/types/metrics';
-import { CCT_SOFTWARE_QUALITY_METRICS } from '../../../helpers/constants';
+import {
+ CCT_SOFTWARE_QUALITY_METRICS,
+ DEPRECATED_ACTIVITY_METRICS,
+} from '../../../helpers/constants';
import { parseDate } from '../../../helpers/dates';
import { mockHistoryItem, mockMeasureHistory } from '../../../helpers/mocks/project-activity';
import { mockMetric } from '../../../helpers/testMocks';
maintainabilityIssuesCheckbox: byRole('checkbox', { name: MetricKey.maintainability_issues }),
newBugsCheckbox: byRole('checkbox', { name: MetricKey.new_bugs }),
burnedBudgetCheckbox: byRole('checkbox', { name: MetricKey.burned_budget }),
- vulnerabilityCheckbox: byRole('checkbox', { name: MetricKey.vulnerabilities }),
+ vulnerabilityCheckbox: byRole('checkbox', {
+ name: `${MetricKey.vulnerabilities} (deprecated)`,
+ }),
hiddenOptionsAlert: byText('project_activity.graphs.custom.type_x_message', {
exact: false,
}),
await user.type(ui.filterMetrics.get(), text);
},
async clickOnMetric(name: MetricKey) {
- await user.click(screen.getByRole('checkbox', { name }));
+ await user.click(
+ screen.getByRole('checkbox', {
+ name: DEPRECATED_ACTIVITY_METRICS.includes(name) ? `${name} (deprecated)` : name,
+ }),
+ );
},
async removeMetric(metric: MetricKey) {
await user.click(ui.legendRemoveMetricBtn(metric).get());