Commit 7e1aed73 authored by Matija Obreza's avatar Matija Obreza
Browse files

Added "relink accessions" button to crop display page

parent e7853353
......@@ -40,3 +40,10 @@ export const deleteCrop = (crop: Crop) => (dispatch) => {
dispatch(navigateTo('/c'));
});
};
export const relinkAccessions = (shortName: string) => (dispatch) => {
return CropService.relinkAccessions(shortName)
.then(() => {
return true;
});
};
......@@ -42,7 +42,8 @@
"message": "Delete crop '{{cropName, lowercase}}'?",
"description": "Note, deleting any crop causes mayhem."
}
}
},
"link": "Link accessions"
}
},
"common": {
......
......@@ -6,6 +6,7 @@ import withStyles from '@material-ui/core/styles/withStyles';
// Actions
import { loadCropDetails } from 'crop/actions/public';
import { relinkAccessions } from 'crop/actions/admin';
import { applyFilters } from 'accessions/actions/public';
// Models
......@@ -16,13 +17,16 @@ import CropDetails from 'model/genesys/CropDetails';
import PageLayout, {PageContents, PageSection} from 'ui/layout/PageLayout';
import {Properties, PropertiesItem} from 'ui/common/Properties';
import CropCard from 'crop/ui/c/CropCard';
import ContentHeader from 'ui/common/heading/ContentHeader';
import Section from 'ui/common/layout/Section';
import Loading from 'ui/common/Loading';
import PropertiesCard from 'ui/common/PropertiesCard';
import Number from 'ui/common/Number';
import GridContainer from 'ui/layout/GridContainer';
import PieChart from 'ui/common/pie-chart';
import ContentHeaderWithButton from 'ui/common/heading/ContentHeaderWithButton';
import ButtonBar from 'ui/common/buttons/ButtonBar';
import ActionButton from 'ui/common/buttons/ActionButton';
import Authorize from 'ui/common/authorized/Authorize';
/*tslint:disable*/
const styles = (theme) => ({
......@@ -65,6 +69,7 @@ interface IDisplayPageProps extends React.ClassAttributes<any> {
t: any;
classes: any;
applyFilters: any;
relinkAccessions: (shortName: string) => void;
}
class DisplayPage extends React.Component<IDisplayPageProps, any> {
......@@ -88,13 +93,29 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
applyFilters(filter);
}
private relinkAccessions = () => {
const { relinkAccessions, shortName } = this.props;
relinkAccessions(shortName);
}
public render() {
const { cropDetails, shortName, classes, t } = this.props;
const crop = cropDetails;
return (
<PageLayout withFooter>
<ContentHeader title={ t('crop.public.p.display.title') } />
<ContentHeaderWithButton title={ t('crop.public.p.display.title') }
buttons={
<Authorize role="ROLE_ADMINISTRATOR">
<ButtonBar>
<ActionButton
title={ t('crop.admin.p.link') }
action={ this.relinkAccessions }
/>
</ButtonBar>
</Authorize>
}
/>
{ !crop || crop.shortName !== shortName ? (<Loading/>) :
<PageContents className="pt-1rem container-spacing-horizontal pb-1rem">
{ cropDetails.blurb && cropDetails.blurb.body &&
......@@ -211,6 +232,7 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadCropDetails,
applyFilters,
relinkAccessions,
}, dispatch);
......
......@@ -9,6 +9,7 @@ const URL_SAVE_CROP = `/api/v1/crops/save`;
const URL_DELETE_CROP = UrlTemplate.parse(`/api/v1/crops/{shortName}`);
const URL_GET_CROP = UrlTemplate.parse(`/api/v1/crops/{shortName}`);
const URL_GET_CROP_DETAILS = UrlTemplate.parse(`/api/v1/crops/{shortName}/details`);
const URL_RELINK_ACCESSIONS = UrlTemplate.parse(`/api/v1/crops/{shortName}/relink?accessions`);
export class CropService {
......@@ -105,4 +106,22 @@ export class CropService {
}).then(({ data }) => data as CropDetails);
}
/**
* relinkAccessions at /api/v1/crops/{shortName}/relink?accessions
*
* @param shortName shortName
*/
public static relinkAccessions(shortName: string): Promise<boolean> {
const apiUrl = URL_RELINK_ACCESSIONS.expand({shortName});
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
...content,
}).then(({ }) => true);
}
}
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