Commit e529006d authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

Browser back navigation

parent 566dece5
......@@ -60,6 +60,16 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
applyOverviewFilters(filterCode || '');
}
}
public componentWillReceiveProps(nextProps) {
const { filterCode: prevCode, overview: prevOverview } = this.props;
const { filterCode, applyOverviewFilters, overview } = nextProps;
if (prevOverview && overview && _.isEqual(overview.filter, prevOverview.filter)) {
if (prevCode !== filterCode) {
applyOverviewFilters(filterCode || '');
}
}
}
private addTerm = (property, term) => {
const { overview, applyOverviewFilters, showSnackbar } = this.props;
......
......@@ -4,15 +4,19 @@ import { stringify } from 'query-string';
const IN_BROWSER = typeof window !== 'undefined';
export function navigateTo(path: string, query?: object) {
return (dispatch) => {
return (dispatch, getState) => {
if (! IN_BROWSER) {
console.log('Not navigating anywhere while on the server!');
return;
}
if (! query) {
dispatch(push(path ? path : ''));
} else {
dispatch(push(`${path ? path : ''}?` + stringify(query)));
const location = getState().routing.location.pathname;
if (location !== path) {
if (!query) {
dispatch(push(path ? path : ''));
} else {
dispatch(push(`${ path ? path : '' }?` + stringify(query)));
}
}
};
}
......
......@@ -23,6 +23,7 @@ const mapStateToProps = (state, ownProps) => ({
paged: state.datasets.dashboard.paged,
tab: 'datasets',
dataClassName: Dataset.clazz,
filterCode: ownProps.match.params.filterCode,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
......@@ -21,6 +21,7 @@ const mapStateToProps = (state, ownProps) => ({
paged: state.descriptorList.dashboard.paged,
tab: 'descriptorlists',
dataClassName: DescriptorList.clazz,
filterCode: ownProps.match.params.filterCode,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
......@@ -23,6 +23,7 @@ const mapStateToProps = (state, ownProps) => ({
paged: state.descriptors.dashboard.paged,
tab: 'descriptors',
dataClassName: Descriptor.clazz,
filterCode: ownProps.match.params.filterCode,
filterComponent: DashboardDescriptorFilters,
});
......
......@@ -69,9 +69,13 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
}
public componentWillReceiveProps(nextProps) {
const {applyFilters, filterCode} = this.props;
if (filterCode && (!nextProps.filterCode)) {
applyFilters('');
const { filterCode: prevCode, paged: prevPaged } = this.props;
const { filterCode, applyFilters, paged } = nextProps;
if (prevPaged && paged && _.isEqual(paged.filter, prevPaged.filter)) {
if (prevCode !== filterCode) {
applyFilters(filterCode || '');
}
}
}
......
......@@ -31,6 +31,7 @@ interface IDataPublishedContainerProps extends React.ClassAttributes<any> {
paged: FilteredPage<any>;
preFilter?: object;
basePath: string;
filterCode: string;
filterCodeToUrl: any;
listMyData: any;
dataClassName: string;
......@@ -95,12 +96,18 @@ class BaseMyDataPage<T> extends React.Component<T & IDataPublishedContainerProps
}
public componentWillReceiveProps(nextProps) {
const { filterCodeToUrl, paged } = this.props;
if (paged) {
filterCodeToUrl(paged.filterCode);
const { filterCode: prevCode, paged} = this.props;
const { filterCode, tab, pagination} = nextProps;
// if (paged) {
// filterCodeToUrl(paged.filterCode);
// }
if (paged && paged.filterCode !== filterCode) {
if (filterCode !== prevCode) {
this.loadData(filterCode, tab, pagination.page, pagination.size, pagination.sort, pagination.dir);
}
}
const { tab } = nextProps;
if (tab !== this.state.tab) {
const { pagination } = nextProps;
this.loadData(null, tab, pagination.page, pagination.size, pagination.sort, pagination.dir);
......@@ -114,7 +121,7 @@ class BaseMyDataPage<T> extends React.Component<T & IDataPublishedContainerProps
const Filters = filterComponent ? filterComponent : DashboardFilters;
return (
<ContentLayout customHeaderHeight left={ <Filters initialValues={ pagination.filter } onSubmit={ this.onFilter }/> }>
<ContentLayout customHeaderHeight left={ <Filters initialValues={ paged && paged.filter } onSubmit={ this.onFilter }/> }>
<MyDataTable
tab={ tab }
filterComponent={ filterComponent }
......@@ -151,8 +158,8 @@ class BaseMyDataPage<T> extends React.Component<T & IDataPublishedContainerProps
protected loadData(filter, tab, page, size, sortBy, dir) {
const { listMyData, preFilter, pagination, onPageChange } = this.props;
const newFilters = filter && { ...preFilter, ...filter };
const { listMyData, preFilter, pagination, filterCode, onPageChange } = this.props;
const newFilters = typeof filter === 'string' ? filter : filter && { ...preFilter, ...filter };
// console.log(`Filters code=${filterCode}`, newFilters, preFilter);
if (newFilters || this.state.tab !== tab || this.state.pagination.page !== page || this.state.pagination.size !== size || this.state.pagination.sort !== sortBy || this.state.pagination.dir !== dir) {
......@@ -169,7 +176,7 @@ class BaseMyDataPage<T> extends React.Component<T & IDataPublishedContainerProps
},
}));
listMyData({page, size, sort: [{property: sortBy}], filterCode: newFilters || pagination.filterCode, direction: dir});
listMyData({page, size, sort: [{property: sortBy}], filterCode: newFilters || filterCode, direction: dir});
}
}
}
......
import * as React from 'react';
import * as _ from 'lodash';
// Models
import FilteredPage from 'model/FilteredPage';
......@@ -31,6 +32,17 @@ class BrowsePage<T> extends React.Component<IBrowsePageProps<T> & any, any> {
}
}
public componentWillReceiveProps(nextProps) {
const { filterCode: prevCode, paged: prevPaged } = this.props;
const { filterCode, applyFilters, paged } = nextProps;
if (prevPaged && paged && _.isEqual(paged.filter, prevPaged.filter)) {
if (prevCode !== filterCode) {
applyFilters(filterCode || '');
}
}
}
protected onSortChange = (sortBy: string, dir: SortDirection) => {
const { paged, loadMoreData } = this.props;
loadMoreData(FilteredPage.reSort(paged, sortBy, dir));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment