Commit 9793cde1 authored by Maxym Borodenko's avatar Maxym Borodenko

Updated reducers

parent 84e485e2
Pipeline #7738 passed with stages
in 4 minutes
......@@ -12,13 +12,11 @@ import AccessionRef from 'model/accession/AccessionRef';
import { Page } from 'model/common.model';
const INITIAL_STATE: {
currentUuid: string,
dataset: Dataset,
accessionRefs: Page<AccessionRef>
paged: Page<Dataset>,
pagedQuery: any,
} = {
currentUuid: null,
dataset: null,
accessionRefs: null,
paged: null,
......@@ -37,11 +35,12 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
}
case RECEIVE_DATASET: {
const receivedIndex = state.paged ? _.findIndex(state.paged.content, (item) => item.uuid === action.payload.uuid) : -1;
const mustRemoveAccessions = state.dataset && (action.payload.uuid !== state.dataset.uuid);
if (receivedIndex !== -1) {
return update(state, {
dataset: { $set: action.payload },
accessionRefs: { $set: action.payload.uuid === state.currentUuid ? state.accessionRefs : null },
accessionRefs: { $set: mustRemoveAccessions ? null : state.accessionRefs },
paged: {
content: {
[receivedIndex]: { $set: action.payload },
......@@ -59,7 +58,6 @@ function datasetsDashboard(state = INITIAL_STATE, action: { type?: string, paylo
case DASHBOARD_RECEIVE_ACCESSIONS_PAGE: {
return update(state, {
accessionRefs: { $set: action.payload.accessionRefs },
currentUuid: { $set: action.payload.currentUuid },
});
}
......
......@@ -9,13 +9,11 @@ import AccessionRef from 'model/accession/AccessionRef';
import {Page} from 'model/common.model';
const INITIAL_STATE: {
currentUuid: string,
dataset: Dataset,
accessionRefs: Page<AccessionRef>
paged: Page<Dataset>,
pagedQuery: any,
} = {
currentUuid: null,
dataset: null,
accessionRefs: null,
paged: null,
......@@ -34,11 +32,12 @@ function datasetsPublic(state = INITIAL_STATE, action: { type?: string, payload?
case RECEIVE_DATASET: {
const receivedIndex = state.paged ? _.findIndex(state.paged.content, (item) => item.uuid === action.payload.uuid) : -1;
const mustRemoveAccessions = state.dataset && (action.payload.uuid !== state.dataset.uuid);
if (receivedIndex !== -1) {
return update(state, {
dataset: { $set: action.payload },
accessionRefs: { $set: action.payload.uuid === state.currentUuid ? state.accessionRefs : null },
accessionRefs: { $set: mustRemoveAccessions ? null : state.accessionRefs },
paged: {
content: {
[receivedIndex]: {$set: action.payload},
......@@ -63,7 +62,6 @@ function datasetsPublic(state = INITIAL_STATE, action: { type?: string, payload?
case RECEIVE_ACCESSIONS_PAGE: {
return update(state, {
accessionRefs: { $set: action.payload.accessionRefs },
currentUuid: { $set: action.payload.currentUuid },
});
}
......
......@@ -143,8 +143,7 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
{ uploading && <Loading message={ uploadText } /> }
<h3>{ t('datasets.dashboard.p.stepper.listOfAccessions.rowCount',
{ count: accessionRefs && accessionRefs.content ? accessionRefs.content.length : 0 }) }</h3>
<h3>{ t('datasets.dashboard.p.stepper.listOfAccessions.rowCount', { count: accessionRefs ? accessionRefs.totalElements : 0 }) }</h3>
<AccessionRefsTable
loadNextPage={ loadAccessions }
paged={ accessionRefs }
......
......@@ -21,7 +21,6 @@ interface IAccessionsListStep extends React.ClassAttributes<any> {
onPublish: () => void;
onGotoStep: (id: number) => () => void;
location: any;
currentUuid: string;
uuid: string;
}
......@@ -36,8 +35,8 @@ class AccessionsListStep extends React.Component<IAccessionsListStep, any> {
}
public componentWillMount() {
const { currentUuid, uuid, loadAccessions } = this.props;
if (! currentUuid || (currentUuid !== uuid)) {
const { dataset, uuid, loadAccessions, accessionRefs } = this.props;
if (! accessionRefs || (dataset && dataset.uuid !== uuid)) {
loadAccessions(uuid);
}
}
......@@ -75,7 +74,6 @@ class AccessionsListStep extends React.Component<IAccessionsListStep, any> {
const mapStateToProps = (state, ownProps) => ({
uuid: ownProps.match.params.uuid,
currentUuid: state.datasets.dashboard.currentUuid,
dataset: state.datasets.dashboard.dataset,
accessionRefs: state.datasets.dashboard.accessionRefs,
stillLoading: ownProps.stillLoading,
......
......@@ -20,7 +20,6 @@ interface IReviewAndPublishStep extends React.ClassAttributes<any> {
onPublish: () => void;
onGotoStep: (id: number) => () => void;
location: any;
currentUuid: string;
uuid: string;
}
......@@ -31,8 +30,8 @@ class ReviewAndPublishStep extends React.Component<IReviewAndPublishStep, any> {
];
public componentWillMount() {
const { currentUuid, uuid, loadAccessions } = this.props;
if (! currentUuid || (currentUuid !== uuid)) {
const { accessionRefs, uuid, loadAccessions, dataset } = this.props;
if (! accessionRefs || (dataset && dataset.uuid !== uuid)) {
loadAccessions(uuid);
}
}
......@@ -67,7 +66,6 @@ class ReviewAndPublishStep extends React.Component<IReviewAndPublishStep, any> {
const mapStateToProps = (state, ownProps) => ({
dataset: state.datasets.dashboard.dataset,
uuid: ownProps.match.params.uuid,
currentUuid: state.datasets.dashboard.currentUuid,
accessionRefs: state.datasets.dashboard.accessionRefs,
stillLoading: ownProps.stillLoading,
location: ownProps.location,
......
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