]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16823 Buttons have same name but different actions
authorMathieu Suen <mathieu.suen@sonarsource.com>
Thu, 25 Aug 2022 10:33:16 +0000 (12:33 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 25 Aug 2022 20:03:09 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx
server/sonar-web/src/main/js/components/facet/FacetHeader.tsx
server/sonar-web/src/main/js/components/facet/ListStyleFacet.tsx
server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx
server/sonar-web/src/main/js/components/facet/__tests__/__snapshots__/ListStyleFacet-test.tsx.snap
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 7be20e1a1cb68b7e8afceccc0b536e4ffb7760c8..f77224b01c784301e590784e580c0313d84994ec 100644 (file)
@@ -20,7 +20,6 @@
 import classNames from 'classnames';
 import { orderBy, sortBy, without } from 'lodash';
 import * as React from 'react';
-import Tooltip from '../../../components/controls/Tooltip';
 import FacetBox from '../../../components/facet/FacetBox';
 import FacetHeader from '../../../components/facet/FacetHeader';
 import FacetItem from '../../../components/facet/FacetItem';
@@ -110,11 +109,9 @@ export default class Facet extends React.PureComponent<Props> {
         className={classNames({ 'search-navigator-facet-box-forbidden': disabled })}
         property={this.props.property}>
         <FacetHeader
-          name={
-            <Tooltip overlay={disabled ? this.props.disabledHelper : undefined}>
-              <span>{translate('coding_rules.facet', this.props.property)}</span>
-            </Tooltip>
-          }
+          name={translate('coding_rules.facet', this.props.property)}
+          disabled={disabled}
+          disabledHelper={this.props.disabledHelper}
           onClear={this.handleClear}
           onClick={disabled ? undefined : this.handleHeaderClick}
           open={this.props.open && !disabled}
index febd98b02edad148e5573847f179a526e76b7dec..ee06de657517b418dae9d027b58b24b480ebe212 100644 (file)
@@ -23,12 +23,15 @@ import HelpTooltip from '../../components/controls/HelpTooltip';
 import OpenCloseIcon from '../../components/icons/OpenCloseIcon';
 import DeferredSpinner from '../../components/ui/DeferredSpinner';
 import { translate, translateWithParameters } from '../../helpers/l10n';
+import Tooltip from '../controls/Tooltip';
 
 interface Props {
   children?: React.ReactNode;
   fetching?: boolean;
   helper?: string;
-  name: React.ReactNode;
+  disabled?: boolean;
+  disabledHelper?: string;
+  name: string;
   onClear?: () => void;
   onClick?: () => void;
   open: boolean;
@@ -66,9 +69,15 @@ export default class FacetHeader extends React.PureComponent<Props> {
   }
 
   render() {
-    const showClearButton =
-      this.props.values != null && this.props.values.length > 0 && this.props.onClear != null;
-
+    const { disabled, values, disabledHelper, name, open, children, fetching } = this.props;
+    const showClearButton = values != null && values.length > 0 && this.props.onClear != null;
+    const header = disabled ? (
+      <Tooltip overlay={disabledHelper}>
+        <span>{name}</span>
+      </Tooltip>
+    ) : (
+      name
+    );
     return (
       <div className="search-navigator-facet-header-wrapper display-flex-center">
         {this.props.onClick ? (
@@ -77,27 +86,27 @@ export default class FacetHeader extends React.PureComponent<Props> {
               className="button-link"
               type="button"
               onClick={this.handleClick}
-              aria-expanded={this.props.open}
+              aria-expanded={open}
               tabIndex={0}>
-              <OpenCloseIcon className="little-spacer-right" open={this.props.open} />
-              {this.props.name}
+              <OpenCloseIcon className="little-spacer-right" open={open} />
+              {header}
             </button>
             {this.renderHelper()}
           </span>
         ) : (
           <span className="search-navigator-facet-header display-flex-center">
-            {this.props.name}
+            {header}
             {this.renderHelper()}
           </span>
         )}
 
-        {this.props.children}
+        {children}
 
         <span className="search-navigator-facet-header-value spacer-left spacer-right ">
           {this.renderValueIndicator()}
         </span>
 
-        {this.props.fetching && (
+        {fetching && (
           <span className="little-spacer-right">
             <DeferredSpinner />
           </span>
@@ -106,6 +115,7 @@ export default class FacetHeader extends React.PureComponent<Props> {
         {showClearButton && (
           <Button
             className="search-navigator-facet-header-button button-small button-red"
+            aria-label={translateWithParameters('clear_x_filter', name)}
             onClick={this.props.onClear}>
             {translate('clear')}
           </Button>
index d56bfd1b88c7778b8ff15b87752f788d0b330189..206df6595be8eda56775218f2f197c12c01a719f 100644 (file)
@@ -22,7 +22,6 @@ import { sortBy, without } from 'lodash';
 import * as React from 'react';
 import ListFooter from '../../components/controls/ListFooter';
 import SearchBox from '../../components/controls/SearchBox';
-import Tooltip from '../../components/controls/Tooltip';
 import { Alert } from '../../components/ui/Alert';
 import { translate } from '../../helpers/l10n';
 import { formatMeasure } from '../../helpers/measures';
@@ -395,11 +394,9 @@ export default class ListStyleFacet<S> extends React.Component<Props<S>, State<S
         property={this.props.property}>
         <FacetHeader
           fetching={this.props.fetching}
-          name={
-            <Tooltip overlay={disabled ? this.props.disabledHelper : undefined}>
-              <span>{this.props.facetHeader}</span>
-            </Tooltip>
-          }
+          name={this.props.facetHeader}
+          disabled={disabled}
+          disabledHelper={this.props.disabledHelper}
           onClear={this.handleClear}
           onClick={disabled ? undefined : this.handleHeaderClick}
           open={this.props.open && !disabled}
index 8c86352db2a450587054d30cbfdb65fa26df587a..0b1d70d7bf708f2e48dca118f3fdb79acd8ddbb7 100644 (file)
@@ -66,7 +66,7 @@ it('should correctly render a header with helper text', async () => {
 it('should correctly render a header with value data', () => {
   renderFacet(undefined, { values: ['value 1'] });
   expect(screen.getByText('value 1')).toBeInTheDocument();
-  screen.getByRole('button', { name: 'clear' }).click();
+  screen.getByRole('button', { name: 'clear_x_filter.foo' }).click();
   expect(screen.queryByText('value 1')).not.toBeInTheDocument();
 });
 
index ba89dc13bb5161780ffeb552fb5b0c027e4fba10..63f62b3484f11b348d61caea4421c4cca53df1ac 100644 (file)
@@ -6,16 +6,10 @@ exports[`should be disabled 1`] = `
   property="foo"
 >
   <FacetHeader
+    disabled={true}
+    disabledHelper="Disabled helper description"
     fetching={false}
-    name={
-      <Tooltip
-        overlay="Disabled helper description"
-      >
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     open={false}
     values={Array []}
@@ -30,13 +24,7 @@ exports[`should display all selected items 1`] = `
 >
   <FacetHeader
     fetching={false}
-    name={
-      <Tooltip>
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     onClick={[Function]}
     open={true}
@@ -118,13 +106,7 @@ exports[`should render 1`] = `
 >
   <FacetHeader
     fetching={false}
-    name={
-      <Tooltip>
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     onClick={[Function]}
     open={true}
@@ -193,13 +175,7 @@ exports[`should search 1`] = `
 >
   <FacetHeader
     fetching={false}
-    name={
-      <Tooltip>
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     onClick={[Function]}
     open={true}
@@ -259,13 +235,7 @@ exports[`should search 2`] = `
 >
   <FacetHeader
     fetching={false}
-    name={
-      <Tooltip>
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     onClick={[Function]}
     open={true}
@@ -336,13 +306,7 @@ exports[`should search 3`] = `
 >
   <FacetHeader
     fetching={false}
-    name={
-      <Tooltip>
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     onClick={[Function]}
     open={true}
@@ -411,13 +375,7 @@ exports[`should search 4`] = `
 >
   <FacetHeader
     fetching={false}
-    name={
-      <Tooltip>
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     onClick={[Function]}
     open={true}
@@ -451,13 +409,7 @@ exports[`should search 5`] = `
 >
   <FacetHeader
     fetching={false}
-    name={
-      <Tooltip>
-        <span>
-          facet header
-        </span>
-      </Tooltip>
-    }
+    name="facet header"
     onClear={[Function]}
     onClick={[Function]}
     open={true}
index 55fa7879a30e3d67f01ce7c18789fb75daa2c956..f11fd2324484b3bc6431b4266a63ac0cb4046f2c 100644 (file)
@@ -251,6 +251,7 @@ assigned_to=Assigned to
 bulk_change=Bulk Change
 bulleted_point=Bulleted point
 clear=Clear
+clear_x_filter=Clear {0} Filters
 clear_all_filters=Clear All Filters
 coding_rules=Rules
 copy_to_clipboard=Click to copy to clipboard