Commit b0fdc97f authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza
Browse files

Using modular approach for partners, descriptors, descriptorLists and datasets

- added header to parent pages via Wrapper
- added markdown support for PartnerFilter
- removed most MyDataPage work with `tab`
- removed '/accessions' link from user menu (+14 squashed commits)
- now `editor` actions change both public and dashboard 'current' elements
- split DashboardPage into 3 separate pages, now MyDataPage is base page for other dashboard pages
- changed 'steps' routes, now steps declare once in 'steps.ts'
- Removed "list...ByCode" service methods
- migrated 'PageLoader' implementation from genesis-ui
- dashboard reducer now don't contain loaded items, only selected UUID-s
- moved constants to module folders
- added module for vocabulary
- put dashboard routes under '/dashboard' URL, put partner edit page under '/admin' URL
- removed genesys page and related actions, service and constants
- changed 'root' state names to 'public'
parent 67fd877d
// utilities
import {dereferenceReferences} from 'utilities';
import {log} from 'utilities/debug';
// constants
import {ADD_TO_EDIT_LIST, RECEIVE_DASHBOARD_PAGE, REMOVE_FROM_EDIT_LIST, RECEIVE_IS_EDIT_MODE, REMOVE_ITEM, REFRESH_ITEM, SELECT_ALL, UNSELECT_ALL} from 'constants/dashboard';
import {ADD_TO_EDIT_LIST, REMOVE_FROM_EDIT_LIST, RECEIVE_IS_EDIT_MODE, SELECT_ALL, UNSELECT_ALL} from 'constants/dashboard';
// Models
import {Dataset, IDatasetFilter} from 'model/dataset.model';
import {Descriptor, DescriptorList, IDescriptorFilter, IDescriptorListFilter} from 'model/descriptor.model';
import {Page, PublishState} from 'model/common.model';
import {Partner} from 'model/partner.model';
// service
import {DatasetService} from 'service/DatasetService';
import {DescriptorService} from 'service/DescriptorService';
import {DescriptorListService} from 'service/DescriptorListService';
// actions
import {addFilterCode} from 'actions/filterCode';
import {loadDescriptorListTitles} from 'actions/uuidDecoder';
import {Dataset} from 'model/dataset.model';
import {Descriptor, DescriptorList} from 'model/descriptor.model';
export const setEditMode = (payload: boolean) => (dispatch) => {
dispatch({type: RECEIVE_IS_EDIT_MODE, payload});
};
export const refreshDashboardPageItem = (item: any) => ({
type: REFRESH_ITEM,
payload: item,
});
export const removeDashboardPageItem = (item: any) => ({
type: REMOVE_ITEM,
payload: item,
});
export const selectAll = (tab: string) => (dispatch, getState) => {
let payload;
switch (tab) {
case 'descriptorlists': payload = getState().descriptorList.dashboard.paged.content.map((item) => item.uuid); break;
case 'descriptors': payload = getState().descriptors.dashboard.paged.content.map((item) => item.uuid); break;
case 'datasets':
default: payload = getState().datasets.dashboard.paged.content.map((item) => item.uuid);
}
export const selectAll = () => ({
type: SELECT_ALL,
});
return dispatch({
type: SELECT_ALL,
payload,
});
};
export const unselectAll = () => ({
type: UNSELECT_ALL,
});
const receivePaged = (paged: Page<Dataset> | Page<Descriptor> | Page<DescriptorList>) => (dispatch) => {
dispatch({type: RECEIVE_DASHBOARD_PAGE, payload: !paged ? paged : {...paged}});
};
const addToList = (payload: Dataset | Descriptor | DescriptorList) => (dispatch) => {
dispatch({type: ADD_TO_EDIT_LIST, payload: payload.uuid});
};
......@@ -58,12 +40,6 @@ const removeFromList = (payload: Dataset | Descriptor | DescriptorList) => (disp
export const onPageChange = () => (dispatch) => {
dispatch(setEditMode(false));
dispatch(unselectAll());
dispatch(receivePaged(null));
};
const receiveAndPushDashboardPage = (paged: any) => (dispatch, getState) => {
const oldContent = getState().dashboard.paged && getState().dashboard.paged.content || [];
dispatch(receivePaged({...paged, content: [...oldContent, ...paged.content]}));
};
export const addToEditList = (item: Dataset | Descriptor | DescriptorList) => (dispatch, getState) => {
......@@ -80,167 +56,58 @@ export const removeFromEditList = (item: Dataset | Descriptor | DescriptorList)
}
};
/**
* Publish all items that are in dashboard.toEditList
* @param publishOne: (uuid: string) => Promise<any> action to publish one item
*/
export const publishAll = (publishOne) => (dispatch, getState) => {
const toEditList = getState().dashboard.selected;
const pagedContent = getState().dashboard.paged.content;
const toPublishItems = pagedContent.filter((pagedItem) => toEditList.indexOf(pagedItem.uuid) !== -1);
const toPublishItems = getState().dashboard.selected;
toPublishItems.map((item) => {
if (item.state === PublishState.DRAFT) {
dispatch(publishOne(item))
.then((published) => {
dispatch(removeFromList(published));
dispatch(refreshDashboardPageItem(published));
});
} else {
dispatch(removeFromList(item));
}
publishOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
/**
* Approve all items that are in dashboard.toEditList
* @param approveOne: (uuid: string) => Promise<any> action to approve one item
*/
export const approveAll = (approveOne) => (dispatch, getState) => {
const toEditList = getState().dashboard.selected;
const pagedContent = getState().dashboard.paged.content;
const toApproveItems = pagedContent.filter((pagedItem) => toEditList.indexOf(pagedItem.uuid) !== -1);
const toApproveItems = getState().dashboard.selected;
toApproveItems.map((item) => {
if (item.state === PublishState.REVIEWING) {
dispatch(approveOne(item))
.then((approved) => {
dispatch(removeFromList(approved));
dispatch(refreshDashboardPageItem(approved));
});
} else {
dispatch(removeFromList(item));
}
approveOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
export const unpublishAll = (publishOne) => (dispatch, getState) => {
const toEditList = getState().dashboard.selected;
const pagedContent = getState().dashboard.paged.content;
const toUnpublishItems = pagedContent.filter((pagedItem) => toEditList.indexOf(pagedItem.uuid) !== -1);
/**
* Unpublish all items that are in dashboard.toEditList
* @param unPublishOne: (uuid: string) => Promise<any> action to unpublish one item
*/
export const unpublishAll = (unPublishOne) => (dispatch, getState) => {
const toUnpublishItems = getState().dashboard.selected;
toUnpublishItems.map((item) => {
if (item.state !== PublishState.DRAFT) {
dispatch(publishOne(item))
.then((unpublished) => {
dispatch(removeFromList(unpublished));
dispatch(refreshDashboardPageItem(unpublished));
});
} else {
dispatch(removeFromList(item));
}
unPublishOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
/**
* Delete all items that are in dashboard.toEditList
* @param deleteOne: (uuid: string) => Promise<any> action to delete one item
*/
export const deleteAll = (deleteOne) => (dispatch, getState) => {
const toEditList = getState().dashboard.selected;
const pagedContent = getState().dashboard.paged.content;
const toDeleteItems = pagedContent.filter((pagedItem) => toEditList.indexOf(pagedItem.uuid) !== -1);
const toDeleteItems = getState().dashboard.selected;
toDeleteItems.map((item) => {
dispatch(deleteOne(item))
.then((deleted) => {
dispatch(removeFromList(deleted));
dispatch(removeDashboardPageItem(deleted));
});
deleteOne(item);
dispatch(removeFromList(item));
});
dispatch(unselectAll());
};
export const listMyDatasets = (page?, results?, sortBy?, filter?: string | IDatasetFilter, order?) => {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.listMyDatasets(token, page, results, sortBy, filter, order)
.then((paged) => {
dispatch(onPageChange());
dispatch(receiveAndPushDashboardPage(paged));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
};
export const listMyDescriptors = (page?, results?, sortBy?, filter?: string | IDescriptorFilter, order?) => {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DescriptorService.listMyDescriptors(token, page, results, sortBy, filter, order)
.then((paged) => {
dereferenceReferences(paged.content, 'owner', (o) => new Partner(o));
dispatch(receiveAndPushDashboardPage(paged));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
};
export const listMyDescriptorLists = (page?, results?, sortBy?, filter?: string | IDescriptorListFilter, order?) => {
return (dispatch, getState) => {
log('Loading my descriptor lists');
const token = getState().login.access_token;
return DescriptorListService.listMyDescriptorLists(token, page, results, sortBy, filter, order)
// receive the current descriptor list
.then((descriptorLists) => {
dispatch(receiveAndPushDashboardPage(descriptorLists));
return dispatch(addFilterCode(descriptorLists.filterCode, descriptorLists.filter));
}).catch((error) => {
log(`Error loading my descriptor lists`, error);
});
};
};
export const promiseListMyDatasets = (page?, results?, sortBy?, filter?, order?) => (dispatch, getState) => {
const token = getState().login.access_token;
return DescriptorService.listMyDescriptors(token, page, results, sortBy, filter, order)
.then((paged) => {
dereferenceReferences(paged.content, 'owner', (o) => new Partner(o));
dispatch(receiveAndPushDashboardPage(paged));
return {...paged, content: []};
})
.catch((error) => {
log('Error', error);
return error;
});
};
export const promiseListMyDescriptors = (page?, results?, sortBy?, filter?, order?) => (dispatch, getState) => {
const token = getState().login.access_token;
return DescriptorService.listMyDescriptors(token, page, results, sortBy, filter, order)
.then((paged) => {
dereferenceReferences(paged.content, 'owner', (o) => new Partner(o));
dispatch(receiveAndPushDashboardPage(paged));
return {...paged, content: []};
})
.catch((error) => {
log('Error', error);
return error;
});
};
export const promiseListMyDescriptorLists = (page?, results?, sortBy?, filter?, order?) => (dispatch, getState) => {
const token = getState().login.access_token;
return DescriptorListService.listDescriptorLists(token, page, results, sortBy, filter, order)
.then((paged) => {
dispatch(loadDescriptorListTitles(paged.content));
return {...paged, content: []};
}).catch((error) => {
log('Error', error);
return error;
});
};
import { push } from 'react-router-redux';
import { Page, PublishState } from 'model/common.model';
import { Dataset, IDatasetFilter, AccessionIdentifier } from 'model/dataset.model';
import { Creator } from 'model/creator.model';
import { Location } from 'model/location.model';
import { RepositoryFile } from 'model/repositoryFile.model';
import { DatasetService } from 'service/DatasetService';
import { CreatorService } from 'service/CreatorService';
import { LocationService } from 'service/LocationService';
import { RepositoryFileService } from 'service/RepositoryFileService';
import { log } from 'utilities/debug';
import {CREATE_DATASET, RECEIVE_DATASET, RECEIVE_DATASET_PAGE, ADD_CREATOR_TO_DATASET, REMOVE_CREATOR_FROM_DATASET, UPDATE_DATASET_CREATOR, ADD_LOCATION, RECEIVE_LOCATION, REMOVE_LOCATION, REMOVE_DATASET} from 'constants/datasets';
import {addFilterCode} from 'actions/filterCode';
import steps from 'ui/pages/dataset/dataset-stepper/steps';
import { navigateTo } from 'actions/navigation';
import * as _ from 'lodash';
const receiveDataset = (dataset: Dataset) => ({
type: RECEIVE_DATASET, payload: dataset,
});
const removeDataset = (dataset: Dataset) => ({
type: REMOVE_DATASET, payload: dataset,
});
const receiveDatasetPage = (paged: Page<Dataset>, page, results, sortBy, filter: IDatasetFilter, order) => ({
type: RECEIVE_DATASET_PAGE,
payload: { paged, query: { page, results, sortBy, filter, order } },
});
function showDataset(uuid: string) {
return (dispatch) => {
dispatch(push(`/datasets/${uuid}`));
};
}
function editDataset(uuid: string) {
return (dispatch) => {
dispatch(push(`/datasets/${uuid}/edit`));
};
}
export const promiseListMyDatasets = (page?, results?, sortBy?, filter?, order?) => (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.listMyDatasets(token, page, results, sortBy, filter, order)
.catch((error) => {
log('Error', error);
return error;
});
};
function listMyDatasets(page?, results?, sortBy?, filter?: string | IDatasetFilter, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.listMyDatasets(token, page, results, sortBy, filter, order)
.then((paged) => {
dispatch(receiveDatasetPage(paged, page, results, sortBy, paged.filter, order));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
}
export const promiselistDatasets = (page?, results?, sortBy?, filter?, order?) => (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.listDatasets(token, page, results, sortBy, filter, order)
.catch((error) => {
log('Error', error);
return error;
});
};
function listDatasetsRequest(page?, results?, sortBy?, filter?, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.listDatasets(token, page, results, sortBy, filter, order)
.then((paged) => {
dispatch(receiveDatasetPage(paged, page, results, sortBy, filter, order));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
}
function listDatasetsByCodeRequest(page?, results?, sortBy?, filterCode?, order?) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.listDatasetsByCode(token, page, results, sortBy, filterCode, order)
.then((paged) => {
dispatch(receiveDatasetPage(paged, page, results, sortBy, paged.filter, order));
return dispatch(addFilterCode(paged.filterCode, paged.filter));
})
.catch((error) => {
log('Error', error);
});
};
}
function loadDataset(uuid: string) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.getDataset(token, uuid)
.then((dataset) => {
dispatch(receiveDataset(dataset));
})
.catch((error) => {
log('Error', error);
});
};
}
// Create a new descriptor
const createDataset = () => (dispatch) => {
dispatch({ type: CREATE_DATASET });
return dispatch(push(`/datasets/edit`));
};
const saveDataset = (dataset: Dataset) => (dispatch, getState) => {
const needToRedirect: boolean = !(dataset.version && dataset.uuid);
if (_.isEqual({...getState().datasets.currentDataset}, {...dataset})) {
return;
}
// remove normalized data here
const data = new Dataset({
repositoryFiles: [],
creators: [],
locations: [],
descriptors: [],
...dataset,
});
const token = getState().login.access_token;
return DatasetService.saveDataset(token, data)
.then((saved) => {
dispatch(receiveDataset(saved));
if (needToRedirect) {
dispatch(gotoNextStep(saved));
}
}).catch((error) => {
log('Save error', error);
});
};
function gotoNextStep(dataset: Dataset) {
return (dispatch, getState) => {
const link = window.location.pathname.split('/').pop();
const stepId = steps.find((e) => e.link.endsWith(link)).id;
const path = steps.find((e) => e.id === (stepId + 1)).link;
dispatch(navigateTo(`/datasets/${dataset.uuid}/${path}`));
};
}
function approveDataset(dataset: Dataset) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.updatePublishState(token, dataset, PublishState.PUBLISHED)
.then((saved) => {
dispatch(receiveDataset(saved));
}).catch((error) => {
log('Error', error);
});
};
}
function rejectDataset(dataset: Dataset, needToRedirect: boolean = true) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.updatePublishState(token, dataset, PublishState.DRAFT)
.then((saved) => {
dispatch(receiveDataset(saved));
if (needToRedirect) {
dispatch(navigateTo(`/datasets/${saved.uuid}/edit`));
}
}).catch((error) => {
log('Error', error);
});
};
}
function publishDataset(dataset: Dataset, needToRedirect: boolean = false) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.updatePublishState(token, dataset, PublishState.REVIEWING)
.then((saved) => {
dispatch(receiveDataset(saved));
if (needToRedirect) {
dispatch(showDataset(saved.uuid));
}
}).catch((error) => {
log('Error', error);
});
};
}
function publishDatasetPromise(dataset: Dataset) {
return (dispatch, getState) => {
return DatasetService.updatePublishState(getState().login.access_token, dataset, PublishState.REVIEWING)
.catch((error) => {
log('Error', error);
});
};
}
function unpublishDatasetPromise(dataset: Dataset) {
return (dispatch, getState) => {
return DatasetService.updatePublishState(getState().login.access_token, dataset, PublishState.DRAFT)
.catch((error) => {
log('Error', error);
});
};
}
function approveDatasetPromise(dataset: Dataset) {
return (dispatch, getState) => {
return DatasetService.updatePublishState(getState().login.access_token, dataset, PublishState.PUBLISHED)
.catch((error) => {
log('Error', error);
});
};
}
function deleteDatasetPromise(dataset: Dataset) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.deleteDataset(token, dataset)
.then((deleted) => {
dispatch(removeDataset(deleted));
return deleted;
})
.catch((error) => {
log('Delete error', error);
});
};
}
function deleteDataset(dataset: Dataset) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.deleteDataset(token, dataset)
.then((deleted) => {
dispatch(removeDataset(deleted));
// dispatch(showDataset(saved.uuid));
}).catch((error) => {
log('Delete error', error);
});
};
}
function updateDatasetAccessionIdentifiers(dataset: Dataset, accessionIdentifiers: AccessionIdentifier[]) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.updateAccessionIdentifiers(token, dataset, accessionIdentifiers)
.then((saved) => {
dispatch(receiveDataset(saved));
}).catch((error) => {
log('Publish error', error);
});
};
}
function addDescriptorsToDataset(dataset: Dataset, descriptorUuids: string[]) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.addDescriptorsToDataset(token, dataset, descriptorUuids)
.then((saved) => {
dispatch(receiveDataset(saved));
}).catch((error) => {
log('Add error', error);
});
};
}
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 removeDescriptorsFromDataset(dataset: Dataset, descriptorUuids: string[]) {
return (dispatch, getState) => {
const token = getState().login.access_token;
return DatasetService.removeDescriptorsFromDataset(token, dataset, descriptorUuids)
.then((saved) => {
dispatch(receiveDataset(saved));
}).catch((error) => {
log('Delete error', error);
});