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 {
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 (
export const mapMetricToProperty = metricKey => {
const map = {
+ analysisDate: 'analysis_date',
reliability_rating: 'reliability',
new_reliability_rating: 'new_reliability',
security_rating: 'security',
export const mapPropertyToMetric = property => {
const map = {
+ analysis_date: 'analysisDate',
reliability: 'reliability_rating',
new_reliability: 'new_reliability_rating',
security: 'security_rating',
export const SORTING_METRICS = [
{ value: 'name' },
+ { value: 'analysis_date' },
{ value: 'reliability' },
{ value: 'security' },
{ value: 'maintainability' },
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' },
];
export const SORTING_SWITCH = {
+ analysis_date: 'analysis_date',
name: 'name',
reliability: 'new_reliability',
security: 'new_security',