* 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 * as React from 'react';
+import { Button, ButtonPlain } from '../../../components/controls/buttons';
import Dropdown from '../../../components/controls/Dropdown';
import DropdownIcon from '../../../components/icons/DropdownIcon';
import FilterIcon from '../../../components/icons/FilterIcon';
import IssueTypeIcon from '../../../components/icons/IssueTypeIcon';
import TagsIcon from '../../../components/icons/TagsIcon';
import SeverityHelper from '../../../components/shared/SeverityHelper';
-import { translate } from '../../../helpers/l10n';
+import { translate, translateWithParameters } from '../../../helpers/l10n';
import { Rule } from '../../../types/types';
import { Query } from '../query';
}
export default class SimilarRulesFilter extends React.PureComponent<Props> {
- handleLanguageClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
- event.preventDefault();
- event.currentTarget.blur();
+ handleLanguageClick = () => {
if (this.props.rule.lang) {
this.props.onFilterChange({ languages: [this.props.rule.lang] });
}
};
- handleTypeClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
- event.preventDefault();
- event.currentTarget.blur();
+ handleTypeClick = () => {
this.props.onFilterChange({ types: [this.props.rule.type] });
};
- handleSeverityClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
- event.preventDefault();
- event.currentTarget.blur();
+ handleSeverityClick = () => {
if (this.props.rule.severity) {
this.props.onFilterChange({ severities: [this.props.rule.severity] });
}
};
- handleTagClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
- event.preventDefault();
- event.currentTarget.blur();
- const { tag } = event.currentTarget.dataset;
+ handleTagClick = (tag: string) => {
if (tag) {
this.props.onFilterChange({ tags: [tag] });
}
className="display-inline-block"
overlay={
<>
- <h2 className="menu-header" id="filter-similar-rules">
+ <h3 className="coding-rules-filter-title">
{translate('coding_rules.filter_similar_rules')}
- </h2>
- <ul className="menu" aria-labelledby="filter-similar-rules">
- <li>
- <a
- data-test="coding-rules__similar-language"
- href="#"
- onClick={this.handleLanguageClick}
- >
- {rule.langName}
- </a>
- </li>
-
+ </h3>
+ <ul className="menu">
+ {rule.langName && (
+ <li>
+ <ButtonPlain
+ data-test="coding-rules__similar-language"
+ aria-label={translateWithParameters(
+ 'coding_rules.filter_by_language',
+ rule.langName
+ )}
+ onClick={this.handleLanguageClick}
+ >
+ {rule.langName}
+ </ButtonPlain>
+ </li>
+ )}
<li>
- <a
- className="display-flex-center"
+ <ButtonPlain
+ aria-label={translateWithParameters(
+ 'coding_rules.filter_by_type',
+ translate('issue.type', rule.type)
+ )}
data-test="coding-rules__similar-type"
- href="#"
onClick={this.handleTypeClick}
>
<IssueTypeIcon query={rule.type} />
<span className="little-spacer-left">{translate('issue.type', rule.type)}</span>
- </a>
+ </ButtonPlain>
</li>
{severity && (
<li>
- <a
+ <ButtonPlain
data-test="coding-rules__similar-severity"
- href="#"
+ aria-label={translateWithParameters(
+ 'coding_rules.filter_by_severity',
+ severity
+ )}
onClick={this.handleSeverityClick}
>
- <SeverityHelper className="display-flex-center" severity={rule.severity} />
- </a>
+ <SeverityHelper className="display-flex-center" severity={severity} />
+ </ButtonPlain>
</li>
)}
- {allTags.length > 0 && <li className="divider" />}
- {allTags.map((tag) => (
- <li key={tag}>
- <a
+ {allTags.map((tag, index) => (
+ <li
+ className={classNames('coding-rules-similar-tag', {
+ 'coding-rules-similar-tag-divider': index === 0,
+ })}
+ key={tag}
+ >
+ <ButtonPlain
data-tag={tag}
data-test="coding-rules__similar-tag"
- href="#"
- onClick={this.handleTagClick}
+ aria-label={translateWithParameters('coding_rules.filter_by_tag', tag)}
+ onClick={() => this.handleTagClick(tag)}
>
<TagsIcon className="little-spacer-right text-middle" />
<span className="text-middle">{tag}</span>
- </a>
+ </ButtonPlain>
</li>
))}
</ul>
</>
}
>
- <a
- className="js-rule-filter link-no-underline spacer-left dropdown-toggle"
- href="#"
+ <Button
+ className="js-rule-filter spacer-left"
title={translate('coding_rules.filter_similar_rules')}
>
<FilterIcon />
<DropdownIcon />
- </a>
+ </Button>
</Dropdown>
);
}
className="display-inline-block"
overlay={
<React.Fragment>
- <h2
- className="menu-header"
- id="filter-similar-rules"
+ <h3
+ className="coding-rules-filter-title"
>
coding_rules.filter_similar_rules
- </h2>
+ </h3>
<ul
- aria-labelledby="filter-similar-rules"
className="menu"
>
<li>
- <a
+ <ButtonPlain
+ aria-label="coding_rules.filter_by_language.JavaScript"
data-test="coding-rules__similar-language"
- href="#"
onClick={[Function]}
>
JavaScript
- </a>
+ </ButtonPlain>
</li>
<li>
- <a
- className="display-flex-center"
+ <ButtonPlain
+ aria-label="coding_rules.filter_by_type.issue.type.CODE_SMELL"
data-test="coding-rules__similar-type"
- href="#"
onClick={[Function]}
>
<IssueTypeIcon
>
issue.type.CODE_SMELL
</span>
- </a>
+ </ButtonPlain>
</li>
<li>
- <a
+ <ButtonPlain
+ aria-label="coding_rules.filter_by_severity.MAJOR"
data-test="coding-rules__similar-severity"
- href="#"
onClick={[Function]}
>
<SeverityHelper
className="display-flex-center"
severity="MAJOR"
/>
- </a>
+ </ButtonPlain>
</li>
<li
- className="divider"
- />
- <li>
- <a
+ className="coding-rules-similar-tag coding-rules-similar-tag-divider"
+ >
+ <ButtonPlain
+ aria-label="coding_rules.filter_by_tag.x"
data-tag="x"
data-test="coding-rules__similar-tag"
- href="#"
onClick={[Function]}
>
<TagsIcon
>
x
</span>
- </a>
+ </ButtonPlain>
</li>
- <li>
- <a
+ <li
+ className="coding-rules-similar-tag"
+ >
+ <ButtonPlain
+ aria-label="coding_rules.filter_by_tag.a"
data-tag="a"
data-test="coding-rules__similar-tag"
- href="#"
onClick={[Function]}
>
<TagsIcon
>
a
</span>
- </a>
+ </ButtonPlain>
</li>
- <li>
- <a
+ <li
+ className="coding-rules-similar-tag"
+ >
+ <ButtonPlain
+ aria-label="coding_rules.filter_by_tag.b"
data-tag="b"
data-test="coding-rules__similar-tag"
- href="#"
onClick={[Function]}
>
<TagsIcon
>
b
</span>
- </a>
+ </ButtonPlain>
</li>
</ul>
</React.Fragment>
}
>
- <a
- className="js-rule-filter link-no-underline spacer-left dropdown-toggle"
- href="#"
+ <Button
+ className="js-rule-filter spacer-left"
title="coding_rules.filter_similar_rules"
>
<FilterIcon />
<DropdownIcon />
- </a>
+ </Button>
</Dropdown>
`;