Commit 7c1f424f authored by Matija Obreza's avatar Matija Obreza

Merge branch '288-bug-filtering-subsets-in-the-dashboard'

* 288-bug-filtering-subsets-in-the-dashboard:
  Fix "Bug: Filtering Subsets in the Dashboard"
parents 639d2e45 2e74ba79
......@@ -48,8 +48,8 @@ export const loadSubset = (uuid: string) => (dispatch) => {
return dispatch(apiLoadSubset(uuid));
};
export const loadMoreSubsets = (paged?: Page<Subset>) => (dispatch) => {
return dispatch(apiListSubsets('', Page.nextPage(paged)));
export const loadMoreSubsets = (paged: FilteredPage<Subset>) => (dispatch) => {
return dispatch(apiListSubsets(paged ? paged.filterCode : '', Page.nextPage(paged)));
};
export const loadMoreAccessions = (uuid: string, paged?: Page<AccessionRef>) => (dispatch, getState) => {
......
......@@ -12,6 +12,7 @@ import FilteredPage from 'model/FilteredPage';
import Subset from 'model/subset/Subset';
import SubsetFilter from 'model/subset/SubsetFilter';
import {SortDirection, IPageRequest} from 'model/Page';
import ApiCall from 'model/ApiCall';
// UI
import SubsetFilters from './c/SubsetFilters';
......@@ -26,7 +27,7 @@ import PaginationComponent from 'ui/common/pagination';
import PrettyFilters from 'ui/common/filter/PrettyFilters';
interface IDashboardPageProps extends React.ClassAttributes<any> {
paged: FilteredPage<Subset>;
apiCall: ApiCall<FilteredPage<Subset>>;
loadMoreSubsets: (page?: FilteredPage<Subset>) => void;
createNewVersion: (uuid: string) => void;
login: any;
......@@ -56,7 +57,8 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
}
public componentWillMount() {
const {paged, applyFilters, filterCode} = this.props;
const {apiCall, applyFilters, filterCode} = this.props;
const {data: paged} = apiCall || {data: undefined};
if (filterCode) {
if (!paged || paged.filterCode !== filterCode) {
applyFilters(filterCode);
......@@ -67,18 +69,19 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
}
public componentWillReceiveProps(nextProps) {
const { filterCode: prevCode, paged: prevPaged } = this.props;
const { filterCode, applyFilters, paged } = nextProps;
const { filterCode: prevFilterCode } = this.props;
const { filterCode, applyFilters, apiCall } = nextProps;
if (prevPaged && paged && _.isEqual(paged.filter, prevPaged.filter)) {
if (prevCode !== filterCode) {
if (filterCode !== prevFilterCode) {
if (apiCall && apiCall.data && !apiCall.loading && apiCall.data.filterCode !== filterCode) {
applyFilters(filterCode || '');
}
}
}
protected myApplyFilters = (filters: SubsetFilter) => {
const { paged, applyFilters } = this.props;
const { apiCall, applyFilters } = this.props;
const {data: paged} = apiCall || {data: undefined};
if (paged) {
applyFilters(filters, { page: 0, direction: paged.sort[0].direction, properties: [ paged.sort[0].property ] });
} else {
......@@ -87,7 +90,8 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
}
protected onSortChange = (sortBy: string, dir: SortDirection) => {
const { paged, applyFilters, filterCode } = this.props;
const { apiCall, applyFilters, filterCode } = this.props;
const {data: paged} = apiCall || {data: undefined};
applyFilters(filterCode || paged.filterCode || '', FilteredPage.reSort(paged, sortBy, dir));
}
......@@ -97,7 +101,8 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
}
public render() {
const {paged, login: { authorities: userRoles }, loadMoreSubsets, t} = this.props;
const {apiCall, login: { authorities: userRoles }, loadMoreSubsets, t} = this.props;
const {data: paged} = apiCall || {data: undefined};
const renderSubset = (s: Subset, index: number) => {
return (
<SubsetCard
......@@ -148,7 +153,7 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
}
const mapStateToProps = (state, ownProps) => ({
paged: state.subsets.dashboard.paged ? state.subsets.dashboard.paged.data : undefined,
apiCall: state.subsets.dashboard.paged,
login: state.login,
filterCode: ownProps.match.params.filterCode,
dataClassName: Subset.clazz,
......
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