Commit 1e62f327 authored by Matija Obreza's avatar Matija Obreza
Browse files

Subsets: Don't send accessionRefs for basic updates

- Loading indicator
parent 72192b83
......@@ -10,7 +10,6 @@ import AccessionMapInfo from 'model/accession/AccessionMapInfo';
import { RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEND_ACCESSIONS, RECEIVE_ACCESSION_MAPINFO } from 'accessions/constants';
import AccessionService from 'service/genesys/AccessionService';
import { AccessionRef } from 'model/accession/AccessionRef';
import { showSnackbar } from 'actions/snackbar';
import Page from 'model/Page';
......@@ -39,10 +38,6 @@ const receiveAccession = (accession: AccessionDetails, error = null) => ({
payload: { accession, error },
});
export const toUUIDPromise = (identifiers: AccessionRef[]) => (dispatch, getState): Promise<Map<string, AccessionRef>> => {
return AccessionService.toUUID(identifiers);
};
export const updateRoute = (paged: FilteredPage<Accession>, path: string = '/a') => (dispatch) => {
const qs = {
s: paged.sort[0].property === Accession.DEFAULT_SORT.property ? undefined : paged.sort[0].property,
......
// Actions
import navigateTo from 'actions/navigation';
import { toUUIDPromise } from 'accessions/actions/public'; // TODO
import { receiveSubset, removeSubset } from './dashboard';
// Constants
......@@ -13,17 +12,19 @@ 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) => {
dispatch(toUUIDPromise(AccessionRefs))
.then((AccessionRefs) => {
SubsetService.addAccessions(subset.uuid, subset.version, Object.keys(AccessionRefs))
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));
return subset;
});
});
};
......@@ -35,6 +36,7 @@ export const publishSubset = (subset: Subset) => (dispatch) => {
dispatch(receiveSubset(subset));
});
};
export const unpublishSubset = (subset: Subset) => (dispatch) => {
return SubsetService.rejectSubset(subset.uuid, subset.version)
.then((subset) => {
......@@ -127,6 +129,14 @@ export const saveSubset = (subset: Subset) => (dispatch) => {
dispatch(gotoNextStep(subset));
});
}
return SubsetService.update(subset)
// remove normalized data here
const data: Subset = {
...subset,
creators: [],
accessionRefs: [],
};
return SubsetService.update(data)
.then((subset) => dispatch(receiveSubset(subset)));
};
......@@ -16,11 +16,12 @@ import Subset from 'model/subset/Subset';
// ui
import CSVConfiguration, { CSVConfig } from 'ui/common/csv-configuration/CSVConfiguration';
import AccessionRefsTable from 'ui/catalog/accession/AccessionRefsTable';
import Loading from 'ui/common/Loading';
interface IListOfAccession extends React.ClassAttributes<any> {
classes: any;
subset: Subset;
onAccessionsUpdated: (AccessionRefs: AccessionRef[]) => void;
onAccessionsUpdated: (AccessionRefs: AccessionRef[]) => Promise<Subset>;
t: any;
}
......@@ -40,16 +41,20 @@ const styleSheet = {
class ListOfAccession extends React.Component<IListOfAccession, any> {
public dataPasted = (e) => {
e.preventDefault();
this.setState({ ...this.state, uploading: true, uploadText: 'Parsing' });
console.log('Pasted', e.clipboardData);
// console.log(e.clipboardData.getData('text/plain'));
this.parseCsv(e.clipboardData.getData('text/plain'));
// Delay parsing a little bit for UI to update
const data = e.clipboardData.getData('text/plain');
setTimeout(() => this.parseCsv(data), 10);
}
public textBlurred = (e) => {
this.parseCsv(e.target.value);
}
private onUpdateCsvConfig = (value: CSVConfig) => {
this.setState({...this.state, csvConfig: value});
}
......@@ -64,12 +69,14 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
quote: '"',
autodetect: false,
},
uploading: false,
};
}
public render() {
const {classes, subset, t} = this.props;
const { classes, subset, t } = this.props;
const { uploading, uploadText } = this.state;
return (
<div className={ `${ classes.root } m-20 p-20 even-row` }>
......@@ -95,9 +102,11 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
</div>
{ uploading && <Loading message={ uploadText } /> }
<h3>{ t('subsets.dashboard.p.stepper.accessionList.accessionListCount', {count: subset.accessionRefs && subset.accessionRefs.length || 0}) }</h3>
{ subset.accessionRefs &&
<AccessionRefsTable AccessionRefs={ subset.accessionRefs.map((accessionRef) => (
<AccessionRefsTable accessionRefs={ subset.accessionRefs.map((accessionRef) => (
{
doi: accessionRef.accession.doi,
instCode: accessionRef.accession.institute.code,
......@@ -114,6 +123,7 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
private parseCsv(csvText: string) {
// log('CSV text', csvText);
if (!csvText) {
this.setState({ ...this.state, uploading: false, uploadText: undefined });
return;
}
......@@ -124,15 +134,23 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
const newIdentifiers: AccessionRef[] = [];
CSV.parse(csvText, config, {headers: [ 'instCode', 'acceNumb', 'genus', 'species', 'doi']})
CSV.parse(csvText, config, { headers: ['instCode', 'acceNumb', 'genus', 'species', 'doi'] })
.subscribe((jsonObj) => {
const aid: AccessionRef = new AccessionRef(jsonObj);
newIdentifiers.push(aid);
log(aid);
// log(aid);
}).then(() => {
log('All CSV parsed');
this.props.onAccessionsUpdated(newIdentifiers);
});
log('All CSV parsed');
this.setState({ ...this.state, uploading: true, uploadText: 'Uploading to server' });
this.props.onAccessionsUpdated(newIdentifiers)
.then((dataset) => {
console.log('Done', dataset);
this.setState({ ...this.state, uploading: false });
}).catch((err) => {
this.setState({ ...this.state, uploading: false });
console.log('Error uploading', err);
});
});
}
}
......
......@@ -18,7 +18,7 @@ interface IAccessionsListStep extends React.ClassAttributes<any> {
updateSubsetAccessionRefs: (subset: Subset, accessionRefs: AccessionRef[]) => Promise<Subset>;
}
class AccessionsListStep extends StepperTemplate<IAccessionsListStep> {
class AccessionsListStep extends StepperTemplate<IAccessionsListStep> {
protected renderContent = () => {
const { item } = this.props;
......@@ -32,11 +32,12 @@ class AccessionsListStep extends StepperTemplate<IAccessionsListStep> {
}
protected updateaccessionRefs = (AccessionRefs: AccessionRef[]) => {
const {item: subset, updateSubsetAccessionRefs} = this.props;
updateSubsetAccessionRefs(subset, AccessionRefs);
const { item: subset, updateSubsetAccessionRefs } = this.props;
return updateSubsetAccessionRefs(subset, AccessionRefs);
}
}
const mapStateToProps = (state, ownProps) => ({
// null
});
......
......@@ -5,7 +5,6 @@ import { withStyles } from '@material-ui/core/styles';
import { AccessionRef } from 'model/accession/AccessionRef';
import { Table as VTable, Column as VColumn, AutoSizer } from 'react-virtualized';
import DOI from 'ui/common/DOI';
// import Hidden from '@material-ui/core/Hidden';
const styles = (theme) => ({
......@@ -34,7 +33,7 @@ const styles = (theme) => ({
interface IAccessionRefsTableProps extends React.ClassAttributes<any> {
classes: any;
AccessionRefs: AccessionRef[];
accessionRefs: AccessionRef[];
t: any;
}
......@@ -45,12 +44,12 @@ class AccessionRefsTable extends React.Component<IAccessionRefsTableProps, any>
}
public render() {
const { AccessionRefs, classes, t } = this.props;
const rowGetter = ({ index }) => AccessionRefs[index];
const { accessionRefs, classes, t } = this.props;
const rowGetter = ({ index }) => accessionRefs[index];
const renderDoi = ({ cellData }) => <DOI noPrefix value={ cellData } />;
const rowClassName = ({ index }) => index === -1 ? '' : `${classes.tableCell} ${index % 2 === 0 ? classes.evenRow : classes.oddRow}`;
return AccessionRefs && AccessionRefs.sort((a, b) => a.acceNumb.localeCompare(b.acceNumb)) && (
return accessionRefs && accessionRefs.sort((a, b) => a.acceNumb.localeCompare(b.acceNumb)) && (
<AutoSizer disableHeight>
{ ({ width }) => (
<VTable
......@@ -59,7 +58,7 @@ class AccessionRefsTable extends React.Component<IAccessionRefsTableProps, any>
height={ 500 }
headerHeight={ 25 }
rowHeight={ 30 }
rowCount={ AccessionRefs.length }
rowCount={ accessionRefs.length }
rowGetter={ rowGetter }
rowClassName={ rowClassName }
headerClassName={ `back-green` }
......
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