From 3e53583cc71533a1602f94ffe17feed2fcdeed44 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Fri, 25 Mar 2022 17:43:34 +0100 Subject: [PATCH] SONAR-16086 migrate selectlegacy in component-measures --- .../components/MeasureContent.tsx | 4 +- .../components/MeasureViewSelect.tsx | 55 +++++++++++------ .../__tests__/MeasureViewSelect-test.tsx | 3 +- .../MeasureContent-test.tsx.snap | 16 +++-- .../MeasureViewSelect-test.tsx.snap | 59 +++++++++++++------ .../main/js/apps/component-measures/style.css | 13 ++-- 6 files changed, 98 insertions(+), 52 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx index 130abf96800..fad332407d8 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.tsx @@ -376,7 +376,9 @@ export default class MeasureContent extends React.PureComponent {
{!isFileComponent && metric && ( <> -
{translate('component_measures.view_as')}
+
+ {translate('component_measures.view_as')} +
{ getOptions = () => { const { metric } = this.props; - const options = []; + const options: ViewOption[] = []; if (hasTree(metric.key)) { options.push({ icon: , @@ -62,31 +69,41 @@ export default class MeasureViewSelect extends React.PureComponent { return options; }; - handleChange = (option: { value: string }) => { + handleChange = (option: ViewOption) => { return this.props.handleViewChange(option.value as MeasurePageView); }; - renderOption = (option: { icon: JSX.Element; label: string }) => { - return ( - <> - {option.icon} - {option.label} - - ); - }; + renderOption = (props: OptionProps) => ( + + {props.data.icon} + {props.data.label} + + ); + + renderValue = (props: SingleValueProps) => ( + + {props.data.icon} + {props.data.label} + + ); render() { + const { className, view } = this.props; + const options = this.getOptions(); + return ( - o.value === view)} /> ); } diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx index 557b05229d8..2bb5a708616 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx @@ -19,6 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import ListIcon from '../../../../components/icons/ListIcon'; import { mockMetric } from '../../../../helpers/testMocks'; import { MetricKey } from '../../../../types/metrics'; import MeasureViewSelect from '../MeasureViewSelect'; @@ -38,7 +39,7 @@ it('should render correctly', () => { it('should correctly trigger a selection change', () => { const handleViewChange = jest.fn(); const wrapper = shallowRender({ handleViewChange }); - wrapper.instance().handleChange({ value: 'list' }); + wrapper.instance().handleChange({ icon: , label: 'List View', value: 'list' }); expect(handleViewChange).toBeCalledWith('list'); }); diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap index 8446a01bac0..46fe354db7c 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/MeasureContent-test.tsx.snap @@ -162,7 +162,9 @@ exports[`should render correctly for a project 1`] = ` className="display-flex-center" > -
+
component_measures.view_as
-
+
component_measures.view_as
-
+
component_measures.view_as
-
+
component_measures.view_as
`; exports[`should render correctly: has no tree 1`] = ` -, + "label": "component_measures.tab.list", + "value": "list", + } + } /> `; exports[`should render correctly: has no treemap 1`] = ` -, + "label": "component_measures.tab.list", + "value": "list", + } + } /> `; diff --git a/server/sonar-web/src/main/js/apps/component-measures/style.css b/server/sonar-web/src/main/js/apps/component-measures/style.css index c0915cedb8f..b4e0cdd5d32 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/style.css +++ b/server/sonar-web/src/main/js/apps/component-measures/style.css @@ -134,20 +134,15 @@ } } -.measure-view-select { - width: 102px; -} - -.measure-view-select .Select-menu-outer { - width: 100px; - border-top-right-radius: 4px; -} - .measure-content-header { display: flex; align-items: center; } +.measure-content-header .measure-view-select { + width: 102px; +} + .measure-content-header-left { flex: 1; min-width: 0; -- 2.39.5