From: Andrey Luiz Date: Fri, 2 Feb 2024 13:19:06 +0000 (+0100) Subject: SONAR-20947 Order the failing conditions on the same order as the CaYC conditions... X-Git-Tag: 10.5.0.89998~287 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9c53c1f7a9613126495a3e2e48a934b9d512655c;p=sonarqube.git SONAR-20947 Order the failing conditions on the same order as the CaYC conditions on the Quality Gate page (#10421) --- diff --git a/server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx index de461bfb406..6b0f86f3659 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx @@ -25,6 +25,7 @@ import { BranchLike } from '../../../types/branch-like'; import { MetricKey } from '../../../types/metrics'; import { QualityGateStatusConditionEnhanced } from '../../../types/quality-gates'; import { Component } from '../../../types/types'; +import { CAYC_CONDITION_ORDER_PRIORITIES } from '../../quality-gates/utils'; import QualityGateCondition from './QualityGateCondition'; import QualityGateSimplifiedCondition from './QualityGateSimplifiedCondition'; @@ -54,9 +55,10 @@ export function QualityGateConditions(props: Readonly - LEVEL_ORDER.indexOf(condition.level), - ); + const sortedConditions = sortBy(failedConditions, [ + (condition) => CAYC_CONDITION_ORDER_PRIORITIES[condition.metric], + (condition) => LEVEL_ORDER.indexOf(condition.level), + ]); let renderConditions; let renderCollapsed; diff --git a/server/sonar-web/src/main/js/apps/quality-gates/utils.ts b/server/sonar-web/src/main/js/apps/quality-gates/utils.ts index 11cd84b6285..34353e50a9e 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/utils.ts +++ b/server/sonar-web/src/main/js/apps/quality-gates/utils.ts @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import { sortBy } from 'lodash'; import { getLocalizedMetricName } from '../../helpers/l10n'; import { isDiffMetric } from '../../helpers/measures'; import { MetricKey } from '../../types/metrics'; @@ -122,14 +123,12 @@ const ALL_CAYC_CONDITIONS: Record< ...UNOPTIMIZED_CAYC_CONDITIONS, }; -const CAYC_CONDITION_ORDER_PRIORITIES: Dict = [ - MetricKey.new_violations, - MetricKey.new_security_hotspots_reviewed, - MetricKey.new_coverage, - MetricKey.new_duplicated_lines_density, -] - .reverse() - .reduce((acc, key, i) => ({ ...acc, [key.toString()]: i + 1 }), {} as Dict); +export const CAYC_CONDITION_ORDER_PRIORITIES: Dict = { + [MetricKey.new_violations]: 1, + [MetricKey.new_security_hotspots_reviewed]: 2, + [MetricKey.new_coverage]: 3, + [MetricKey.new_duplicated_lines_density]: 4, +}; const CAYC_CONDITIONS_WITHOUT_FIXED_VALUE: AllCaycMetricKeys[] = [ MetricKey.new_duplicated_lines_density, @@ -226,21 +225,17 @@ export function groupAndSortByPriorityConditions( ): GroupedByMetricConditions { const groupedConditions = groupConditionsByMetric(conditions, isBuiltInQG); - function sortFn(a: Condition, b: Condition) { - const priorityA = CAYC_CONDITION_ORDER_PRIORITIES[a.metric] ?? 0; - const priorityB = CAYC_CONDITION_ORDER_PRIORITIES[b.metric] ?? 0; - const diff = priorityB - priorityA; - if (diff !== 0) { - return diff; - } - return metrics[a.metric].name.localeCompare(metrics[b.metric].name, undefined, { - sensitivity: 'base', - }); - } + const sortFns = [ + (condition: Condition) => CAYC_CONDITION_ORDER_PRIORITIES[condition.metric], + (condition: Condition) => metrics[condition.metric]?.name, + ]; - groupedConditions.newCodeConditions.sort(sortFn); - groupedConditions.overallCodeConditions.sort(sortFn); - groupedConditions.caycConditions.sort(sortFn); + groupedConditions.newCodeConditions = sortBy(groupedConditions.newCodeConditions, sortFns); + groupedConditions.overallCodeConditions = sortBy( + groupedConditions.overallCodeConditions, + sortFns, + ); + groupedConditions.caycConditions = sortBy(groupedConditions.caycConditions, sortFns); return groupedConditions; }