]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8392 Order components by name ascending as default ordering for equalities
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 13 Oct 2017 15:17:39 +0000 (17:17 +0200)
committerTeryk Bellahsene <teryk@users.noreply.github.com>
Mon, 16 Oct 2017 07:34:11 +0000 (09:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeSort.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeSortTest.java
server/sonar-web/src/main/js/apps/component-measures/components/MeasureContent.js

index cab5998548840bcca99a2f5d602264f770165133..af94995abd01cab379ec3ecdcb7dc7131b5bfb65 100644 (file)
@@ -86,6 +86,7 @@ public class ComponentTreeSort {
         primaryOrdering = primaryOrdering.compound(secondaryOrdering);
       }
     }
+    primaryOrdering = primaryOrdering.compound(componentNameOrdering(true));
 
     return primaryOrdering.immutableSortedCopy(components);
   }
index 43e47e025a1ae748fa458f6c7eb33eb0e8d1142b..a829d11a9891ffbfbb7cda08094a224336da7b2c 100644 (file)
@@ -137,6 +137,20 @@ public class ComponentTreeSortTest {
       .containsExactly("path-9", "path-8", "path-7", "path-6", "path-5", "path-4", "path-3", "path-2", "path-1", "path-without-measure");
   }
 
+  @Test
+  public void sort_by_name_ascending_in_case_of_equality() {
+    components = newArrayList(
+      newComponentWithoutSnapshotId("PROJECT 12", Qualifiers.PROJECT, "PROJECT_PATH_1"),
+      newComponentWithoutSnapshotId("PROJECT 11", Qualifiers.PROJECT, "PROJECT_PATH_1"),
+      newComponentWithoutSnapshotId("PROJECT 0", Qualifiers.PROJECT, "PROJECT_PATH_2"));
+
+    ComponentTreeWsRequest wsRequest = newRequest(newArrayList(PATH_SORT), false, null);
+
+    List<ComponentDto> result = sortComponents(wsRequest);
+
+    assertThat(result).extracting("name").containsExactly("PROJECT 0", "PROJECT 11", "PROJECT 12");
+  }
+
   @Test
   public void sort_by_alert_status_ascending() {
     components = newArrayList(
index 16ba5d4ba82707c00fcfefd412f766e0ffc207a8..12f3616697daf89f5b894b3db4d9afd41a363a54 100644 (file)
@@ -133,7 +133,7 @@ export default class MeasureContent extends React.PureComponent {
       opts.asc = metric.direction === 1;
       opts.ps = 100;
       opts.metricSort = metric.key;
-      opts.s = isDiff ? 'metricPeriod,name' : 'metric,name';
+      opts.s = isDiff ? 'metricPeriod' : 'metric';
     }
     return { metricKeys, opts: { ...opts, ...options }, strategy };
   };