Commit 4366e195 authored by Matija Obreza's avatar Matija Obreza
Browse files

Cleanup: Using `Page.fromQueryString(qs)` utility method

- Fixed SSR for admin/requests
parent bf01348d
import * as React from 'react';
import {translate} from 'react-i18next';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import { translate } from 'react-i18next';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { parse } from 'query-string';
// Actions
import { applyFilters, loadMoreAccessions, updateRoute } from 'accessions/actions/public';
// Models
import Page from 'model/Page';
import Accession from 'model/accession/Accession';
// UI
......@@ -19,7 +20,7 @@ import PagedLoader from 'ui/common/PagedLoader';
import PrettyFilters from 'ui/common/filter/PrettyFilters';
import PaginationComponent from 'ui/common/pagination';
import AccessionCard from 'accessions/ui/c/AccessionCard';
import Tabs, {Tab} from 'ui/common/Tabs';
import Tabs, { Tab } from 'ui/common/Tabs';
import AccessionFilters from './c/Filters';
// TODO only for demo
import Button from '@material-ui/core/Button';
......@@ -28,11 +29,7 @@ class BrowsePage extends BrowsePageTemplate<Accession> {
protected static needs = [
({ search, params: { filterCode } }) => {
const qs = parse(search || '');
const page = { direction: qs.d, properties: null };
if (qs.s) {
page.properties = [ qs.s ];
}
return applyFilters(filterCode || '', page);
return applyFilters(filterCode || '', Page.fromQueryString(qs));
},
];
......
......@@ -46,11 +46,7 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
protected static needs = [
({ search, params: { filterCode } }) => {
const qs = parse(search || '');
const page = { direction: qs.d, properties: null };
if (qs.s) {
page.properties = [ qs.s ];
}
return applyOverviewFilters(filterCode || '', page);
return applyOverviewFilters(filterCode || '', FilteredPage.fromQueryString(qs));
},
];
......
......@@ -8,6 +8,7 @@ import { translate } from 'react-i18next';
import { applyFilters, loadMoreInstitutes, updateRoute } from 'institutes/actions/public';
// Models
import Page from 'model/Page';
import FaoInstitute from 'model/genesys/FaoInstitute';
// UI
......@@ -26,11 +27,7 @@ class BrowsePage extends BrowsePageTemplate<FaoInstitute> {
protected static needs = [
({ search, params: { filterCode } }) => {
const qs = parse(search || '');
const page = { direction: qs.d, properties: null };
if (qs.s) {
page.properties = [ qs.s ];
}
return applyFilters(filterCode || '', page);
return applyFilters(filterCode || '', Page.fromQueryString(qs));
},
];
......
......@@ -20,6 +20,10 @@ import ContentHeaderWithButton from 'ui/common/heading/ContentHeaderWithButton';
class BrowsePage extends BrowsePageTemplate<any> {
protected static needs = [
({ }) => loadMoreRequests(),
];
public componentWillMount() {
const { paged, loadMoreData } = this.props;
if (!paged) {
......
......@@ -8,6 +8,7 @@ import { parse } from 'query-string';
import { applyFilters, loadSubsetsPage, updateRoute } from 'subsets/actions/public';
// Models
import Page from 'model/Page';
import Subset from 'model/subset/Subset';
// UI
......@@ -27,11 +28,7 @@ class BrowsePage extends BrowsePageTemplate<Subset> {
protected static needs = [
({ search, params: { filterCode } }) => {
const qs = parse(search || '');
const page = { direction: qs.d, properties: null };
if (qs.s) {
page.properties = [ qs.s ];
}
return applyFilters(filterCode || '', page);
return applyFilters(filterCode || '', Page.fromQueryString(qs));
},
];
......
......@@ -2,21 +2,23 @@ import * as React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { parse } from 'query-string';
// Actions
import { loadMoreSubsets } from 'subsets/actions/dashboard';
import { applyFilters } from 'subsets/actions/public';
// Models
import Subset from 'model/subset/Subset';
import FilteredPage from 'model/FilteredPage';
import Subset from 'model/subset/Subset';
// UI
import SubsetDashboardCard from './c/SubsetDashboardRow';
import MyDataTable from 'ui/common/tables/MyDataTable';
import Page from 'model/Page';
interface IDashboardPageProps extends React.ClassAttributes<any> {
paged: FilteredPage<Subset>;
loadMoreSubsets: (page?: Page<Subset>) => void;
loadMoreSubsets: (page?: FilteredPage<Subset>) => void;
history: any;
location: any;
login: any;
......@@ -42,7 +44,7 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
protected static needs = [
({ search, params: { filterCode } }) => {
const qs = parse(search || '');
return applyFilters(filterCode || '', Page.fromQueryString(qs));
return applyFilters(filterCode || '', FilteredPage.fromQueryString(qs));
},
];
......
......@@ -8,6 +8,7 @@ import { parse } from 'query-string';
import { applyFilters, updateRoute, loadMoreUsers } from 'user/actions/admin';
// Models
import FilteredPage from 'model/FilteredPage';
import { User } from 'model/user/User';
// UI
......@@ -26,11 +27,7 @@ class BrowsePage extends BrowsePageTemplate<User> {
protected static needs = [
({ search, params: { filterCode } }) => {
const qs = parse(search || '');
const page = { direction: qs.d, properties: null };
if (qs.s) {
page.properties = [qs.s];
}
return applyFilters(filterCode || '', page);
return applyFilters(filterCode || '', FilteredPage.fromQueryString(qs));
},
];
......
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