]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9254 Add analysis date sorting on projects page
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 30 May 2017 08:11:27 +0000 (10:11 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 9 Jun 2017 06:26:48 +0000 (08:26 +0200)
server/sonar-web/src/main/js/apps/projects/components/AllProjects.js
server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js
server/sonar-web/src/main/js/apps/projects/store/utils.js
server/sonar-web/src/main/js/apps/projects/utils.js
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 46d752be2db8a391d126802253bdd52ede656885..f1f8356335281a944edd18eabafd1821e68e7502 100644 (file)
@@ -95,13 +95,8 @@ export default class AllProjects extends React.PureComponent {
     }
   };
 
-  handleSortChange = (sort: string, desc: boolean) => {
-    if (sort === 'name' && !desc) {
-      this.updateLocationQuery({ sort: undefined });
-    } else {
-      this.updateLocationQuery({ sort: (desc ? '-' : '') + sort });
-    }
-  };
+  handleSortChange = (sort: string, desc: boolean) =>
+    this.updateLocationQuery({ sort: (desc ? '-' : '') + sort });
 
   handleQueryChange() {
     const query = parseUrlQuery(this.props.location.query);
index aa306689acd07729f2d2dde8b56db1273f06fae2..b8673473218b97cf45edbfa3453737a16b24ef8d 100644 (file)
@@ -29,11 +29,14 @@ import { searchProjects } from '../../../api/components';
 type Props = {
   currentUser: { isLoggedIn: boolean },
   location: { query: {} },
-  router: { replace: (path: string) => void }
+  router: {
+    replace: (location: { pathname?: string, query?: { [string]: string } }) => void
+  }
 };
 
 type State = {
-  shouldBeRedirected?: boolean
+  shouldBeRedirected?: boolean,
+  shouldForceSorting?: string
 };
 
 class DefaultPageSelector extends React.PureComponent {
@@ -53,35 +56,49 @@ class DefaultPageSelector extends React.PureComponent {
     if (prevProps.location !== this.props.location) {
       this.defineIfShouldBeRedirected();
     } else if (this.state.shouldBeRedirected === true) {
-      this.props.router.replace('/projects/favorite');
+      this.props.router.replace({ ...this.props.location, pathname: '/projects/favorite' });
+    } else if (this.state.shouldForceSorting != null) {
+      this.props.router.replace({
+        ...this.props.location,
+        query: {
+          ...this.props.location.query,
+          sort: this.state.shouldForceSorting
+        }
+      });
     }
   }
 
   defineIfShouldBeRedirected() {
     if (Object.keys(this.props.location.query).length > 0) {
       // show ALL projects when there are some filters
-      this.setState({ shouldBeRedirected: false });
+      this.setState({ shouldBeRedirected: false, shouldForceSorting: undefined });
     } else if (!this.props.currentUser.isLoggedIn) {
       // show ALL projects if user is anonymous
-      this.setState({ shouldBeRedirected: false });
+      if (!this.props.location.query || !this.props.location.query.sort) {
+        // force default sorting to last analysis date
+        this.setState({ shouldBeRedirected: false, shouldForceSorting: '-analysis_date' });
+      } else {
+        this.setState({ shouldBeRedirected: false, shouldForceSorting: undefined });
+      }
     } else if (isFavoriteSet()) {
       // show FAVORITE projects if "favorite" setting is explicitly set
-      this.setState({ shouldBeRedirected: true });
+      this.setState({ shouldBeRedirected: true, shouldForceSorting: undefined });
     } else if (isAllSet()) {
       // show ALL projects if "all" setting is explicitly set
-      this.setState({ shouldBeRedirected: false });
+      this.setState({ shouldBeRedirected: false, shouldForceSorting: undefined });
     } else {
       // otherwise, request favorites
-      this.setState({ shouldBeRedirected: undefined });
+      this.setState({ shouldBeRedirected: undefined, shouldForceSorting: undefined });
       searchProjects({ filter: 'isFavorite', ps: 1 }).then(r => {
         // show FAVORITE projects if there are any
-        this.setState({ shouldBeRedirected: r.paging.total > 0 });
+        this.setState({ shouldBeRedirected: r.paging.total > 0, shouldForceSorting: undefined });
       });
     }
   }
 
   render() {
-    if (this.state.shouldBeRedirected == null || this.state.shouldBeRedirected === true) {
+    const { shouldBeRedirected, shouldForceSorting } = this.state;
+    if (shouldBeRedirected == null || shouldBeRedirected === true || shouldForceSorting != null) {
       return null;
     } else {
       return (
index 13db6e4c7cb1a378cce37d6cbef5aeea2bb260a0..2fdac8465447a30738773cb8906c881a67fc1e82 100644 (file)
@@ -78,6 +78,7 @@ export const parseUrlQuery = urlQuery => ({
 
 export const mapMetricToProperty = metricKey => {
   const map = {
+    analysisDate: 'analysis_date',
     reliability_rating: 'reliability',
     new_reliability_rating: 'new_reliability',
     security_rating: 'security',
@@ -100,6 +101,7 @@ export const mapMetricToProperty = metricKey => {
 
 export const mapPropertyToMetric = property => {
   const map = {
+    analysis_date: 'analysisDate',
     reliability: 'reliability_rating',
     new_reliability: 'new_reliability_rating',
     security: 'security_rating',
index ab4d157c3a2bb5c259812d3b9ca53ef97464272f..85d898e64a09af72a81c0d0884015509999ec95b 100644 (file)
@@ -49,6 +49,7 @@ export const saveFavorite = () => save(LOCALSTORAGE_FAVORITE);
 
 export const SORTING_METRICS = [
   { value: 'name' },
+  { value: 'analysis_date' },
   { value: 'reliability' },
   { value: 'security' },
   { value: 'maintainability' },
@@ -59,6 +60,7 @@ export const SORTING_METRICS = [
 
 export const SORTING_LEAK_METRICS = [
   { value: 'name' },
+  { value: 'analysis_date' },
   { value: 'new_reliability', complement: 'on_new_code' },
   { value: 'new_security', complement: 'on_new_code' },
   { value: 'new_maintainability', complement: 'on_new_code' },
@@ -68,6 +70,7 @@ export const SORTING_LEAK_METRICS = [
 ];
 
 export const SORTING_SWITCH = {
+  analysis_date: 'analysis_date',
   name: 'name',
   reliability: 'new_reliability',
   security: 'new_security',
index 957a773a6b187915341f38f42dfda17b316a1446..2a0e497caa8a012f87dcfdffd7defea977a754d5 100644 (file)
@@ -869,6 +869,7 @@ projects.sort_by=Sort by
 projects.sort_ascending=Result sorted in ascending order
 projects.sort_descending=Result sorted in descending order
 projects.sorting.name=Name (default)
+projects.sorting.analysis_date=Last analysis date
 projects.sorting.reliability=Reliability
 projects.sorting.security=Security
 projects.sorting.maintainability=Maintainability