Commit 6de885ea authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '321-reorder-descriptors-in-dataset' into 'master'

Resolve "Reorder descriptors in Dataset"

Closes #321

See merge request !250
parents 0d2c7117 9be1719d
......@@ -212,6 +212,15 @@ function addDescriptorsToDatasetRequest(dataset: Dataset, descriptor: Descriptor
};
}
export const setDescriptorsToDatasetRequest = (dataset: Dataset, descriptorUuids: string[]) => (dispatch, getState) => {
return DatasetService.setDescriptorsToDataset(getState().login.access_token, dataset, descriptorUuids)
.then((saved) => {
dispatch(receiveDataset(saved));
}).catch((error) => {
log('Add error', error);
});
};
function removeDescriptorsFromDatasetRequest(dataset: Dataset, descriptor: Descriptor) {
return (dispatch, getState) => {
const token = getState().login.access_token;
......
......@@ -60,6 +60,7 @@ export const LIST_DATASET_URL = `${DATASET_API}/list`;
export const PUBLISH_DATASET_URL = `${DATASET_API}/publish`;
export const UPDATE_DATASET_ACCESSIONS_URL = `${DATASET_API}/upsertaccessions`;
export const ADD_DESCRIPTORS_TO_DATASET_URL = `${DATASET_API}/add-descriptors`;
export const SET_DESCRIPTORS_TO_DATASET_URL = `${DATASET_API}/set-descriptors`;
export const REMOVE_DESCRIPTORS_FROM_DATASET_URL = `${DATASET_API}/remove-descriptors`;
// RepositoryFile API. Note: starts from 'GET_DATASET_URL'
......
......@@ -10,6 +10,7 @@ import { Partner } from 'model/partner.model';
import {
MY_DATASETS_LIST_URL, LIST_DATASET_URL, GET_DATASET_URL, CREATE_DATASET_URL, UPDATE_DATASET_URL, PUBLISH_DATASET_URL,
DELETE_DATASET_URL, UPDATE_DATASET_ACCESSIONS_URL, ADD_DESCRIPTORS_TO_DATASET_URL, REMOVE_DESCRIPTORS_FROM_DATASET_URL,
SET_DESCRIPTORS_TO_DATASET_URL,
} from 'constants/apiURLS';
export class DatasetService {
......@@ -129,6 +130,15 @@ export class DatasetService {
}).then(({ data }) => new Dataset(data));
}
public static setDescriptorsToDataset(token: string, dataset: Dataset, descriptorUuids: string[]): Promise<Dataset> {
return authenticatedRequest(token, {
url: `${SET_DESCRIPTORS_TO_DATASET_URL}/${dataset.uuid},${dataset.version}`,
method: 'POST',
data: [...descriptorUuids],
}).then(({ data }) => new Dataset(data));
}
public static removeDescriptorsFromDataset(token: string, dataset: Dataset, descriptorUuids: string[]): Promise<Dataset> {
return authenticatedRequest(token, {
......
......@@ -31,6 +31,11 @@ const steps = [
},
{
id: 7,
name: 'Reorder descriptors',
link: 'edit/reorder-descriptors',
},
{
id: 8,
name: 'Review and publish',
link: 'edit/review-and-publish',
},
......
import * as React from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import * as _ from 'lodash';
import {log} from 'utilities/debug';
import {setDescriptorsToDatasetRequest} from 'actions/dataset';
import DescriptorOrder from 'ui/common/reorderable/DescriptorOrder';
import steps from '../../steps';
import DatasetNavigator from '../../DatasetNavigator';
import {Dataset} from 'model/dataset.model';
interface IReorderTraitsStep extends React.ClassAttributes<any> {
dataset: Dataset;
setDescriptorsToDatasetRequest: (dataset: Dataset, descriptorUuids: string[]) => any;
stillLoading: boolean;
onDelete: () => void;
onPublish: () => void;
onGotoStep: (id: number) => () => void;
location: any;
}
class ReorderTraitsStep extends React.Component<IReorderTraitsStep, any> {
public constructor(props: any) {
super(props);
this.state = {
childrenRef: null,
};
}
protected gotoStep = (id) => () => {
const {dataset, setDescriptorsToDatasetRequest} = this.props;
const descriptors = this.state.childrenRef.state.descriptors;
if (!_.isEqual({...dataset.descriptors}, {...descriptors})) {
log('Saving descriptors ', descriptors);
setDescriptorsToDatasetRequest(dataset, descriptors.map((e) => e.uuid));
}
this.props.onGotoStep(id);
}
private onRef = (that) => {
this.setState({ ...this.state, childrenRef: that });
}
public render() {
const { dataset, stillLoading, onDelete, onPublish } = this.props;
return (
<DatasetNavigator location={ location } stillLoading={ stillLoading }
disabledNext={ false } disabled={ false } steps={ steps }
gotoStep={ this.gotoStep } onDelete={ onDelete } onPublish={ onPublish }>
<DescriptorOrder onRef={ this.onRef } descriptors={ dataset.descriptors } />
</DatasetNavigator>
);
}
}
const mapStateToProps = (state, ownProps) => ({
dataset: state.datasets.currentDataset,
stillLoading: ownProps.stillLoading,
location: ownProps.location,
onDelete: ownProps.onDelete,
onGotoStep: ownProps.onGotoStep,
onPublish: ownProps.onPublish,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
setDescriptorsToDatasetRequest,
}, dispatch);
export default connect(
mapStateToProps, mapDispatchToProps,
)(ReorderTraitsStep);
......@@ -41,6 +41,7 @@ import AccessionsListStep from './pages/dataset/dataset-stepper/steps/accessions
import TimingAndLocationStep from './pages/dataset/dataset-stepper/steps/timing-and-location';
import ReviewAndPublishStep from './pages/dataset/dataset-stepper/steps/review';
import Traits from './pages/dataset/dataset-stepper/steps/traits';
import ReorderTraitsStep from 'ui/pages/dataset/dataset-stepper/steps/reorder';
import UserProfilePage from './pages/profile/ProfilePage';
import AccessionsBrowsePage from './pages/genesys/BrowsePage';
......@@ -241,6 +242,11 @@ const routes = [
component: Traits,
exact: true,
},
{
path: '/reorder-descriptors',
component: ReorderTraitsStep,
exact: true,
},
{
path: '/review-and-publish',
component: ReviewAndPublishStep,
......
Supports Markdown
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