Commit d6d5ee14 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'crop-relink-accessions' into 'master'

Added "relink accessions" button to crop display page

See merge request genesys-pgr/genesys-ui!177
parents e7853353 7e1aed73
...@@ -40,3 +40,10 @@ export const deleteCrop = (crop: Crop) => (dispatch) => { ...@@ -40,3 +40,10 @@ export const deleteCrop = (crop: Crop) => (dispatch) => {
dispatch(navigateTo('/c')); dispatch(navigateTo('/c'));
}); });
}; };
export const relinkAccessions = (shortName: string) => (dispatch) => {
return CropService.relinkAccessions(shortName)
.then(() => {
return true;
});
};
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
"message": "Delete crop '{{cropName, lowercase}}'?", "message": "Delete crop '{{cropName, lowercase}}'?",
"description": "Note, deleting any crop causes mayhem." "description": "Note, deleting any crop causes mayhem."
} }
} },
"link": "Link accessions"
} }
}, },
"common": { "common": {
......
...@@ -6,6 +6,7 @@ import withStyles from '@material-ui/core/styles/withStyles'; ...@@ -6,6 +6,7 @@ import withStyles from '@material-ui/core/styles/withStyles';
// Actions // Actions
import { loadCropDetails } from 'crop/actions/public'; import { loadCropDetails } from 'crop/actions/public';
import { relinkAccessions } from 'crop/actions/admin';
import { applyFilters } from 'accessions/actions/public'; import { applyFilters } from 'accessions/actions/public';
// Models // Models
...@@ -16,13 +17,16 @@ import CropDetails from 'model/genesys/CropDetails'; ...@@ -16,13 +17,16 @@ import CropDetails from 'model/genesys/CropDetails';
import PageLayout, {PageContents, PageSection} from 'ui/layout/PageLayout'; import PageLayout, {PageContents, PageSection} from 'ui/layout/PageLayout';
import {Properties, PropertiesItem} from 'ui/common/Properties'; import {Properties, PropertiesItem} from 'ui/common/Properties';
import CropCard from 'crop/ui/c/CropCard'; import CropCard from 'crop/ui/c/CropCard';
import ContentHeader from 'ui/common/heading/ContentHeader';
import Section from 'ui/common/layout/Section'; import Section from 'ui/common/layout/Section';
import Loading from 'ui/common/Loading'; import Loading from 'ui/common/Loading';
import PropertiesCard from 'ui/common/PropertiesCard'; import PropertiesCard from 'ui/common/PropertiesCard';
import Number from 'ui/common/Number'; import Number from 'ui/common/Number';
import GridContainer from 'ui/layout/GridContainer'; import GridContainer from 'ui/layout/GridContainer';
import PieChart from 'ui/common/pie-chart'; 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*/ /*tslint:disable*/
const styles = (theme) => ({ const styles = (theme) => ({
...@@ -65,6 +69,7 @@ interface IDisplayPageProps extends React.ClassAttributes<any> { ...@@ -65,6 +69,7 @@ interface IDisplayPageProps extends React.ClassAttributes<any> {
t: any; t: any;
classes: any; classes: any;
applyFilters: any; applyFilters: any;
relinkAccessions: (shortName: string) => void;
} }
class DisplayPage extends React.Component<IDisplayPageProps, any> { class DisplayPage extends React.Component<IDisplayPageProps, any> {
...@@ -88,13 +93,29 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> { ...@@ -88,13 +93,29 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
applyFilters(filter); applyFilters(filter);
} }
private relinkAccessions = () => {
const { relinkAccessions, shortName } = this.props;
relinkAccessions(shortName);
}
public render() { public render() {
const { cropDetails, shortName, classes, t } = this.props; const { cropDetails, shortName, classes, t } = this.props;
const crop = cropDetails; const crop = cropDetails;
return ( return (
<PageLayout withFooter> <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/>) : { !crop || crop.shortName !== shortName ? (<Loading/>) :
<PageContents className="pt-1rem container-spacing-horizontal pb-1rem"> <PageContents className="pt-1rem container-spacing-horizontal pb-1rem">
{ cropDetails.blurb && cropDetails.blurb.body && { cropDetails.blurb && cropDetails.blurb.body &&
...@@ -211,6 +232,7 @@ const mapStateToProps = (state, ownProps) => ({ ...@@ -211,6 +232,7 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({ const mapDispatchToProps = (dispatch) => bindActionCreators({
loadCropDetails, loadCropDetails,
applyFilters, applyFilters,
relinkAccessions,
}, dispatch); }, dispatch);
......
...@@ -9,6 +9,7 @@ const URL_SAVE_CROP = `/api/v1/crops/save`; ...@@ -9,6 +9,7 @@ const URL_SAVE_CROP = `/api/v1/crops/save`;
const URL_DELETE_CROP = UrlTemplate.parse(`/api/v1/crops/{shortName}`); const URL_DELETE_CROP = UrlTemplate.parse(`/api/v1/crops/{shortName}`);
const URL_GET_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_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 { export class CropService {
...@@ -105,4 +106,22 @@ export class CropService { ...@@ -105,4 +106,22 @@ export class CropService {
}).then(({ data }) => data as CropDetails); }).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