Commit e79ddd15 authored by Maxym Borodenko's avatar Maxym Borodenko

Detect accessions in Dataset file

parent f2653cfe
......@@ -1229,6 +1229,10 @@
"rowCount_pural": "{{count, number}} accessions",
"placeholder": "Paste accessions data here (comma separated)",
"rematch": "Rematch accessions",
"detect": "Detect accessions",
"detectionResult": "{{count, number}} accession reference was added.",
"detectionResult_plural": "{{count, number}} accession references were added.",
"detectionNoResults": "No accession references were found to add.",
"clearList": "Clear list"
},
"pastingTraits": {
......
......@@ -15,7 +15,10 @@ import { listAccessionsByUuid } from 'accessions/actions/public';
import { clearDataset } from 'datasets/actions/public';
// Constants
import { ADD_CREATOR_TO_DATASET, ADD_LOCATION, RECEIVE_LOCATION, REMOVE_CREATOR_FROM_DATASET, REMOVE_LOCATION, UPDATE_DATASET_CREATOR, DASHBOARD_RECEIVE_DATASET } from 'datasets/constants';
import {
ADD_CREATOR_TO_DATASET, ADD_LOCATION, RECEIVE_LOCATION, REMOVE_CREATOR_FROM_DATASET,
REMOVE_LOCATION, UPDATE_DATASET_CREATOR, DASHBOARD_RECEIVE_DATASET,
} from 'datasets/constants';
// Models
import Dataset from 'model/catalog/Dataset';
......@@ -51,6 +54,7 @@ const apiCreateDataset = createApiCaller(DatasetService.createDataset, DASHBOARD
const apiSetAccessions = createApiCaller(DatasetService.setAccessions, DASHBOARD_RECEIVE_DATASET);
const apiAddAccessions = createApiCaller(DatasetService.addAccessions, DASHBOARD_RECEIVE_DATASET);
const apiDetectAccessions = createApiCaller(DatasetService.detectAccessions, DASHBOARD_RECEIVE_DATASET);
const apiRematchDatasetAccessions = createApiCaller(DatasetService.rematchDatasetAccessions, DASHBOARD_RECEIVE_DATASET);
const apiDecodeAcceNumbers = createPureApiCaller(AccessionService.uuidsFromAcceNumbers);
......@@ -154,8 +158,23 @@ const addAccessionRefsByAcceNumbers = (dataset: Dataset, acceNumbers: string[],
});
};
const detectAccessions = (dataset: Dataset) => (dispatch) => {
return dispatch(apiDetectAccessions(dataset.uuid))
.then((saved: Dataset) => {
if (dataset.version === saved.version) {
dispatch(showSnackbar('datasets.dashboard.p.stepper.listOfAccessions.detectionNoResults'));
} else {
dispatch(showSnackbar('datasets.dashboard.p.stepper.listOfAccessions.detectionResult', { count: (saved.accessionCount - dataset.accessionCount) }));
}
return dispatch(loadMoreAccessions(saved.uuid));
});
};
// Accession identifiers step exports
export { addDatasetAccessionRefs as addDatasetAccessionRefs, rematchDatasetAccessions, clearAccessionRefList, addAccessionRefsByAcceNumbers };
export {
addDatasetAccessionRefs as addDatasetAccessionRefs, rematchDatasetAccessions,
detectAccessions, clearAccessionRefList, addAccessionRefsByAcceNumbers,
};
// Descriptors step
......
......@@ -126,6 +126,10 @@
"rowCount_pural": "{{count, number}} accessions",
"placeholder": "Paste accessions data here (comma separated)",
"rematch": "Rematch accessions",
"detect": "Detect accessions",
"detectionResult": "{{count, number}} accession reference was added.",
"detectionResult_plural": "{{count, number}} accession references were added.",
"detectionNoResults": "No accession references were found to add.",
"clearList": "Clear list"
},
"pastingTraits": {
......
......@@ -29,6 +29,7 @@ interface IListOfAccession extends React.ClassAttributes<any>, WithTranslation,
rematchDatasetAccessions: (dataset: Dataset) => void;
clearAccessionRefList: (dataset: Dataset) => void;
addAccessionRefsByAcceNumbers: (dataset: Dataset, acceNumbers: string[], instCode?: string) => void;
detectAccessions: (dataset: Dataset) => Promise<Dataset>;
}
const styleSheet = {
......@@ -73,6 +74,10 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
const {dataset, rematchDatasetAccessions} = this.props;
rematchDatasetAccessions(dataset);
}
private detectAccessions = () => {
const {dataset, detectAccessions} = this.props;
detectAccessions(dataset);
}
private clearList = () => {
const {dataset, clearAccessionRefList, t} = this.props;
confirm(<span>{ `${t('datasets.dashboard.p.stepper.listOfAccessions.clearList')}?` }</span>, {
......@@ -156,6 +161,7 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
{ !uploading &&
<span className="float-right">
<ButtonBar>
<ActionButton title={ t('datasets.dashboard.p.stepper.listOfAccessions.detect') } action={ this.detectAccessions }/>
<AddAccessionsDialog
className={ classes.addButton }
decodeAcceNumbers={ addAccessionRefsByAcceNumbers.bind(null, dataset) }
......
......@@ -3,10 +3,8 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
// actions
import {
rematchDatasetAccessions,
addDatasetAccessionRefs,
clearAccessionRefList,
addAccessionRefsByAcceNumbers,
rematchDatasetAccessions, addDatasetAccessionRefs, clearAccessionRefList,
addAccessionRefsByAcceNumbers, detectAccessions,
} from 'datasets/actions/editor';
import {loadMoreAccessions} from 'datasets/actions/dashboard';
......@@ -34,6 +32,7 @@ interface IAccessionsListStep extends React.ClassAttributes<any> {
clearAccessionRefList: (dataset: Dataset) => void;
rematchDatasetAccessions: (dataset: Dataset) => void;
addAccessionRefsByAcceNumbers: (dataset: Dataset, acceNumbers: string[], instCode?: string) => void;
detectAccessions: (dataset: Dataset) => Promise<Dataset>;
}
class AccessionsListStep extends StepperTemplate<IAccessionsListStep> {
......@@ -55,6 +54,7 @@ class AccessionsListStep extends StepperTemplate<IAccessionsListStep> {
rematchDatasetAccessions={ rematchDatasetAccessions }
clearAccessionRefList={ clearAccessionRefList }
addAccessionRefsByAcceNumbers={ addAccessionRefsByAcceNumbers }
detectAccessions={ this.props.detectAccessions }
/>
);
}
......@@ -89,6 +89,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
rematchDatasetAccessions,
loadMore: loadMoreAccessions,
addAccessionRefsByAcceNumbers,
detectAccessions,
}, dispatch);
export default connect(
......
......@@ -14,6 +14,7 @@ import DatasetOverview from 'model/catalog/DatasetOverview';
import { dereferenceReferences2 } from 'utilities';
const URL_LIST_ACCESSIONS = UrlTemplate.parse(`/api/v1/dataset/accessions/{uuid}`);
const URL_DETECT_ACCESSIONS = UrlTemplate.parse(`/api/v1/dataset/detect-accessions/{uuid}`);
const URL_ADD_DESCRIPTORS = UrlTemplate.parse(`/api/v1/dataset/add-descriptors/{uuid},{version}`);
const URL_APPROVE_DATASET = `/api/v1/dataset/approve`;
const URL_CREATE_DATASET = `/api/v1/dataset/create`;
......@@ -83,6 +84,19 @@ class DatasetService {
});
}
public static detectAccessions(uuid: string, xhrConfig?): Promise<Dataset> {
const apiUrl = URL_DETECT_ACCESSIONS.expand({ uuid });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as Dataset);
}
/**
* addDescriptors at /api/v1/dataset/add-descriptors/{uuid},{version}
*
......
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