]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20947 Order the failing conditions on the same order as the CaYC conditions...
authorAndrey Luiz <andrey.luiz@sonarsource.com>
Fri, 2 Feb 2024 13:19:06 +0000 (14:19 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 2 Feb 2024 20:02:30 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/overview/branches/QualityGateConditions.tsx
server/sonar-web/src/main/js/apps/quality-gates/utils.ts

index de461bfb406d65ad6f7d25ac7be4d2de2bed09ac..6b0f86f3659628acddca25b8540c2c587fdabcc5 100644 (file)
@@ -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<QualityGateConditionsProps
     [isBuiltInQualityGate],
   );
 
-  const sortedConditions = sortBy(failedConditions, (condition) =>
-    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;
index 11cd84b62855d8e38dcdd8ed78be9d98fbb3c4de..34353e50a9e0ccd4e53528c70cf6c978ad30f40c 100644 (file)
@@ -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<number> = [
-  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<number>);
+export const CAYC_CONDITION_ORDER_PRIORITIES: Dict<number> = {
+  [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;
 }