Commit 37e575a1 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Unnecessary API calls

parent 855e8f64
......@@ -205,7 +205,7 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
const mapStateToProps = (state, ownProps) => ({
paged: state.accessions.public.paged || undefined,
overview: state.accessions.public.overview,
filterCode: ownProps.match.params.filterCode,
filterCode: ownProps.match.params.filterCode || '',
currentTab: ownProps.match.params.tab || 'overview', // current tab, or ownProps.location.pathname
});
......
import Crop from 'model/genesys/Crop';
import {IReducerAction} from 'model/common.model';
import {ADMIN_RECEIVE_CROP} from 'crop/constants';
import {ADMIN_RECEIVE_CROP, UPDATE_CROPS_LIST} from 'crop/constants';
import {CropService} from 'service/CropService';
import navigateTo from 'actions/navigation';
import {loadCrops} from './public';
const receiveCrop = (cropDetails: Crop): IReducerAction => ({
type: ADMIN_RECEIVE_CROP, payload: cropDetails,
});
const updateCropList = (cropDetails: Crop): IReducerAction => ({
type: UPDATE_CROPS_LIST, payload: cropDetails,
});
export const loadCrop = (shortName: string) => (dispatch) => {
CropService.getCrop(shortName)
.then((details) => dispatch(receiveCrop(details)));
return CropService.getCrop(shortName)
.then((details) => {
dispatch(receiveCrop(details));
});
};
export const saveCrop = (crop: Crop) => (dispatch) => {
return CropService.saveCrop(crop)
.then((crop) => dispatch(receiveCrop(crop)));
.then((crop) => {
dispatch(receiveCrop(crop));
dispatch(updateCropList(crop));
});
};
export const createCrop = () => (dispatch) => {
......
......@@ -5,7 +5,6 @@ import {IReducerAction} from 'model/common.model';
import {log} from 'utilities/debug';
import CropDetails from 'model/genesys/CropDetails';
const receiveCrops = (crops: Crop[]): IReducerAction => ({
type: RECEIVE_CROPS, payload: crops,
});
......@@ -14,7 +13,7 @@ const receiveCropDetails = (cropDetails: CropDetails): IReducerAction => ({
});
export const loadCropDetails = (shortName: string) => (dispatch) => {
CropService.getCropDetails(shortName)
return CropService.getCropDetails(shortName)
.then((details) => dispatch(receiveCropDetails(details)));
};
......
......@@ -7,6 +7,7 @@ export const RECEIVE_CROPS = 'App/Crop/RECEIVE_CROPS';
export const RECEIVE_CROP_DETAILS = 'App/Crop/RECEIVE_CROP_DETAILS';
export const ADMIN_RECEIVE_CROP = 'App/Crop/Admin/RECEIVE_CROP';
export const UPDATE_CROPS_LIST = 'App/Crop/Admin/UPDATE_CROPS_LIST';
export const CROP_FORM = 'Form/CROP';
// 300000 ms = 5 min
......
import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import {RECEIVE_CROP_DETAILS, RECEIVE_CROPS, ADMIN_RECEIVE_CROP} from 'crop/constants';
const INITIAL_STATE = {
import {RECEIVE_CROP_DETAILS, RECEIVE_CROPS, UPDATE_CROPS_LIST} from 'crop/constants';
import Crop from 'model/genesys/Crop';
const INITIAL_STATE: {
list: Crop[],
lastFetched: number,
details: Crop,
} = {
list: null,
lastFetched: 0,
details: null,
......@@ -18,7 +23,7 @@ export default function crop(state = INITIAL_STATE, action: IReducerAction = {ty
lastFetched: {$set: Date.now()},
});
}
case ADMIN_RECEIVE_CROP: {
case UPDATE_CROPS_LIST: {
const updateIndex = state.list && action.payload ? state.list.findIndex((crop) => crop.shortName === action.payload.shortName) : -1;
return updateIndex === -1 ?
......
......@@ -74,8 +74,8 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
];
public componentWillMount() {
const { loadCropDetails, shortName } = this.props;
if (shortName) {
const { loadCropDetails, shortName, cropDetails } = this.props;
if (shortName && (! cropDetails || shortName !== cropDetails.shortName)) {
loadCropDetails(shortName);
}
}
......
......@@ -32,6 +32,7 @@ class CropEditPage extends React.Component<ICropEditPageProps, any> {
protected static needs = [
({params: {shortName}}) => loadCrop(shortName),
];
private onSave = (updatedCrop: Crop) => {
const {saveCrop, navigateTo} = this.props;
saveCrop(updatedCrop)
......@@ -52,7 +53,7 @@ class CropEditPage extends React.Component<ICropEditPageProps, any> {
});
}
public componentDidMount() {
public componentWillMount() {
const {crop, loadCrop, shortName} = this.props;
if (shortName && (!crop || crop.shortName !== shortName)) {
......
......@@ -42,8 +42,8 @@ class CountryDisplayPage extends React.Component<ICountryDisplayPageProps> {
}
public componentWillMount() {
const { loadCountryDetails, isoCode } = this.props;
if (isoCode) {
const { loadCountryDetails, isoCode, details } = this.props;
if (isoCode && (! details || isoCode !== details.code3)) {
loadCountryDetails(isoCode);
}
}
......
......@@ -44,8 +44,8 @@ class RegionDisplayPage extends React.Component<IRegionDisplayPageProps> {
}
public componentWillMount() {
const { loadRegionDetails, isoCode} = this.props;
if (isoCode) {
const { loadRegionDetails, isoCode, details } = this.props;
if (isoCode && (! details || isoCode !== details.isoCode)) {
loadRegionDetails(isoCode);
}
}
......
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 FilteredPage from 'model/FilteredPage';
......@@ -42,10 +40,7 @@ const tableHeaderProps = [
class DashboardPage extends React.Component<IDashboardPageProps> {
protected static needs = [
({ search, params: { filterCode } }) => {
const qs = parse(search || '');
return applyFilters(filterCode || '', FilteredPage.fromQueryString(qs));
},
() => loadMoreSubsets(),
];
constructor(props: IDashboardPageProps, context: any) {
......@@ -85,7 +80,6 @@ const mapStateToProps = (state, ownProps) => ({
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
applyFilters,
loadMoreSubsets,
}, dispatch);
......
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