diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/coding-rules/components')
13 files changed, 11 insertions, 240 deletions
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/AttributeCategoryFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/AttributeCategoryFacet.tsx index c314a1150cf..76f99ceeb88 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/AttributeCategoryFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/AttributeCategoryFacet.tsx @@ -18,9 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import Facet, { BasicProps } from '../../../components/facets/Facet'; import { CLEAN_CODE_CATEGORIES } from '../../../helpers/constants'; import { translate } from '../../../helpers/l10n'; -import Facet, { BasicProps } from './Facet'; export default function AttributeCategoryFacet(props: BasicProps) { const renderName = React.useCallback( diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormFieldsCCT.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormFieldsCCT.tsx index 94e0d1f4447..5482b9a4147 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormFieldsCCT.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormFieldsCCT.tsx @@ -133,7 +133,7 @@ export function SoftwareQualitiesFields( () => IMPACT_SEVERITIES.map((severity) => ({ value: severity, - label: intl.formatMessage({ id: `severity.${severity}` }), + label: intl.formatMessage({ id: `severity_impact.${severity}` }), Icon: <SoftwareImpactSeverityIcon severity={severity} />, })), [intl], diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx deleted file mode 100644 index 2f594df563f..00000000000 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * 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 { FacetBox, FacetItem } from 'design-system'; -import { orderBy, sortBy, without } from 'lodash'; -import * as React from 'react'; -import { formatMeasure } from '~sonar-aligned/helpers/measures'; -import { MetricType } from '~sonar-aligned/types/metrics'; -import Tooltip from '../../../components/controls/Tooltip'; -import { translate } from '../../../helpers/l10n'; -import { Dict } from '../../../types/types'; -import { FacetItemsList } from '../../issues/sidebar/FacetItemsList'; -import { MultipleSelectionHint } from '../../issues/sidebar/MultipleSelectionHint'; -import { FacetKey } from '../query'; - -export interface BasicProps { - help?: React.ReactNode; - onChange: (changes: Dict<string | string[] | undefined>) => void; - onToggle: (facet: FacetKey) => void; - open: boolean; - stats?: Dict<number>; - values: string[]; -} - -interface Props extends BasicProps { - disabled?: boolean; - disabledHelper?: string; - options?: string[]; - property: FacetKey; - renderFooter?: () => React.ReactNode; - renderName?: (value: string, disabled: boolean) => React.ReactNode; - renderTextName?: (value: string) => string; - singleSelection?: boolean; -} - -export default class Facet extends React.PureComponent<Props> { - handleItemClick = (itemValue: string, multiple: boolean) => { - const { values } = this.props; - let newValue; - if (this.props.singleSelection) { - const value = values.length ? values[0] : undefined; - newValue = itemValue === value ? undefined : itemValue; - } else if (multiple) { - newValue = orderBy( - values.includes(itemValue) ? without(values, itemValue) : [...values, itemValue], - ); - } else { - newValue = values.includes(itemValue) && values.length < 2 ? [] : [itemValue]; - } - this.props.onChange({ [this.props.property]: newValue }); - }; - - handleHeaderClick = () => this.props.onToggle(this.props.property); - - handleClear = () => this.props.onChange({ [this.props.property]: [] }); - - getStat = (value: string) => this.props.stats && this.props.stats[value]; - - renderItem = (value: string) => { - const active = this.props.values.includes(value); - const stat = this.getStat(value); - const disabled = stat === 0 || typeof stat === 'undefined'; - const { renderName = defaultRenderName, renderTextName = defaultRenderName } = this.props; - - return ( - <FacetItem - className="it__search-navigator-facet" - active={active} - key={value} - name={renderName(value, disabled)} - onClick={this.handleItemClick} - stat={stat && formatMeasure(stat, MetricType.ShortInteger)} - value={value} - tooltip={renderTextName(value)} - /> - ); - }; - - render() { - const { - disabled, - disabledHelper, - open, - property, - renderTextName = defaultRenderName, - stats, - help, - values, - } = this.props; - const items = - this.props.options || - (stats && - sortBy( - Object.keys(stats), - (key) => -stats[key], - (key) => renderTextName(key).toLowerCase(), - )); - const headerId = `facet_${property}`; - const nbSelectableItems = - items?.filter((item) => (stats ? stats[item] : undefined)).length ?? 0; - const nbSelectedItems = values.length; - - return ( - <FacetBox - className={classNames('it__search-navigator-facet-box', { - 'it__search-navigator-facet-box-forbidden': disabled, - })} - data-property={property} - clearIconLabel={translate('clear')} - count={values.length} - id={headerId} - name={translate('coding_rules.facet', property)} - onClear={this.handleClear} - onClick={disabled ? undefined : this.handleHeaderClick} - open={open && !disabled} - disabled={disabled} - disabledHelper={disabledHelper} - tooltipComponent={Tooltip} - help={help} - > - {open && items !== undefined && ( - <FacetItemsList labelledby={headerId}>{items.map(this.renderItem)}</FacetItemsList> - )} - - {open && this.props.renderFooter !== undefined && this.props.renderFooter()} - - <MultipleSelectionHint - nbSelectableItems={nbSelectableItems} - nbSelectedItems={nbSelectedItems} - /> - </FacetBox> - ); - } -} - -function defaultRenderName(value: string) { - return value; -} diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx index e937feb4806..a1dbda02d91 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx @@ -21,6 +21,7 @@ import { BasicSeparator } from 'design-system'; import * as React from 'react'; import { Profile } from '../../../api/quality-profiles'; import { useAvailableFeatures } from '../../../app/components/available-features/withAvailableFeatures'; +import SeverityFacet from '../../../components/facets/SeverityFacet'; import { translate } from '../../../helpers/l10n'; import { Feature } from '../../../types/features'; import { Dict } from '../../../types/types'; @@ -33,7 +34,6 @@ import InheritanceFacet from './InheritanceFacet'; import PrioritizedRulesFacet from './PrioritizedRulesFacet'; import ProfileFacet from './ProfileFacet'; import RepositoryFacet from './RepositoryFacet'; -import SeverityFacet from './SeverityFacet'; import SoftwareQualityFacet from './SoftwareQualityFacet'; import StatusFacet from './StatusFacet'; import TagFacet from './TagFacet'; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx index 49a5fb2eae4..92080f9afef 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx @@ -18,9 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import Facet, { BasicProps } from '../../../components/facets/Facet'; import { translate } from '../../../helpers/l10n'; import { RuleInheritance } from '../../../types/types'; -import Facet, { BasicProps } from './Facet'; interface Props extends Omit<BasicProps, 'values'> { disabled: boolean; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/PrioritizedRulesFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/PrioritizedRulesFacet.tsx index 66f1cc3b697..f739939fd89 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/PrioritizedRulesFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/PrioritizedRulesFacet.tsx @@ -18,8 +18,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import Facet, { BasicProps } from '../../../components/facets/Facet'; import { translate } from '../../../helpers/l10n'; -import Facet, { BasicProps } from './Facet'; interface Props extends Omit<BasicProps, 'onChange' | 'values'> { disabled: boolean; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx index f53ba7c4ae4..997f2f4bed1 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx @@ -21,12 +21,12 @@ import { Note } from 'design-system'; import * as React from 'react'; import { getRuleRepositories } from '../../../api/rules'; import withLanguagesContext from '../../../app/components/languages/withLanguagesContext'; +import { BasicProps } from '../../../components/facets/Facet'; import { translate } from '../../../helpers/l10n'; import { highlightTerm } from '../../../helpers/search'; import { Languages } from '../../../types/languages'; import { Dict } from '../../../types/types'; import { ListStyleFacet } from '../../issues/sidebar/ListStyleFacet'; -import { BasicProps } from './Facet'; interface StateProps { languages: Languages; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/SeverityFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/SeverityFacet.tsx deleted file mode 100644 index 6acfbcc3871..00000000000 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/SeverityFacet.tsx +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import { HelperHintIcon } from 'design-system'; -import * as React from 'react'; -import DocHelpTooltip from '~sonar-aligned/components/controls/DocHelpTooltip'; -import SoftwareImpactSeverityIcon from '../../../components/icon-mappers/SoftwareImpactSeverityIcon'; -import { IMPACT_SEVERITIES } from '../../../helpers/constants'; -import { DocLink } from '../../../helpers/doc-links'; -import { translate } from '../../../helpers/l10n'; -import Facet, { BasicProps } from './Facet'; - -export default function SeverityFacet(props: BasicProps) { - const renderName = React.useCallback( - (severity: string, disabled: boolean) => ( - <div className="sw-flex sw-items-center"> - <SoftwareImpactSeverityIcon severity={severity} disabled={disabled} /> - <span className="sw-ml-1">{translate('severity', severity)}</span> - </div> - ), - [], - ); - - const renderTextName = React.useCallback( - (severity: string) => translate('severity', severity), - [], - ); - - return ( - <Facet - {...props} - options={IMPACT_SEVERITIES} - property="impactSeverities" - renderName={renderName} - renderTextName={renderTextName} - help={ - <DocHelpTooltip - placement="right" - content={ - <> - <p>{translate('issues.facet.impactSeverities.help.line1')}</p> - <p className="sw-mt-2">{translate('issues.facet.impactSeverities.help.line2')}</p> - </> - } - links={[ - { - href: DocLink.CleanCodeIntroduction, - label: translate('learn_more'), - }, - ]} - > - <HelperHintIcon /> - </DocHelpTooltip> - } - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/SoftwareQualityFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/SoftwareQualityFacet.tsx index 1097682a5aa..26151da5286 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/SoftwareQualityFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/SoftwareQualityFacet.tsx @@ -18,9 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import Facet, { BasicProps } from '../../../components/facets/Facet'; import { SOFTWARE_QUALITIES } from '../../../helpers/constants'; import { translate } from '../../../helpers/l10n'; -import Facet, { BasicProps } from './Facet'; export default function SoftwareQualityFacet(props: BasicProps) { const renderName = React.useCallback( diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/StatusFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/StatusFacet.tsx index 8fcd7092240..e7d03dc66d2 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/StatusFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/StatusFacet.tsx @@ -18,9 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import Facet, { BasicProps } from '../../../components/facets/Facet'; import { RULE_STATUSES } from '../../../helpers/constants'; import { translate } from '../../../helpers/l10n'; -import Facet, { BasicProps } from './Facet'; export default class StatusFacet extends React.PureComponent<BasicProps> { renderName = (status: string) => translate('rules.status', status.toLowerCase()); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/TagFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/TagFacet.tsx index 78c3fd4a660..ae3b0b11a13 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/TagFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/TagFacet.tsx @@ -20,10 +20,10 @@ import { uniq } from 'lodash'; import * as React from 'react'; import { getRuleTags } from '../../../api/rules'; +import { BasicProps } from '../../../components/facets/Facet'; import { translate } from '../../../helpers/l10n'; import { highlightTerm } from '../../../helpers/search'; import { ListStyleFacet } from '../../issues/sidebar/ListStyleFacet'; -import { BasicProps } from './Facet'; export default class TagFacet extends React.PureComponent<BasicProps> { handleSearch = (query: string) => { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx index 87fdc3d87cf..3d49c68bcb9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx @@ -20,8 +20,8 @@ import { HelperHintIcon } from 'design-system'; import * as React from 'react'; import HelpTooltip from '~sonar-aligned/components/controls/HelpTooltip'; +import Facet, { BasicProps } from '../../../components/facets/Facet'; import { translate } from '../../../helpers/l10n'; -import Facet, { BasicProps } from './Facet'; interface Props extends Omit<BasicProps, 'onChange' | 'values'> { onChange: (changes: { template: boolean | undefined }) => void; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/TypeFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/TypeFacet.tsx index c92a3c11697..09ba4b0635d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/TypeFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/TypeFacet.tsx @@ -18,10 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import Facet, { BasicProps } from '../../../components/facets/Facet'; import IssueTypeIcon from '../../../components/icon-mappers/IssueTypeIcon'; import { RULE_TYPES } from '../../../helpers/constants'; import { translate } from '../../../helpers/l10n'; -import Facet, { BasicProps } from './Facet'; export default class TypeFacet extends React.PureComponent<BasicProps> { renderName = (type: string) => ( |