Commit 69c23a12 authored by Matija Obreza's avatar Matija Obreza
Browse files

Admin Requests: Updated default sort and fixed admin request actions (on fail)

parent 367e918a
......@@ -64,7 +64,7 @@
"fromIncluding": "At least (min)",
"toIncluding": "At most (max)",
"createdDate": "Created on",
"lastModifiedDate": "Last modified date",
"lastModifiedDate": "Last modified",
"textSearch": "Text search",
"keyword": "Keyword search"
},
......
......@@ -20,8 +20,8 @@ class MaterialRequest {
public version: number;
public static DEFAULT_SORT = {
property: 'id',
direction: 'ASC',
property: 'lastModifiedDate',
direction: 'DESC',
};
public static STATE: { [key: number]: string; } = {
......
......@@ -22,9 +22,6 @@ import MaterialRequestFilter from 'model/request/MaterialRequestFilter';
// Wrapped API Calls
const apiListRequests = createApiCaller(RequestService.list, ADMIN_APPEND_MATERIAL_REQUESTS);
const apiLoadRequest = createApiCaller(RequestService.getRequest, ADMIN_RECEIVE_MATERIAL_REQUEST);
const apiRecheckPid = createApiCaller(RequestService.recheckPid, ADMIN_RECEIVE_MATERIAL_REQUEST);
const apiValidateRequest = createApiCaller(RequestService.validateRequest, ADMIN_RECEIVE_MATERIAL_REQUEST);
const apiSendValidationEmail = createApiCaller(RequestService.sendValidationEmail, ADMIN_RECEIVE_MATERIAL_REQUEST);
const apiAccessionIdToUUID = createPureApiCaller(AccessionService.uuidFromIds);
const apiListAccessionsByUUID = createApiCaller(AccessionService.listAllByUuid, ADMIN_RECEIVE_MATERIAL_REQUEST_ACCESSIONS);
......@@ -41,19 +38,19 @@ export const loadMaterialRequest = (uuid: string) => (dispatch) => {
};
export const recheckPidAction = (uuid: string) => (dispatch) => {
return dispatch(apiRecheckPid(uuid))
.then((request) => dispatch(loadRequestAccessions(request)));
return RequestService.recheckPid(uuid)
.then((request) => dispatch(loadMaterialRequest(request.uuid)));
};
export const validateRequestAction = (uuid: string) => (dispatch) => {
return dispatch(apiValidateRequest(uuid))
.then((request) => dispatch(loadRequestAccessions(request)));
return RequestService.validateRequest(uuid)
.then((request) => dispatch(loadMaterialRequest(request.uuid)));
};
export const sendValidationEmailAction = (uuid: string) => (dispatch) => {
return dispatch(apiSendValidationEmail(uuid))
.then((request) => dispatch(loadRequestAccessions(request)));
return RequestService.sendValidationEmail(uuid)
.then((request) => dispatch(loadMaterialRequest(request.uuid)));
};
const loadRequestAccessions = (request: MaterialRequest) => (dispatch) => {
......
......@@ -22,6 +22,7 @@ import Markdown from 'ui/common/markdown';
import PageTitle from 'ui/common/PageTitle';
import AccessionCard from 'accessions/ui/c/AccessionCard';
import ApiCall from 'model/ApiCall';
import confirm from 'utilities/confirmAlert';
interface IDisplayPageProps extends React.ClassAttributes<any> {
t: any;
......@@ -56,6 +57,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
const { requestCall, sendValidationEmail } = this.props;
sendValidationEmail(requestCall.data.uuid).catch((error) => {
console.log(`Error sending validation email`, error);
confirm(`Error sending validation email`, { confirmOnly: true, description: JSON.stringify(error.response.data) });
});
}
......@@ -63,13 +65,14 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
const { requestCall, validateRequest } = this.props;
validateRequest(requestCall.data.uuid).catch((error) => {
console.log(`Error validating request`, error);
confirm(`Error validating request`, { confirmOnly: true, description: JSON.stringify(error.response.data) });
});
}
private recheckPid = () => {
const { requestCall, recheckPid } = this.props;
recheckPid(requestCall.data.uuid).catch((error) => {
console.log(`Error checking for PID`, error);
confirm(`Error checking for PID`, { confirmOnly: true, description: JSON.stringify(error.response.data) });
});
}
......@@ -90,9 +93,9 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
title={ t('requests.admin.p.display.title', {email: request.email}) }
buttons={
<div>
<ActionButton title={ t('requests.admin.p.display.sendValidationEmail') } action={ this.sendValidationEmail }/>
<ActionButton title={ t('requests.admin.p.display.validateRequest') } action={ this.validateRequest }/>
<ActionButton title={ t('requests.admin.p.display.recheckPID') } action={ this.recheckPid }/>
{ request.state === 0 && <ActionButton title={ t('requests.admin.p.display.sendValidationEmail') } action={ this.sendValidationEmail }/> }
{ request.body && ! request.body.pid && <ActionButton title={ t('requests.admin.p.display.recheckPID') } action={ this.recheckPid }/> }
{ request.state !== 2 && <ActionButton title={ t('requests.admin.p.display.validateRequest') } action={ this.validateRequest }/> }
<BackButton defaultTarget="/admin/requests"/>
</div>
}
......@@ -155,14 +158,14 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
</PageSection>
}
{ requestAccessionsCall && requestAccessionsCall.data && requestAccessionsCall.data.length > 0 &&
<div>
<h3 style={ { marginTop: '1em' } }>{ t('requests.admin.p.display.requestedAccessions') }</h3>
<div className="container-spacing-horizontal mb-15">
{ requestAccessionsCall.data.map((accession, index) => <AccessionCard key={ accession.uuid } index={ index } accession={ accession } />) }
</div>
<div>
<h3 style={ { marginTop: '1em' } }>{ t('requests.admin.p.display.requestedAccessions') }</h3>
<div className="container-spacing-horizontal mb-15">
{ requestAccessionsCall && requestAccessionsCall.loading && <Loading /> }
{ requestAccessionsCall && ! requestAccessionsCall.loading && requestAccessionsCall.data && requestAccessionsCall.data.length
&& requestAccessionsCall.data.map((accession, index) => <AccessionCard key={ accession.uuid } index={ index } accession={ accession } />) }
</div>
}
</div>
</PageContents>
}
</div>
......
......@@ -32,7 +32,9 @@ const RequestCard = ({request, classes, index, t, ...other}: { request: Material
</RequestLink>
</b>
<b></b>
<PrettyDate value={ request.createdDate }/>
{ t('common:f.lastModifiedDate') } <PrettyDate value={ request.lastModifiedDate }/>
<b></b>
{ t('common:f.createdDate') } <PrettyDate value={ request.createdDate }/>
</div>
<div>
{ request.state !== undefined &&
......
......@@ -163,8 +163,8 @@ class RequestService {
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
d: page.direction ? page.direction : MaterialRequest.DEFAULT_SORT.direction,
s: page.properties || MaterialRequest.DEFAULT_SORT.property,
}, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
......
......@@ -9,10 +9,11 @@ import DialogTitle from '@material-ui/core/DialogTitle';
interface IConfirmProps extends React.ClassAttributes<any> {
message: string;
description: string;
message?: string;
description?: string;
confirmLabel?: string;
abortLabel?: string;
confirmOnly?: boolean;
}
function PromiseWrapper() {
......@@ -41,7 +42,7 @@ class Confirm extends React.Component<IConfirmProps, any> {
}
public render() {
const {message, description, confirmLabel = 'OK', abortLabel = 'Cancel'} = this.props;
const {message, description, confirmLabel = 'OK', abortLabel = 'Cancel', confirmOnly = false} = this.props;
return (
<Dialog
......@@ -51,16 +52,20 @@ class Confirm extends React.Component<IConfirmProps, any> {
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">{ message }</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{ description }
</DialogContentText>
</DialogContent>
{ description && (
<DialogContent>
<DialogContentText id="alert-dialog-description">
{ description }
</DialogContentText>
</DialogContent>
) }
<DialogActions>
<Button onClick={ this.reject } autoFocus>
{ abortLabel }
</Button>
<Button onClick={ this.resolve } color="primary">
{ ! confirmOnly && (
<Button onClick={ this.reject } autoFocus>
{ abortLabel }
</Button>
) }
<Button onClick={ this.resolve } color="primary" autoFocus={ confirmOnly }>
{ confirmLabel }
</Button>
</DialogActions>
......@@ -70,7 +75,7 @@ class Confirm extends React.Component<IConfirmProps, any> {
}
export default (message, options = {}) => {
export default (message: any, options: IConfirmProps = {}) => {
const props: any = {message, ...options};
const wrapper = document.body.appendChild(document.createElement('div'));
......
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