Commit 21ddac75 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

WIP: added addObservations UI

parent a9c001ac
......@@ -2,7 +2,7 @@
import {createApiCaller, createPureApiCaller} from 'actions/ApiCall';
import { showSnackbar } from 'actions/snackbar';
// Constants
import {RECEIVE_PREVIEW, RECEIVE_PREVIEW_DATA, RECEIVE_AMPHIBIAN_DATASET, RECEIVE_DRYRUN_DATA} from 'amphibian/constants';
import {RECEIVE_PREVIEW, RECEIVE_PREVIEW_DATA, RECEIVE_AMPHIBIAN_DATASET, RECEIVE_DRYRUN_DATA, RECEIVE_OBSERVATIONS_DATA} from 'amphibian/constants';
// model
import DatasetTable from 'model/amphibian/DatasetTable';
// Service
......@@ -15,7 +15,8 @@ const apiGetDataset = createApiCaller(AmphibianService.getDataset, RECEIVE_AMPHI
const apiCreateDataset = createApiCaller(AmphibianService.createDataset, RECEIVE_AMPHIBIAN_DATASET);
const apiGetPreviewData = createApiCaller(AmphibianService.getData, RECEIVE_PREVIEW_DATA);
const apiDryrunIngest = createPureApiCaller(AmphibianService.dryrunIngest, {noCancel: true});
const apiAddObservations = createPureApiCaller(AmphibianService.addObservations);
const apiGetObservations = createApiCaller(AmphibianService.getObservations, RECEIVE_OBSERVATIONS_DATA);
const apiAddObservations = createApiCaller(AmphibianService.addObservations, RECEIVE_OBSERVATIONS_DATA);
const apiUpdateDatasetTable = createApiCaller(AmphibianService.updateDataset, RECEIVE_AMPHIBIAN_DATASET);
......@@ -53,6 +54,10 @@ export const getPreviewData = (uuid: string, sheet: number, startRow: number, co
return dispatch(apiGetPreviewData(uuid, sheet, startRow, count));
};
export const getObservations = (uuid: string, skip: number, count: string = '50', fields?: string[]) => (dispatch) => {
return dispatch(apiGetObservations(uuid, skip || '0', count, fields));
};
export const addObservations = ( uuid: string, fileUuid: string, sheet?: number) => (dispatch) => {
return dispatch(apiAddObservations(uuid, fileUuid, sheet));
};
export const RECEIVE_PREVIEW = 'amphibian/public/RECEIVE_PREVIEW';
export const RECEIVE_PREVIEW_DATA = 'amphibian/public/RECEIVE_PREVIEW_DATA';
export const RECEIVE_OBSERVATIONS_DATA = 'amphibian/public/RECEIVE_OBSERVATIONS_DATA';
export const RECEIVE_AMPHIBIAN_DATASET = 'amphibian/public/RECEIVE_AMPHIBIAN_DATASET';
export const RECEIVE_DRYRUN_DATA = 'amphibian/public/RECEIVE_DRYRUN_DATA';
......
import update from 'immutability-helper';
import {RECEIVE_AMPHIBIAN_DATASET, RECEIVE_DRYRUN_DATA, RECEIVE_PREVIEW, RECEIVE_PREVIEW_DATA} from 'amphibian/constants';
import {RECEIVE_AMPHIBIAN_DATASET, RECEIVE_DRYRUN_DATA, RECEIVE_OBSERVATIONS_DATA, RECEIVE_PREVIEW, RECEIVE_PREVIEW_DATA} from 'amphibian/constants';
import ApiCall from 'model/ApiCall';
import { IReducerAction } from 'model/common.model';
import Preview from 'model/amphibian/Preview';
import DatasetTable from 'model/amphibian/DatasetTable';
import IPreviewRow from 'model/amphibian/IPreviewRow';
import AccessionObservations from 'model/amphibian/AccessionObservations';
const INITIAL_STATE: {
......@@ -13,11 +14,13 @@ const INITIAL_STATE: {
previewData: ApiCall<IPreviewRow[]>,
datasetTable: ApiCall<DatasetTable>,
dryRunResult: any,
observations: ApiCall<AccessionObservations[]>,
} = {
preview: null,
previewData: null,
datasetTable: null,
dryRunResult: {},
observations: null,
};
export default function geo(state = INITIAL_STATE, action: IReducerAction = {type: ''}) {
......@@ -49,6 +52,12 @@ export default function geo(state = INITIAL_STATE, action: IReducerAction = {typ
},
});
}
case RECEIVE_OBSERVATIONS_DATA: {
const {apiCall} = action.payload;
return update(state, {
observations: {$set: apiCall},
});
}
default:
return state;
......
......@@ -3,14 +3,13 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {withTranslation, WithTranslation} from 'react-i18next';
// actions
import {dryRunIngestMultiple, getDataset, updateDataset, addObservations} from 'amphibian/actions/public';
import {dryRunIngestMultiple, getDataset, updateDataset} from 'amphibian/actions/public';
import {loadDataset} from 'datasets/actions/dashboard';
import navigateTo from 'actions/navigation';
// model
import IPreviewRow from 'model/amphibian/IPreviewRow';
import DatasetTable from 'model/amphibian/DatasetTable';
import Dataset from 'model/catalog/Dataset';
import AccessionObservations from 'model/amphibian/AccessionObservations';
// ui
import Loading from 'ui/common/Loading';
import Markdown from 'ui/common/markdown';
......@@ -33,7 +32,6 @@ interface IDatasetTraitsProps extends React.ClassAttributes<any>, WithTranslatio
getDataset: (uuid: string) => void;
dryRunIngestMultiple: (uuid: string, sheet: number, firstRow: number, traits: any) => void;
getPreviewData: (uuid: string, sheet: number, startRow: number, count?: number) => Promise<IPreviewRow[]>;
addObservations: ( uuid: string, fileUuid: string, sheet?: number) => Promise<AccessionObservations[]>;
navigateTo: (path: string) => void;
}
......@@ -65,12 +63,6 @@ class DryrunTestStep extends StepperTemplate<IDatasetTraitsProps> {
}
}
protected addObservations = () => {
const {datasetUuid, uuid, sheet, addObservations} = this.props;
addObservations(datasetUuid, uuid, sheet)
.then((res) => console.log('Added Observation: ', res));
};
protected dryRun = () => {
const {uuid, datasetTable, sheet, dryRunIngestMultiple} = this.props;
......@@ -129,7 +121,6 @@ class DryrunTestStep extends StepperTemplate<IDatasetTraitsProps> {
</div>
))}
<ActionButton title={t('common:action.test')} action={this.dryRun} className="float-right"/>
<ActionButton title={t('common:action.addObservations')} action={this.addObservations} className="float-right mr-1rem"/>
</div>
}
</PageContents>
......@@ -150,7 +141,6 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
getDataset,
updateDataset,
loadDataset,
addObservations,
dryRunIngestMultiple,
navigateTo,
}, dispatch);
......
import * as React from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {withTranslation, WithTranslation} from 'react-i18next';
// actions
import {addObservations, dryRunIngestMultiple, getDataset, getObservations, updateDataset} from 'amphibian/actions/public';
import {loadDataset} from 'datasets/actions/dashboard';
import navigateTo from 'actions/navigation';
// model
import AccessionObservations from 'model/amphibian/AccessionObservations';
// ui
import StepperTemplate from 'ui/common/stepper/StepperTemplate';
import ActionButton from 'ui/common/buttons/ActionButton';
import {PageContents} from 'ui/layout/PageLayout';
interface IPushToAmphibianPageProps extends React.ClassAttributes<any>, WithTranslation {
// preview: Preview;
uuid: string;
datasetUuid: string;
sheet: number;
observations: AccessionObservations[];
getObservations: (uuid: string, skip: number, count?: string, fields?: string[]) => void;
addObservations: (uuid: string, fileUuid: string, sheet?: number) => Promise<AccessionObservations[]>;
navigateTo: (path: string) => void;
}
class PushToAmphibianStep extends StepperTemplate<IPushToAmphibianPageProps> {
public componentDidMount() {
const {datasetUuid, observations, getObservations} = this.props;
if (datasetUuid && !observations) {
// console.log(`Loading dataset table for ${ uuid }`);
getObservations(datasetUuid, 0, '100'); // TODO count
}
// if (datasetTable && datasetTable.extras.sources[uuid][sheet] && !datasetTable.extras.sources[uuid][sheet].headers) { // TODO
// return navigateTo(`/dashboard/amphibian/${datasetUuid}/${uuid}/${sheet}/edit`);
// }
}
public componentDidUpdate(prevProps: Readonly<IPushToAmphibianPageProps>) {
const {datasetUuid: oldDatasetUuid} = prevProps;
const {datasetUuid, getObservations} = this.props;
if (oldDatasetUuid !== datasetUuid) {
// console.log(`Loading dataset table for ${ uuid }`);
getObservations(datasetUuid, 0, '100'); // TODO count
}
// if (datasetTable && datasetTable.extras.sources[uuid][sheet] && !datasetTable.extras.sources[uuid][sheet].headers) { // TODO
// return navigateTo(`/dashboard/amphibian/${datasetUuid}/${uuid}/${sheet}/edit`);
// }
}
protected addObservations = () => {
const {datasetUuid, uuid, sheet, addObservations} = this.props;
addObservations(datasetUuid, uuid, sheet)
.then((res) => console.log('Added Observation: ', res));
};
protected renderContent = () => {
const {observations, t} = this.props;
// if (!dataset || !datasetTable || (datasetTable.extras.sources[uuid][sheet] && !datasetTable.extras.sources[uuid][sheet].headers)) {
// return <Loading/>;
// }
return (
<PageContents>
{observations &&
<div className="mb-1rem mt-1rem">
<h3>{t('amphibian.dashboard.stepper.dryRunStep.traitsTest')}</h3>
<ActionButton title={t('common:action.addObservations')} action={this.addObservations} className="float-right mr-1rem"/>
<table className="genesys-table full-width">
<thead>
<td>{t('accessions.common.acceNumb')}</td>
<td>{t('accessions.common.instituteCode')}</td>
<td>{t('accessions.common.genus')}</td>
<td>{t('accessions.common.doi')}</td>
</thead>
{observations.map((observation) => (
<tr>
<td>{observation.accessionNumber}</td>
<td>{observation.instCode}</td>
<td>{observation.genus}</td>
<td>{observation.doi}</td>
</tr>
))}
</table>
</div>
}
</PageContents>
);
};
}
const mapStateToProps = (state, ownProps) => ({
uuid: ownProps.match.params.uuid,
datasetUuid: ownProps.match.params.datasetUuid,
sheet: ownProps.match.params.sheet || 0,
observations: state.amphibian.dashboard.observations ? state.amphibian.dashboard.observations.data : undefined,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
getDataset,
updateDataset,
loadDataset,
getObservations,
addObservations,
dryRunIngestMultiple,
navigateTo,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation()(PushToAmphibianStep));
......@@ -37,6 +37,15 @@ const steps = [
}),
exact: true,
},
{
id: 5,
name: 'amphibian.dashboard.stepper.pushTitle',
path: '/edit/push',
component: Loadable({
loader: () => import(/* webpackMode:"lazy", webpackChunkName: "amphibian" */'amphibian/ui/dashboard/stepper/push'),
}),
exact: true,
},
];
export default steps;
......@@ -129,7 +129,7 @@ class AmphibianService {
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'GET',
method: 'POST',
...content,
}).then(({ data }) => data as AccessionObservations[]);
}
......
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