1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { connect } from "react-redux";
6 import { Dispatch } from "redux";
7 import { SubmissionError } from "redux-form";
8 import { RootState } from "../../store/store";
9 import { snackbarActions } from "../../store/snackbar/snackbar-actions";
10 import { collectionUpdaterActions, updateCollection } from "../../store/collections/updater/collection-updater-action";
11 import { dataExplorerActions } from "../../store/data-explorer/data-explorer-action";
12 import { PROJECT_PANEL_ID } from "../../views/project-panel/project-panel";
13 import { DialogCollectionUpdate } from "../dialog-update/dialog-collection-update";
15 const mapStateToProps = (state: RootState) => ({
16 open: state.collections.updater.opened
19 const mapDispatchToProps = (dispatch: Dispatch) => ({
21 dispatch(collectionUpdaterActions.CLOSE_COLLECTION_UPDATER());
23 onSubmit: (data: { name: string, description: string }) => {
24 return dispatch<any>(editCollection(data))
27 throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Collection with this name already exists." : "" });
33 const editCollection = (data: { name: string, description: string }) =>
34 (dispatch: Dispatch) => {
35 return dispatch<any>(updateCollection(data)).then(() => {
36 dispatch(snackbarActions.OPEN_SNACKBAR({
37 message: "Collection has been successfully updated.",
40 dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID }));
44 export const UpdateCollectionDialog = connect(mapStateToProps, mapDispatchToProps)(DialogCollectionUpdate);