Commit 33e2d49c authored by Matija Obreza's avatar Matija Obreza

Updates for new backend API for AccessionRefs

- Using add-accessions, set-accessions
- Rematch accessions happens out-of-band
- Axios timeouts set to 0 for add-accessions
- Don't sort AccessionRefs in AccessionRefsTable (causes bugs)
parent a00a3920
......@@ -105,7 +105,7 @@ export { rejectDataset, approveDataset, publishDataset, deleteDataset };
// Accession identifiers step
function clearAccessionRefList(dataset: Dataset) {
return (dispatch, getState) => {
return DatasetService.upsertAccessions(dataset.uuid, dataset.version, [])
return DatasetService.setAccessions(dataset.uuid, dataset.version, [])
.then((saved) => {
dispatch(receiveDataset(saved));
dispatch(loadMoreAccessions(saved.uuid));
......@@ -115,10 +115,10 @@ function clearAccessionRefList(dataset: Dataset) {
};
}
function updateDatasetAccessionRefs(dataset: Dataset, accessionRefs: AccessionRef[]) {
function addDatasetAccessionRefs(dataset: Dataset, accessionRefs: AccessionRef[]) {
return (dispatch, getState) => {
return DatasetService.upsertAccessions(dataset.uuid, dataset.version, accessionRefs)
return DatasetService.addAccessions(dataset.uuid, dataset.version, accessionRefs)
.then((saved) => {
dispatch(receiveDataset(saved));
dispatch(loadMoreAccessions(saved.uuid));
......@@ -143,7 +143,7 @@ function rematchDatasetAccessions(dataset: Dataset) {
}
// Accession identifiers step exports
export { updateDatasetAccessionRefs, rematchDatasetAccessions, clearAccessionRefList };
export { addDatasetAccessionRefs as addDatasetAccessionRefs, rematchDatasetAccessions, clearAccessionRefList };
// Descriptors step
......
......@@ -2,7 +2,7 @@ import * as React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
// actions
import { rematchDatasetAccessions, updateDatasetAccessionRefs, clearAccessionRefList } from 'datasets/actions/editor';
import { rematchDatasetAccessions, addDatasetAccessionRefs, clearAccessionRefList } from 'datasets/actions/editor';
import {loadMoreAccessions} from 'datasets/actions/dashboard';
// models
......@@ -19,7 +19,7 @@ import Loading from 'ui/common/Loading';
interface IAccessionsListStep extends React.ClassAttributes<any> {
item: Dataset;
accessionRefs: Page<AccessionRef>;
updateDatasetAccessionRefs: (dataset: Dataset, accessionRefs: AccessionRef[]) => Promise<Dataset>;
addDatasetAccessionRefs: (dataset: Dataset, accessionRefs: AccessionRef[]) => Promise<Dataset>;
loadMore: (uuid: string, page?: Page<AccessionRef>) => any;
stillLoading: boolean;
onDelete: () => void;
......@@ -58,8 +58,8 @@ class AccessionsListStep extends StepperTemplate<IAccessionsListStep> {
}
protected updateAccessionsRefs = (AccessionRefs: AccessionRef[]) => {
const { item: dataset, updateDatasetAccessionRefs } = this.props;
return updateDatasetAccessionRefs(dataset, AccessionRefs);
const { item: dataset, addDatasetAccessionRefs } = this.props;
return addDatasetAccessionRefs(dataset, AccessionRefs);
}
public componentWillMount() {
......@@ -82,7 +82,7 @@ const mapStateToProps = (state, ownProps) => ({
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
updateDatasetAccessionRefs,
addDatasetAccessionRefs,
clearAccessionRefList,
rematchDatasetAccessions,
loadMore: loadMoreAccessions,
......
......@@ -23,7 +23,8 @@ const URL_REJECT_DATASET = `/api/v1/dataset/reject`;
const URL_REMOVE_DESCRIPTORS = UrlTemplate.parse(`/api/v1/dataset/remove-descriptors/{uuid},{version}`);
const URL_UPDATE_DESCRIPTORS = UrlTemplate.parse(`/api/v1/dataset/set-descriptors/{uuid},{version}`);
const URL_UPDATE_DATASET = `/api/v1/dataset/update`;
const URL_UPSERT_ACCESSIONS = UrlTemplate.parse(`/api/v1/dataset/upsertaccessions/{uuid},{version}`);
const URL_ADD_ACCESSIONS = UrlTemplate.parse(`/api/v1/dataset/add-accessions/{uuid},{version}`);
const URL_SET_ACCESSIONS = UrlTemplate.parse(`/api/v1/dataset/set-accessions/{uuid},{version}`);
const URL_GET_DATASET = UrlTemplate.parse(`/api/v1/dataset/{uuid}`);
const URL_DELETE_DATASET = UrlTemplate.parse(`/api/v1/dataset/{uuid},{version}`);
const URL_AUTOCOMPLETE = UrlTemplate.parse(`/api/v1/dataset/{uuid}/datasetcreator/autocomplete`);
......@@ -289,21 +290,43 @@ class DatasetService {
}
/**
* upsertAccessions at /api/v1/dataset/upsertaccessions/{uuid},{version}
* addAccessions at /api/v1/dataset/add-accessions/{uuid},{version}
*
* @param uuid uuid
* @param version version
* @param accessionRefs accessionRefs
*/
public static upsertAccessions(uuid: string, version: number, accessionRefs: AccessionRef[]): Promise<Dataset> {
public static addAccessions(uuid: string, version: number, accessionRefs: AccessionRef[]): Promise<Dataset> {
const apiUrl = URL_UPSERT_ACCESSIONS.expand({ uuid, version });
const apiUrl = URL_ADD_ACCESSIONS.expand({ uuid, version });
// console.log(`Fetching from ${apiUrl}`);
const content = { data: accessionRefs };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
timeout: 0, // don't timeout
...content,
}).then(({ data }) => data as Dataset);
}
/**
* setAccessions at /api/v1/dataset/add-accessions/{uuid},{version}
*
* @param uuid uuid
* @param version version
* @param accessionRefs accessionRefs
*/
public static setAccessions(uuid: string, version: number, accessionRefs: AccessionRef[]): Promise<Dataset> {
const apiUrl = URL_SET_ACCESSIONS.expand({ uuid, version });
// console.log(`Fetching from ${apiUrl}`);
const content = { data: accessionRefs };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
timeout: 0, // don't timeout
...content,
}).then(({ data }) => data as Dataset);
}
......
......@@ -12,6 +12,8 @@ import {AccessionRef} from 'model/accession/AccessionRef';
const URL_LIST_ACCESSIONS = UrlTemplate.parse(`/api/v1/subset/accessions/{uuid}`);
const URL_ADD_ACCESSIONS = UrlTemplate.parse(`/api/v1/subset/add-accessions/{uuid},{version}`);
const URL_SET_ACCESSIONS = UrlTemplate.parse(`/api/v1/subset/set-accessions/{uuid},{version}`);
const URL_REMATCH_ACCESSIONS = UrlTemplate.parse(`/api/v1/subset/rematch-accessions/{uuid},{version}`);
const URL_APPROVE_SUBSET = `/api/v1/subset/approve`;
const URL_CREATE = `/api/v1/subset/create`;
const URL_REVIEW_SUBSET = `/api/v1/subset/for-review`;
......@@ -66,11 +68,53 @@ class SubsetService {
* @param version version
* @param accessionIds accessionIds
*/
public static addAccessions(uuid: string, version: number, accessionIds: string[]): Promise<Subset> {
public static addAccessions(uuid: string, version: number, accessionRefs: AccessionRef[]): Promise<Subset> {
const apiUrl = URL_ADD_ACCESSIONS.expand({uuid, version});
// console.log(`Fetching from ${apiUrl}`);
const content = { data: accessionIds };
const content = { data: accessionRefs };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
timeout: 0, // don't timeout
...content,
}).then(({ data }) => data as Subset);
}
/**
* setAccessions at /api/v1/subset/set-accessions/{uuid},{version}
*
* @param uuid UUID
* @param version version
* @param accessionIds accessionIds
*/
public static setAccessions(uuid: string, version: number, accessionRefs: AccessionRef[]): Promise<Subset> {
const apiUrl = URL_SET_ACCESSIONS.expand({uuid, version});
// console.log(`Fetching from ${apiUrl}`);
const content = { data: accessionRefs };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
timeout: 0, // don't timeout
...content,
}).then(({ data }) => data as Subset);
}
/**
* rematchAccessions at /api/v1/subset/rematch-accessions/{uuid},{version}
*
* @param uuid UUID
* @param version version
* @param accessionIds accessionIds
*/
public static rematchAccessions(uuid: string, version: number): Promise<Subset> {
const apiUrl = URL_REMATCH_ACCESSIONS.expand({uuid, version});
// console.log(`Fetching from ${apiUrl}`);
const content = { };
return axiosBackend.request({
url: apiUrl,
......
......@@ -12,24 +12,47 @@ import { AccessionRef } from 'model/accession/AccessionRef';
// Service
import SubsetService from 'service/genesys/SubsetService';
import AccessionService from 'service/genesys/AccessionService';
// UI
import steps from 'subsets/ui/dashboard/subset-stepper/steps';
// Accession Identifiers step
export const updateSubsetAccessionRefs = (subset: Subset, accessionRefs: AccessionRef[]) => (dispatch) => {
return AccessionService.toUUID(accessionRefs)
.then((accessionRefs) => {
SubsetService.addAccessions(subset.uuid, subset.version, Object.keys(accessionRefs))
.then((subset) => {
dispatch(receiveSubset(subset));
dispatch(loadMoreAccessions(subset.uuid));
return subset;
});
export const addSubsetAccessionRefs = (subset: Subset, accessionRefs: AccessionRef[]) => (dispatch) => {
return SubsetService.addAccessions(subset.uuid, subset.version, accessionRefs)
.then((subset) => {
dispatch(receiveSubset(subset));
dispatch(loadMoreAccessions(subset.uuid));
return subset;
});
};
export const clearAccessionRefList = (subset: Subset) => {
return (dispatch, getState) => {
return SubsetService.setAccessions(subset.uuid, subset.version, [])
.then((saved) => {
dispatch(receiveSubset(saved));
dispatch(loadMoreAccessions(saved.uuid));
return saved;
}).catch((error) => {
console.log('Clear error', error);
});
};
};
export const rematchSubsetAccessions = (subset: Subset) => {
return (dispatch, getState) => {
return SubsetService.rematchAccessions(subset.uuid, subset.version)
.then((saved) => {
dispatch(receiveSubset(saved));
dispatch(loadMoreAccessions(saved.uuid));
return saved;
}).catch((error) => {
console.log('Rematch error', error);
});
};
};
// Review step
export const publishSubset = (subset: Subset) => (dispatch) => {
return SubsetService.reviewSubset(subset.uuid, subset.version)
......
......@@ -18,6 +18,8 @@ import CSVConfiguration, { CSVConfig } from 'ui/common/csv-configuration/CSVConf
import AccessionRefsTable from 'ui/catalog/accession/AccessionRefsTable';
import Loading from 'ui/common/Loading';
import Page from 'model/Page';
import ButtonBar from 'ui/common/buttons/ButtonBar';
import ActionButton from 'ui/common/buttons/ActionButton';
interface IListOfAccession extends React.ClassAttributes<any> {
classes: any;
......@@ -25,6 +27,8 @@ interface IListOfAccession extends React.ClassAttributes<any> {
onAccessionsUpdated: (AccessionRefs: AccessionRef[]) => Promise<Subset>;
accessionRefs: Page<AccessionRef>;
loadAccessions: (page?: Page<AccessionRef>) => any;
rematchAccessions: (subset: Subset) => void;
clearAccessionRefList: (subset: Subset) => void;
t: any;
}
......@@ -62,6 +66,15 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
this.setState({...this.state, csvConfig: value});
}
private rematchAccessions = () => {
const {subset, rematchAccessions} = this.props;
rematchAccessions(subset);
}
private clearList = () => {
const {subset, clearAccessionRefList} = this.props;
clearAccessionRefList(subset);
}
public constructor(props: any) {
super(props);
......@@ -107,7 +120,17 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
{ uploading && <Loading message={ uploadText } /> }
<h3>{ t('subsets.dashboard.p.stepper.accessionList.accessionListCount', {count: subset && subset.accessionCount || 0}) }</h3>
<h3>
{ t('subsets.dashboard.p.stepper.accessionList.accessionListCount', {count: subset && subset.accessionCount || 0}) }
{ !uploading &&
<span className="float-right">
<ButtonBar>
<ActionButton title={ t('datasets.dashboard.p.stepper.listOfAccessions.rematch') } action={ this.rematchAccessions }/>
<ActionButton title={ t('datasets.dashboard.p.stepper.listOfAccessions.clearList') } action={ this.clearList }/>
</ButtonBar>
</span>
}
</h3>
<AccessionRefsTable
loadNextPage={ loadAccessions }
paged={ accessionRefs }
......
......@@ -2,7 +2,7 @@ import * as React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
// actions
import { updateSubsetAccessionRefs } from 'subsets/actions/editor';
import { addSubsetAccessionRefs, rematchSubsetAccessions, clearAccessionRefList } from 'subsets/actions/editor';
import {loadMoreAccessions} from 'subsets/actions/dashboard';
// models
......@@ -18,6 +18,8 @@ import Loading from 'ui/common/Loading';
interface IAccessionsListStep extends React.ClassAttributes<any> {
item: Subset;
updateSubsetAccessionRefs: (subset: Subset, accessionRefs: AccessionRef[]) => Promise<Subset>;
rematchSubsetAccessions: (subset: Subset) => Promise<Subset>;
clearAccessionRefList: (subset: Subset) => Promise<Subset>;
loadMore: (uuid: string, page?: Page<AccessionRef>) => any;
accessionRefs: Page<AccessionRef>;
uuid: string;
......@@ -44,13 +46,15 @@ class AccessionsListStep extends StepperTemplate<IAccessionsListStep> {
}
protected renderContent = () => {
const { item, accessionRefs } = this.props;
const { item, accessionRefs, rematchSubsetAccessions, clearAccessionRefList } = this.props;
return !item ? <Loading /> : (
<ListOfAccessions
onAccessionsUpdated={ this.updateaccessionRefs }
subset={ item }
accessionRefs={ accessionRefs }
rematchAccessions={ rematchSubsetAccessions }
clearAccessionRefList={ clearAccessionRefList }
loadAccessions={ this.loadMoreAccessions }
/>
);
......@@ -69,7 +73,9 @@ const mapStateToProps = (state, ownProps) => ({
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
updateSubsetAccessionRefs,
updateSubsetAccessionRefs: addSubsetAccessionRefs,
rematchSubsetAccessions,
clearAccessionRefList,
loadMore: loadMoreAccessions,
}, dispatch);
......
......@@ -94,7 +94,7 @@ class AccessionRefsTable extends React.Component<IAccessionRefsTableProps, any>
</TableRow>
);
return paged ? paged.content && paged.content.sort((a, b) => a.acceNumb.localeCompare(b.acceNumb)) && (
return paged ? paged.content && (
<div className={ this.props.classes.root }>
<Table maxHeight="500px" widths={ widths } headers={ [
t('institutes.common.instCode'),
......
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