Commit ae5d5e5d authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Merge branch '680-api-v2-in-dashboard-for-actions-on-multiple-objects' into 'master'

API v2 in dashboard/datasets for actions on multiple objects

Closes #680

See merge request genesys-pgr/genesys-ui!665
parents 37a17e2d 157009c3
......@@ -341,7 +341,11 @@
"record_plural": "Records",
"selectInstitute": "Select institute to view KPI data",
"noChartDataAvailable": "No kpi data available",
"noInstitutesAvailable": "No institutes available"
"noInstitutesAvailable": "No institutes available",
"updatedItemsWithError": "{{successCount, number}} item were updated and {{errorCount, number}} failed with error",
"updatedItemsWithError_plural": "{{successCount, number}} items were updated and {{errorCount, number}} failed with error",
"updatedItems": "{{successCount, number}} item were updated",
"updatedItems_plural": "{{successCount, number}} items were updated"
}
},
"f": {
......
......@@ -9,8 +9,9 @@ import Dataset from 'model/catalog/Dataset';
import Descriptor from 'model/catalog/Descriptor';
import DescriptorList from 'model/catalog/DescriptorList';
import Subset from 'model/subset/Subset';
// import {showSnackbar} from 'actions/snackbar';
import OpResponse from 'model/OpResponse';
type DashboardItem = Dataset | Descriptor | DescriptorList | Subset;
export const setEditMode = (payload: boolean) => (dispatch) => {
dispatch({ type: RECEIVE_IS_EDIT_MODE, payload });
......@@ -20,17 +21,17 @@ export const selectAll = (tab: string) => (dispatch, getState) => {
let payload;
switch (tab) {
case 'descriptorlists':
payload = getState().descriptorList.dashboard.paged.data.content.map((item) => item.uuid);
payload = getState().descriptorList.dashboard.paged.data.content;
break;
case 'descriptors':
payload = getState().descriptors.dashboard.paged.data.content.map((item) => item.uuid);
payload = getState().descriptors.dashboard.paged.data.content;
break;
case 'subsets':
payload = getState().subsets.dashboard.paged.data.content.map((item) => item.uuid);
payload = getState().subsets.dashboard.paged.data.content;
break;
case 'datasets':
default:
payload = getState().datasets.dashboard.paged.data.content.map((item) => item.uuid);
payload = getState().datasets.dashboard.paged.data.content;
}
return dispatch({
......@@ -43,11 +44,11 @@ export const unselectAll = () => ({
type: UNSELECT_ALL,
});
const addToList = (payload: Dataset | Descriptor | DescriptorList | Subset) => (dispatch) => {
dispatch({ type: ADD_TO_EDIT_LIST, payload: payload.uuid });
const addToList = (item: DashboardItem) => (dispatch) => {
dispatch({ type: ADD_TO_EDIT_LIST, payload: item });
};
const removeFromList = (payload: Dataset | Descriptor | DescriptorList | Subset) => (dispatch) => {
const removeFromList = (payload: DashboardItem) => (dispatch) => {
dispatch({ type: REMOVE_FROM_EDIT_LIST, payload: payload.uuid });
};
......@@ -55,120 +56,37 @@ export const onPageChange = () => (dispatch) => {
dispatch(setEditMode(false));
};
export const addToEditList = (item: Dataset | Descriptor | DescriptorList | Subset) => (dispatch, getState) => {
export const addToEditList = (item: DashboardItem) => (dispatch, getState) => {
const list = getState().dashboard.selected;
if (!list.includes(item.uuid)) {
if (!list.some((listItem) => listItem.uuid === item.uuid)) {
dispatch(addToList(item));
}
};
export const removeFromEditList = (item: Dataset | Descriptor | DescriptorList | Subset) => (dispatch, getState) => {
export const removeFromEditList = (item: DashboardItem) => (dispatch, getState) => {
const list = getState().dashboard.selected;
if (list.includes(item.uuid)) {
if (list.some((listItem) => listItem.uuid === item.uuid)) {
dispatch(removeFromList(item));
}
};
/**
* Publish all items that are in dashboard.toEditList
* @param publishOne: (uuid: string) => Promise<any> action to publish one item
*/
export const publishAll = (publishOne) => async (dispatch, getState) => {
const toPublishItems = getState().dashboard.selected;
let error;
for (const item of toPublishItems) {
try {
await publishOne(item);
dispatch(removeFromList(item));
} catch (e) {
console.log('Dashboard publish all error: ', e);
error = e;
// Error while publishing item
}
}
if (error) {
dispatch(showSnackbar('common.snackbar.bulkRequestFail'));
}
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) => async (dispatch, getState) => {
const toApproveItems = getState().dashboard.selected;
let error;
for (const item of toApproveItems) {
try {
await approveOne(item);
dispatch(removeFromList(item));
} catch (e) {
console.log('Dashboard approve all error: ', e);
error = e;
// Error while approving item
}
}
if (error) {
dispatch(showSnackbar('common.snackbar.bulkRequestFail'));
}
dispatch(unselectAll());
};
/**
* Unpublish all items that are in dashboard.toEditList
* @param unPublishOne: (uuid: string) => Promise<any> action to unpublish one item
*/
export const unpublishAll = (unPublishOne) => async (dispatch, getState) => {
const toUnpublishItems = getState().dashboard.selected;
let error;
for (const item of toUnpublishItems) {
try {
await unPublishOne(item);
dispatch(removeFromList(item));
} catch (e) {
error = e;
console.log('Dashboard unpublish all error: ', e);
// Error while unpublishing item
export const handleAll = (action) => (dispatch, getState) => {
action(getState().dashboard.selected).then((responses: Array<OpResponse<DashboardItem>>) => {
// console.log('responses on dashboard', responses);
const result = responses.reduce((result, element) => {
if (element.success && !element.error) {
return { successCount: (result.successCount + 1), errorCount: result.errorCount };
} else if (!element.success && element.error) {
return { successCount: result.successCount, errorCount: (result.errorCount + 1) };
}
}, { successCount: 0, errorCount: 0 });
if (result.errorCount > 0) {
dispatch(showSnackbar('dashboard.p.dashboard.updatedItemsWithError', { successCount: result.successCount, errorCount: result.errorCount, count: result.successCount }));
} else if (result.successCount > 0 && result.errorCount === 0) {
dispatch(showSnackbar('dashboard.p.dashboard.updatedItems', { successCount: result.successCount, count: result.successCount }));
}
}
if (error) {
dispatch(showSnackbar('common.snackbar.bulkRequestFail'));
}
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) => async (dispatch, getState) => {
const toDeleteItems = getState().dashboard.selected;
let error;
for (const item of toDeleteItems) {
try {
await deleteOne(item);
dispatch(removeFromList(item));
} catch (e) {
error = e;
console.log('Dashboard delete all error: ', e);
// Error while deleting item
}
}
if (error) {
dispatch(showSnackbar('common.snackbar.bulkRequestFail'));
}
dispatch(unselectAll());
dispatch(unselectAll());
});
};
......@@ -7,15 +7,15 @@ import {createApiCaller} from 'actions/ApiCall';
import {showSnackbar} from 'actions/snackbar';
// Constants
import {
DASHBOARD_REMOVE_DATASET,
DASHBOARD_REMOVE_DATASETS,
CREATE_DATASET,
DASHBOARD_APPEND_DATASET_PAGE,
DASHBOARD_RECEIVE_DATASET,
DASHBOARD_APPEND_ACCESSIONS_PAGE,
DASHBOARD_RECEIVE_UPDATED_DATASETS,
} from 'datasets/constants';
// Models
import Dataset from 'model/catalog/Dataset';
import { PublishState } from 'model/common.model';
import Page, {IPageRequest} from 'model/Page';
import FilteredPage from 'model/FilteredPage';
import { AccessionRef } from 'model/accession/AccessionRef';
......@@ -36,10 +36,10 @@ const apiListAccessions = createApiCaller(DatasetService.listAccessions, DASHBOA
const apiCreateNewVersion = createApiCaller(DatasetService.createNewVersion, DASHBOARD_RECEIVE_DATASET);
export const apiGetDataset = createApiCaller(DatasetService.getDataset, DASHBOARD_RECEIVE_DATASET);
export const apiRejectDataset = createApiCaller(DatasetService.rejectDataset, DASHBOARD_RECEIVE_DATASET);
export const apiReviewDataset = createApiCaller(DatasetService.reviewDataset, DASHBOARD_RECEIVE_DATASET);
export const apiApproveDataset = createApiCaller(DatasetService.approveDataset, DASHBOARD_RECEIVE_DATASET);
export const apiDeleteDataset = createApiCaller(DatasetService.deleteDataset, DASHBOARD_REMOVE_DATASET);
export const apiRejectDatasets = createApiCaller(DatasetService.rejectDatasets, DASHBOARD_RECEIVE_UPDATED_DATASETS);
export const apiReviewDatasets = createApiCaller(DatasetService.reviewDatasets, DASHBOARD_RECEIVE_UPDATED_DATASETS);
export const apiApproveDatasets = createApiCaller(DatasetService.approveDatasets, DASHBOARD_RECEIVE_UPDATED_DATASETS);
export const apiDeleteDatasets = createApiCaller(DatasetService.deleteDatasets, DASHBOARD_REMOVE_DATASETS);
const loadMoreDatasets = (paged?: FilteredPage<Dataset>) => (dispatch, getState) => {
......@@ -77,10 +77,6 @@ export const updateRoute = (paged: FilteredPage<Dataset>) => (dispatch) => {
};
export { loadMoreDatasets };
const getOneFromStateByUUID = (uuid: string, state): Dataset => {
return state.datasets.dashboard.paged && state.datasets.dashboard.paged.data.content.find((dataset) => dataset.uuid === uuid);
};
export const loadDataset = (uuid: string) => (dispatch) => {
return dispatch(apiGetDataset(uuid));
};
......@@ -90,36 +86,10 @@ export const createNewVersion = (uuid) => (dispatch) => {
.then((newVersion) => dispatch(navigateTo(`/dashboard/datasets/${newVersion.uuid}/edit`)));
};
function publishDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = getOneFromStateByUUID(datasetUuid, getState());
return dataset.state === PublishState.DRAFT &&
dispatch(apiReviewDataset(dataset.uuid, dataset.version));
};
}
function unpublishDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = getOneFromStateByUUID(datasetUuid, getState());
return dataset.state !== PublishState.DRAFT &&
dispatch(apiRejectDataset(dataset.uuid, dataset.version));
};
}
function approveDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = getOneFromStateByUUID(datasetUuid, getState());
return dataset.state === PublishState.REVIEWING &&
dispatch(apiApproveDataset(dataset.uuid, dataset.version));
};
}
function deleteDataset(datasetUuid: string) {
return (dispatch, getState) => {
const dataset = getOneFromStateByUUID(datasetUuid, getState());
return dispatch(apiDeleteDataset(dataset.uuid, dataset.version));
};
}
const publishDatasets = (datasets: Dataset[]) => (dispatch) => dispatch(apiReviewDatasets(datasets));
const unpublishDatasets = (datasets: Dataset[]) => (dispatch) => dispatch(apiRejectDatasets(datasets));
const approveDatasets = (datasets: Dataset[]) => (dispatch) => dispatch(apiApproveDatasets(datasets));
const deleteDatasets = (datasets: Dataset[]) => (dispatch) => dispatch(apiDeleteDatasets(datasets));
// Dashboard action section exports
export { publishDataset, approveDataset, unpublishDataset, deleteDataset, loadMoreAccessions };
export { publishDatasets, approveDatasets, unpublishDatasets, deleteDatasets, loadMoreAccessions };
......@@ -3,10 +3,10 @@ import * as _ from 'lodash';
// Actions
import { navigateTo } from 'actions/navigation';
import {
apiApproveDataset,
apiDeleteDataset,
apiRejectDataset,
apiReviewDataset,
apiApproveDatasets,
apiDeleteDatasets,
apiRejectDatasets,
apiReviewDatasets,
loadMoreAccessions,
} from 'datasets/actions/dashboard';
import {createApiCaller, createPureApiCaller} from 'actions/ApiCall';
......@@ -75,27 +75,27 @@ const apiGetCountry = createPureApiCaller(GeoService.getCountry);
// Review step
function rejectDataset(dataset: Dataset) {
return (dispatch, getState) => {
return dispatch(apiRejectDataset(dataset.uuid, dataset.version));
return (dispatch) => {
return dispatch(apiRejectDatasets([dataset]));
};
}
function approveDataset(dataset: Dataset) {
return (dispatch, getState) => {
return dispatch(apiApproveDataset(dataset.uuid, dataset.version));
return (dispatch) => {
return dispatch(apiApproveDatasets([dataset]));
};
}
function publishDataset(dataset: Dataset) {
return (dispatch) => {
dispatch(clearDataset());
return dispatch(apiReviewDataset(dataset.uuid, dataset.version));
return dispatch(apiReviewDatasets([dataset]));
};
}
function deleteDataset(dataset: Dataset) {
return (dispatch, getState) => {
return dispatch(apiDeleteDataset(dataset.uuid, dataset.version));
return (dispatch) => {
return dispatch(apiDeleteDatasets([dataset]));
};
}
......
......@@ -3,7 +3,7 @@ import {addFilterCode, filterCodeToUrl} from 'actions/filterCode';
import navigateTo from 'actions/navigation';
import { showSnackbar } from 'actions/snackbar';
import {createApiCaller, createPureApiCaller} from 'actions/ApiCall';
import { apiDeleteDataset, apiRejectDataset as apiRejectDatasetDashboard } from 'datasets/actions/dashboard';
import { apiDeleteDatasets, apiRejectDatasets } from 'datasets/actions/dashboard';
// Constants
import {
RECEIVE_DATASET,
......@@ -20,6 +20,7 @@ import Page from 'model/Page';
import FilteredPage, { IPageRequest } from 'model/FilteredPage';
import { AccessionRef } from 'model/accession/AccessionRef';
import DatasetOverview from 'model/catalog/DatasetOverview';
import OpResponse from 'model/OpResponse';
// Service
import DatasetService from 'service/catalog/DatasetService';
// Util
......@@ -108,9 +109,15 @@ export const rejectDataset = (dataset: Dataset) => (dispatch) => {
};
export const editDataset = (dataset: Dataset) => (dispatch) => {
return dispatch(apiRejectDatasetDashboard(dataset.uuid, dataset.version))
.then((saved) => {
dispatch(navigateTo(`/dashboard/datasets/${saved.uuid}/edit`));
return dispatch(apiRejectDatasets([dataset]))
.then((responses: Array<OpResponse<Dataset>>) => {
if (responses[0]) {
if (responses[0].success) {
dispatch(navigateTo(`/dashboard/datasets/${responses[0].success.uuid}/edit`));
} else {
console.log('Dataset failed to reject. Error:', responses[0].error.message);
}
}
});
};
......@@ -119,7 +126,7 @@ export const publishDataset = (dataset: Dataset) => (dispatch) => {
};
export const deleteDataset = (dataset: Dataset) => (dispatch) => {
return dispatch(apiDeleteDataset(dataset.uuid, dataset.version))
return dispatch(apiDeleteDatasets([dataset]))
.then(() => {
dispatch(navigateTo('/dashboard/datasets'));
});
......
......@@ -11,12 +11,12 @@ export const CLEAR_DATASET = 'App/CLEAR_DATASET';
// dashboard
export const DASHBOARD_RECEIVE_DATASET = 'App/DASHBOARD_RECEIVE_DATASET';
export const DASHBOARD_REMOVE_DATASET = 'dataset/dashboard/REMOVE_DATASET';
export const DASHBOARD_RECEIVE_DATASET_PAGE = 'dataset/dashboard/RECEIVE_DATASET_PAGE';
export const DASHBOARD_APPEND_DATASET_PAGE = 'dataset/dashboard/APPEND_DATASET_PAGE';
export const DASHBOARD_RECEIVE_ACCESSIONS_PAGE = 'dataset/dashboard/RECEIVE_ACCESSIONS_PAGE';
export const DASHBOARD_APPEND_ACCESSIONS_PAGE = 'dataset/dashboard/APPEND_ACCESSIONS_PAGE';
export const DASHBOARD_RECEIVE_UPDATED_DATASETS = 'dataset/dashboard/DASHBOARD_RECEIVE_UPDATED_DATASETS';
export const DASHBOARD_REMOVE_DATASETS = 'dataset/dashboard/DASHBOARD_REMOVE_DATASETS';
// creators const params
export const RECEIVE_CREATOR = 'App/RECEIVE_CREATOR';
......
......@@ -3,8 +3,8 @@ import { log } from 'utilities/debug';
import * as _ from 'lodash';
import { CREATE_DATASET, ADD_CREATOR_TO_DATASET, REMOVE_CREATOR_FROM_DATASET, UPDATE_DATASET_CREATOR, ADD_LOCATION,
RECEIVE_LOCATION, REMOVE_LOCATION, DASHBOARD_REMOVE_DATASET, DASHBOARD_RECEIVE_DATASET,
DASHBOARD_APPEND_DATASET_PAGE , DASHBOARD_APPEND_ACCESSIONS_PAGE,
RECEIVE_LOCATION, REMOVE_LOCATION, DASHBOARD_RECEIVE_DATASET, DASHBOARD_APPEND_DATASET_PAGE,
DASHBOARD_APPEND_ACCESSIONS_PAGE, DASHBOARD_RECEIVE_UPDATED_DATASETS, DASHBOARD_REMOVE_DATASETS,
} from 'datasets/constants';
import Dataset from 'model/catalog/Dataset';
......@@ -33,6 +33,70 @@ const datasetsDashboard = (state = INITIAL_STATE, action: { type?: string, paylo
dataset: { $set: ApiCall.success(dataset) },
});
}
case DASHBOARD_RECEIVE_UPDATED_DATASETS: {
const { apiCall } = action.payload;
if (apiCall && apiCall.data) {
if (state.paged && state.paged.data && state.paged.data.content) {
const updatedDatasets = apiCall.data.reduce((acum, response) => {
if (response.success) {
acum.push(response.success);
} else {
console.log('Dataset failed to update. Error:', response.error.message);
}
return acum;
}, []);
const updateContent = (content) => {
return content.map((dataset) => {
const updated = updatedDatasets.find((upd) => upd.uuid === dataset.uuid);
return updated ? updated : dataset;
});
};
return update(state, {
paged: {
data: {
content: { $apply: updateContent },
},
},
});
}
}
return state;
}
case DASHBOARD_REMOVE_DATASETS: {
const { apiCall } = action.payload;
if (apiCall && apiCall.data) {
if (state.paged && state.paged.data && state.paged.data.content) {
const deletedDatasets = apiCall.data.reduce((acum, response) => {
if (response.success) {
acum.push(response.success);
} else {
console.log('Dataset failed to update. Error:', response.error.message);
}
return acum;
}, []);
const updateContent = (content) => {
return content.filter((dataset) => {
return !deletedDatasets.some((deleted) => deleted.uuid === dataset.uuid);
});
};
return update(state, {
paged: {
data: {
content: { $apply: updateContent },
},
},
});
}
}
return state;
}
case DASHBOARD_RECEIVE_DATASET: {
const {apiCall} = action.payload;
......@@ -83,23 +147,6 @@ const datasetsDashboard = (state = INITIAL_STATE, action: { type?: string, paylo
});
}
case DASHBOARD_REMOVE_DATASET: {
const {apiCall} = action.payload;
if (state.paged) {
const removeIndex = state.paged && state.paged.data && apiCall.data ? _.findIndex(state.paged.data.content, (item) => item.uuid === apiCall.data.uuid) : -1;
return removeIndex === -1 ? state
: update(state, {
paged: {
data: {
content: {$splice: [[removeIndex, 1]]},
number: {$set: state.paged.data.number - 1},
totalElements: {$set: state.paged.data.totalElements - 1},
},
},
});
}
return state;
}
case DASHBOARD_APPEND_DATASET_PAGE: {
const {apiCall: {loading, error, timestamp, data}} = action.payload;
return update(state, {
......@@ -193,6 +240,6 @@ const datasetsDashboard = (state = INITIAL_STATE, action: { type?: string, paylo
default:
return state;
}
}
};
export default datasetsDashboard;
......@@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import BaseMyDataPage, { parentActionCreators, parentMapStateToProps } from 'ui/catalog/dashboard/MyDataPage';
import { approveDataset, deleteDataset, loadMoreDatasets, applyFilters, unpublishDataset, publishDataset, createNewVersion } from 'datasets/actions/dashboard';
import { approveDatasets, deleteDatasets, loadMoreDatasets, applyFilters, unpublishDatasets, publishDatasets, createNewVersion } from 'datasets/actions/dashboard';
import Dataset from 'model/catalog/Dataset';
import { DatasetLink } from 'ui/genesys/Links';
import { PublishState } from 'model/common.model';
......@@ -43,10 +43,10 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadMoreData: loadMoreDatasets,
applyFilters,
deleteOne: deleteDataset,
publishOne: publishDataset,
approveOne: approveDataset,
unpublishOne: unpublishDataset,
deleteItems: deleteDatasets,
publish: publishDatasets,
approve: approveDatasets,
unpublish: unpublishDatasets,
createNewVersion,
...parentActionCreators,
}, dispatch);
......
......@@ -6,13 +6,14 @@ import { loadDescriptorListTitles } from 'actions/decoder';
import {addFilterCode, filterCodeToUrl} from 'actions/filterCode';
import navigateTo from 'actions/navigation';
import {showSnackbar} from 'actions/snackbar';
import { clearDescriptorList } from 'descriptorlists/actions/public';
// Constants
import { CREATE_DESCRIPTORLIST, DASHBOARD_APPEND_DESCRIPTORLISTS, DASHBOARD_RECEIVE_DESCRIPTORLIST, DASHBOARD_REMOVE_DESCRIPTORLIST } from 'descriptors/constants';
import {
CREATE_DESCRIPTORLIST, DASHBOARD_APPEND_DESCRIPTORLISTS,
DASHBOARD_REMOVE_DESCRIPTORLISTS, DASHBOARD_RECEIVE_UPDATED_DESCRIPTORLISTS,
} from 'descriptors/constants';
// Model
import { PublishState } from 'model/common.model';
import Page, {IPageRequest} from 'model/Page';
import DescriptorList from 'model/catalog/DescriptorList';
import FilteredPage from 'model/FilteredPage';
......@@ -27,10 +28,10 @@ import { log } from 'utilities/debug';
// Wrapped API Calls
const apiMyDescriptorLists = createApiCaller(DescriptorListService.myDescriptorLists, DASHBOARD_APPEND_DESCRIPTORLISTS);
export const apiDeleteDescriptorList = createApiCaller(DescriptorListService.deleteDescriptorList, DASHBOARD_REMOVE_DESCRIPTORLIST);
export const apiReviewDescriptorList = createApiCaller(DescriptorListService.reviewDescriptorList, DASHBOARD_RECEIVE_DESCRIPTORLIST);
export const apiRejectDescriptorList = createApiCaller(DescriptorListService.rejectDescriptorList, DASHBOARD_RECEIVE_DESCRIPTORLIST);
export const apiApproveDescriptorList = createApiCaller(DescriptorListService.approveDescriptorList, DASHBOARD_RECEIVE_DESCRIPTORLIST);
export const apiDeleteDescriptorLists = createApiCaller(DescriptorListService.deleteDescriptorLists, DASHBOARD_REMOVE_DESCRIPTORLISTS);
export const apiReviewDescriptorLists = createApiCaller(DescriptorListService.reviewDescriptorLists, DASHBOARD_RECEIVE_UPDATED_DESCRIPTORLISTS);
export const apiRejectDescriptorLists = createApiCaller(DescriptorListService.rejectDescriptorLists, DASHBOARD_RECEIVE_UPDATED_DESCRIPTORLISTS);
export const apiApproveDescriptorLists = createApiCaller(DescriptorListService.approveDescriptorLists, DASHBOARD_RECEIVE_UPDATED_DESCRIPTORLISTS);
export const loadMoreDescriptorLists = (page?: FilteredPage<DescriptorList>) => (dispatch, getState) => {
......@@ -72,35 +73,18 @@ export const createDescriptorList = () => (dispatch) => {
return dispatch(push(`/dashboard/descriptorlists/edit`));
};
const getOneFromStateByUUID = (uuid: string, state): DescriptorList => {
return state.descriptorList.dashboard.paged && state.descriptorList.dashboard.paged.data.content.find((descriptorList) => descriptorList.uuid === uuid);
};
export const deleteDescriptorList = (descriptorListUUID: string) => (dispatch, getState) => {
const descriptorList = getOneFromStateByUUID(descriptorListUUID, getState());
return dispatch(apiDeleteDescriptorList(descriptorList.uuid, descriptorList.version))
.then(() => dispatch(clearDescriptorList()));
export const deleteDescriptorLists = (descriptorLists: DescriptorList[]) => (dispatch) => {
return dispatch(apiDeleteDescriptorLists(descriptorLists));
};
export const publishDescriptorList = (descriptorListUUID: string) => (dispatch, getState) => {
const descriptorList = getOneFromStateByUUID(descriptorListUUID, getState());
return descriptorList.state === PublishState.DRAFT &&
dispatch(apiReviewDescriptorList(descriptorList.uuid, descriptorList.version))
.then(() => dispatch(clearDescriptorList()));
export const publishDescriptorLists = (descriptorLists: DescriptorList[]) => (dispatch) => {
return dispatch(apiReviewDescriptorLists(descriptorLists));
};
export const unpublishDescriptorList = (descriptorListUUID: string) => (dispatch, getState) => {
const descriptorList = getOneFromStateByUUID(descriptorListUUID, getState());
return descriptorList.state !== PublishState.DRAFT &&
dispatch(apiRejectDescriptorList(descriptorList.uuid, descriptorList.version))
.then(() => dispatch(clearDescriptorList()));
export const unpublishDescriptorLists = (descriptorLists: DescriptorList[]) => (dispatch) => {
return dispatch(apiRejectDescriptorLists(descriptorLists));
};
export const approveDescriptorList = (descriptorListUUID: string) => (dispatch, getState) => {
const descriptorList = getOneFromStateByUUID(descriptorListUUID, getState());
return descriptorList.state === PublishState.REVIEWING &&
dispatch(apiApproveDescriptorList(descriptorList.uuid, descriptorList.version))
.then(() => dispatch(clearDescriptorList()));
export const approveDescriptorLists = (descriptorLists: DescriptorList[]) => (dispatch) => {
return dispatch(apiApproveDescriptorLists(descriptorLists));
};
......@@ -22,10 +22,10 @@ import { log } from 'utilities/debug';
// UI
import steps from 'descriptorlists/ui/dashboard/descriptorlist-stepper/steps';
import {
apiApproveDescriptorList,
apiDeleteDescriptorList,
apiRejectDescriptorList,
apiReviewDescriptorList,
apiApproveDescriptorLists,
apiDeleteDescriptorLists,
apiRejectDescriptorLists,
apiReviewDescriptorLists,
} from './dashboard';
......@@ -53,26 +53,26 @@ export const createDescriptorList = () => (dispatch) => {
};
// Review step
const deleteDescriptorList = (descriptorList: DescriptorList) => (dispatch, getState) => {
return dispatch(apiDeleteDescriptorList(descriptorList.uuid, descriptorList.version));
const deleteDescriptorList = (descriptorList: DescriptorList) => (dispatch) => {
return dispatch(apiDeleteDescriptorLists([descriptorList]));
};
function rejectDescriptorList(descriptorList: DescriptorList) {
return (dispatch) => {
return dispatch(apiRejectDescriptorList(descriptorList.uuid, descriptorList.version));
return dispatch(apiRejectDescriptorLists([descriptorList]));
};
}
function publishDescriptorList(descriptorList: DescriptorList) {
return (dispatch) => {
dispatch(clearDescriptorList());
return dispatch(apiReviewDescriptorList(descriptorList.uuid, descriptorList.version));
return dispatch(apiReviewDescriptorLists([descriptorList]));
};
}
function approveDescriptorList(descriptorList: DescriptorList) {
return (dispatch, getState) => {
return dispatch(apiApproveDescriptorList(descriptorList.uuid, descriptorList.version));
return (dispatch) => {
return dispatch(apiApproveDescriptorLists([descriptorList]));
};
}
......
......@@ -4,7 +4,7 @@ import { loadDescriptorListTitles } from 'actions/decoder';
import navigateTo from 'actions/navigation';
import { showSnackbar } from 'actions/snackbar';
import {createApiCaller, createPureApiCaller} from 'actions/ApiCall';
import { apiDeleteDescriptorList, apiRejectDescriptorList as apiRejectDescriptorListDashboard } from './dashboard';
import { apiDeleteDescriptorLists, apiRejectDescriptorLists } from './dashboard';
// Constants
import {
......@@ -145,14 +145,20 @@ export const rejectDescriptorList = (descriptorList: DescriptorList) => (dispatc