Commit 452cb413 authored by Matija Obreza's avatar Matija Obreza

Crops with new module code layout

parent 31c92c2f
import Crop from 'model/Crop';
import {CropService} from 'service/CropService';
import {LOAD_CROPS_CACHE_IDLE, RECEIVE_CROPS} from 'constants/crop';
import {LOAD_CROPS_CACHE_IDLE, RECEIVE_CROPS} from 'crop/constants';
import {IReducerAction} from 'model/common.model';
import {log} from 'utilities/debug';
......@@ -10,7 +10,8 @@ const receiveCrops = (crops: Crop[]): IReducerAction => ({
});
export const loadCrops = (forceReload: boolean = false) => (dispatch, getState) => {
const timeSinceLastFetch = getState().crop.lastFetched;
const timeSinceLastFetch = getState().crop.public.lastFetched;
// perform the API call if the data is older than the allowed limit
const isDataStale = Date.now() - timeSinceLastFetch > LOAD_CROPS_CACHE_IDLE;
......
import { combineReducers } from 'redux';
// import admin from './admin';
// import dashboard from './dashboard';
import root from './public';
const rootReducer = combineReducers({
// admin,
// dashboard,
public: root,
});
export default rootReducer;
import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import { RECEIVE_CROPS } from 'constants/crop';
import { RECEIVE_CROPS } from 'crop/constants';
const INITIAL_STATE = {
crops: null,
list: null,
lastFetched: 0,
};
......@@ -13,7 +13,7 @@ export default function crop(state = INITIAL_STATE, action: IReducerAction = {ty
switch (action.type) {
case RECEIVE_CROPS: {
return update(state, {
crops: {$set: action.payload},
list: {$set: action.payload},
lastFetched: {$set: Date.now()},
});
}
......
// Root
import CropBrowsePage from 'crop/ui/BrowsePage';
import CropDisplayPage from 'crop/ui/DisplayPage';
// Admin
// Dashboard
// Root routes
const rootRoutes = [
// Crops
{
path: '/c/',
component: CropBrowsePage,
exact: true,
},
{
path: '/c/:shortName',
component: CropDisplayPage,
exact: true,
},
];
export {rootRoutes as rootCropRoutes};
......@@ -6,7 +6,7 @@ import {bindActionCreators} from 'redux';
import Crop from 'model/Crop';
// UI
import PageLayout from 'ui/layout/PageLayout';
import PageLayout, { PageContents } from 'ui/layout/PageLayout';
import ContentHeader from 'ui/common/heading/ContentHeader';
import CropCard from 'ui/genesys/crop/CropCard';
import GridLayout from 'ui/layout/GridLayout';
......@@ -23,18 +23,18 @@ class BrowsePage extends React.Component<IBrowsePageProps> {
return (
<PageLayout>
<ContentHeader title="Crop list" subTitle="Genesys crops directory"/>
<div style={ {width: '75%', margin: '16px auto' } }>
<PageContents>
<GridLayout>
{ crops && crops.map((crop) => <CropCard key={ crop.id } crop={ crop } compact/>) }
{ crops && crops.map((crop) => <CropCard key={ crop.shortName } crop={ crop } compact/>) }
</GridLayout>
</div>
</PageContents>
</PageLayout>
);
}
}
const mapStateToProps = (state, ownProps) => ({
crops: state.crop.crops || undefined,
crops: state.crop.public.list || undefined,
filterCode: ownProps.match.params.filterCode,
});
......
......@@ -53,7 +53,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
const mapStateToProps = (state, ownProps) => ({
shortName: ownProps.match.params.shortName,
crops: state.crop.crops,
crops: state.crop.public.list,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({}, dispatch);
......
......@@ -12,7 +12,7 @@ import subsets from './subsets';
import accessions from './accessions';
import institutes from './institute';
import applicationConfig from './applicationConfig';
import crop from './crop';
import crop from 'crop/reducers';
import user from 'user/reducers';
import requests from './requests';
......
......@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {updateHistory} from 'actions/history';
import {loadCrops} from 'actions/crop';
import {loadCrops} from 'crop/actions/public';
import {initMyList} from 'user/actions/root';
import { serverInfoRequest } from 'actions/serverInfo';
......@@ -44,7 +44,7 @@ class App extends React.Component<IAppProps, any> {
public componentWillMount() {
const { crops, loadCrops, serverInfo, serverInfoRequest } = this.props;
if (!crops || crops.length === 0) {
if (! crops || crops.length === 0) {
loadCrops();
}
if (! serverInfo || ! serverInfo.revision) {
......@@ -78,7 +78,7 @@ class App extends React.Component<IAppProps, any> {
}
const mapStateToProps = (state) => ({
crops: state.crop.list,
crops: state.crop.public.list || null,
serverInfo: state.serverInfo.data,
// accessToken: state.login.access_token,
});
......
......@@ -29,7 +29,7 @@ const CropCard = ({crop, classes, compact = false, edit = false, ...other}: { cr
const name = window.initialLanguage && crop.i18n && JSON.parse(crop.i18n).name[window.initialLanguage] || crop.name;
return compact ? (
<Grid item sm={ 4 } md={ 3 } lg={ 2 }>
<Grid item xs={ 12 } sm={ 6 } md={ 4 }>
<Card className={ classes.root }>
<CardHeader title={
<Link to={ `/c/${crop.shortName}${edit ? '/edit' : '' }` }>
......
......@@ -6,6 +6,8 @@ import AdminLayout from 'ui/layout/AdminLayout';
// User
import {userAdminRoutes, userRoutes, userDashboardRoutes} from 'user/routes';
// Crops
import {rootCropRoutes} from 'crop/routes';
import DashboardPage from 'ui/pages/dashboard/DashboardPage';
// import AccessionsBrowsePage from 'ui/pages/genesys/BrowsePage';
......@@ -25,9 +27,6 @@ import MapBrowsePage from 'ui/pages/accessions/MapPage';
import AccessionDisplayPage from 'ui/pages/accessions/DisplayPage';
import AccessionOverviewPage from 'ui/pages/accessions/OverviewPage';
// Crops
import CropBrowsePage from 'ui/pages/crops/BrowsePage';
import CropDisplayPage from 'ui/pages/crops/DisplayPage';
// Institute
import InstituteBrowsePage from 'ui/pages/institutes/BrowsePage';
import InstituteDisplayPage from 'ui/pages/institutes/DisplayPage';
......@@ -48,6 +47,7 @@ const routes = [
component: App,
routes: [
...userRoutes,
...rootCropRoutes,
{
path: '/',
exact: true,
......@@ -164,17 +164,6 @@ const routes = [
component: InstituteDisplayPage,
exact: true,
},
// Crops
{
path: '/c/',
component: CropBrowsePage,
exact: true,
},
{
path: '/c/:shortName',
component: CropDisplayPage,
exact: true,
},
// Dashboard
{
path: '/dashboard',
......
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