Commit 2e74ba79 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Fix "Bug: Filtering Subsets in the Dashboard"

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