Ver código fonte

SONAR-9254 Add analysis date sorting on projects page

tags/6.5-M1
Grégoire Aubert 7 anos atrás
pai
commit
36a4866a99

+ 2
- 7
server/sonar-web/src/main/js/apps/projects/components/AllProjects.js Ver arquivo

@@ -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);

+ 27
- 10
server/sonar-web/src/main/js/apps/projects/components/DefaultPageSelector.js Ver arquivo

@@ -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 (

+ 2
- 0
server/sonar-web/src/main/js/apps/projects/store/utils.js Ver arquivo

@@ -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',

+ 3
- 0
server/sonar-web/src/main/js/apps/projects/utils.js Ver arquivo

@@ -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',

+ 1
- 0
sonar-core/src/main/resources/org/sonar/l10n/core.properties Ver arquivo

@@ -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

Carregando…
Cancelar
Salvar