Commit 9a400991 authored by Matija Obreza's avatar Matija Obreza
Browse files

Render filterCode as part of URL path: /subsets/v123532...

parent 4627dd0b
......@@ -23,11 +23,10 @@ export { listSubsets as listSubsetsPromise };
export const updateRoute = (paged: FilteredPage<Subset>) => (dispatch) => {
const qs = {
f: paged.filterCode || undefined,
s: paged.sort[0].property === Subset.DEFAULT_SORT.property ? undefined : paged.sort[0].property,
d: paged.sort[0].direction === Subset.DEFAULT_SORT.direction ? undefined : paged.sort[0].direction,
};
dispatch(navigateTo(null, qs));
dispatch(navigateTo(paged.filterCode ? `/subsets/${paged.filterCode}` : '/subsets', qs));
};
export const applyFilters = (filters: string | SubsetFilter, page: IPageRequest = { page: 0 }) => (dispatch) => {
......
......@@ -10,13 +10,13 @@ function SubsetLink({ to: subset, edit = false, children = null }
if (subset) {
if (edit) {
return (
<Link to={ `/subsets/${subset.uuid}/edit` }>
<Link to={ `/subset/${subset.uuid}/edit` }>
{ children || <Markdown basic source={ subset.title } /> }
</Link>
);
} else {
return (
<Link to={ `/subsets/${subset.uuid}` }>
<Link to={ `/subset/${subset.uuid}` }>
{ children || <Markdown basic source={ subset.title } /> }
</Link>
);
......
......@@ -23,6 +23,7 @@ import SubsetFilters from './c/Filters';
interface IBrowsePageProps extends React.ClassAttributes<any> {
paged: FilteredPage<Subset>;
filterCode: string;
applyFilters: any;
loadSubsetsPage: any;
listSubsetsPromise: any;
......@@ -32,9 +33,9 @@ interface IBrowsePageProps extends React.ClassAttributes<any> {
class BrowsePage extends React.Component<IBrowsePageProps, any> {
protected static needs = [
({ search }) => {
({ search, params: { filterCode } }) => {
const qs = parse(search);
return applyFilters(qs.f, { direction: qs.d, properties: [ ...qs.s ] });
return applyFilters(filterCode || '', { direction: qs.d, properties: [ ...qs.s ] });
},
];
......@@ -43,10 +44,10 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
}
public componentWillMount() {
const { paged, applyFilters, updateRoute } = this.props;
const { paged, filterCode, applyFilters, updateRoute } = this.props;
if (! paged) {
applyFilters('');
} else {
applyFilters(filterCode || '');
} else if (filterCode !== paged.filterCode) {
updateRoute(paged);
}
}
......@@ -111,6 +112,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
const mapStateToProps = (state, ownProps) => ({
paged: state.subsets.paged || undefined,
filterCode: ownProps.match.params.filterCode,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
......@@ -36,7 +36,7 @@ const routes = [
// },
// },
{
path: '/subsets',
path: '/subsets/:filterCode?',
component: SubsetBrowsePage,
exact: true,
extraProps: {
......@@ -45,7 +45,7 @@ const routes = [
},
},
{
path: '/subsets/:uuid',
path: '/subset/:uuid',
component: SubsetDisplayPage,
exact: true,
extraProps: {
......
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