From: stanislavh Date: Tue, 29 Oct 2024 16:18:21 +0000 (+0100) Subject: SONAR-23299 Update add condition dialog in QG X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=efbf8c38cd84f77471cd884eebaa8e0a2f6be4da;p=sonarqube.git SONAR-23299 Update add condition dialog in QG --- diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionModal.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionModal.tsx index fb5a05cc892..dbf4802d8dc 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionModal.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionModal.tsx @@ -27,10 +27,16 @@ import { useMetrics } from '../../../app/components/metrics/withMetricsContext'; import { translate } from '../../../helpers/l10n'; import { isDiffMetric } from '../../../helpers/measures'; import { useCreateConditionMutation } from '../../../queries/quality-gates'; +import { useStandardExperienceMode } from '../../../queries/settings'; import { MetricKey, MetricType } from '../../../sonar-aligned/types/metrics'; import { Feature } from '../../../types/features'; import { Condition, Metric, QualityGate } from '../../../types/types'; -import { getPossibleOperators, isNonEditableMetric } from '../utils'; +import { + getPossibleOperators, + isNonEditableMetric, + MQR_CONDITIONS_MAP, + STANDARD_CONDITIONS_MAP, +} from '../utils'; import ConditionOperator from './ConditionOperator'; import MetricSelect from './MetricSelect'; import ThresholdInput from './ThresholdInput'; @@ -45,29 +51,14 @@ const FORBIDDEN_METRICS: string[] = [ MetricKey.releasability_rating, MetricKey.security_hotspots, MetricKey.new_security_hotspots, - MetricKey.software_quality_maintainability_rating, - MetricKey.new_software_quality_maintainability_rating, - MetricKey.software_quality_reliability_rating, - MetricKey.new_software_quality_reliability_rating, - MetricKey.software_quality_security_rating, - MetricKey.new_software_quality_security_rating, - MetricKey.effort_to_reach_software_quality_maintainability_rating_a, - MetricKey.software_quality_maintainability_remediation_effort, - MetricKey.new_software_quality_maintainability_remediation_effort, - MetricKey.software_quality_security_remediation_effort, - MetricKey.new_software_quality_security_remediation_effort, - MetricKey.software_quality_reliability_remediation_effort, - MetricKey.new_software_quality_reliability_remediation_effort, - MetricKey.software_quality_maintainability_debt_ratio, - MetricKey.new_software_quality_maintainability_debt_ratio, ]; const ADD_CONDITION_MODAL_ID = 'add-condition-modal'; export default function AddConditionModal({ qualityGate }: Readonly) { + const { data: isStandardMode } = useStandardExperienceMode(); const [open, setOpen] = React.useState(false); const closeModal = React.useCallback(() => setOpen(false), []); - const [errorThreshold, setErrorThreshold] = React.useState(''); const [scope, setScope] = React.useState<'new' | 'overall'>('new'); const [selectedMetric, setSelectedMetric] = React.useState(); @@ -83,6 +74,11 @@ export default function AddConditionModal({ qualityGate }: Readonly) { const { conditions = [] } = qualityGate; + const similarMetricFromAnotherMode = findSimilarConditionMetricFromAnotherMode( + qualityGate.conditions, + selectedMetric, + ); + const availableMetrics = React.useMemo(() => { return differenceWith( map(metrics, (metric) => metric).filter( @@ -90,6 +86,11 @@ export default function AddConditionModal({ qualityGate }: Readonly) { !metric.hidden && !FORBIDDEN_METRIC_TYPES.includes(metric.type) && !FORBIDDEN_METRICS.includes(metric.key) && + !( + isStandardMode + ? Object.values(STANDARD_CONDITIONS_MAP) + : Object.values(MQR_CONDITIONS_MAP) + ).includes(metric.key as MetricKey) && !( metric.key === MetricKey.prioritized_rule_issues && !hasFeature(Feature.PrioritizedRules) @@ -98,7 +99,7 @@ export default function AddConditionModal({ qualityGate }: Readonly) { conditions, (metric, condition) => metric.key === condition.metric, ); - }, [conditions, hasFeature, metrics]); + }, [conditions, hasFeature, metrics, isStandardMode]); const handleFormSubmit = React.useCallback( async (event: React.FormEvent) => { @@ -167,6 +168,7 @@ export default function AddConditionModal({ qualityGate }: Readonly) { label={translate('quality_gates.conditions.fails_when')} > scope === 'new' ? isDiffMetric(m.key) : !isDiffMetric(m.key), @@ -183,6 +185,7 @@ export default function AddConditionModal({ qualityGate }: Readonly) { label={translate('quality_gates.conditions.operator')} > ) { > ) { onOpenChange={setOpen} primaryButton={