X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/d4aa5357707c184f7e450465befeb693379ec5a9..HEAD:/src/store/projects/project-update-actions.ts diff --git a/src/store/projects/project-update-actions.ts b/src/store/projects/project-update-actions.ts index 34ea42f5..81249031 100644 --- a/src/store/projects/project-update-actions.ts +++ b/src/store/projects/project-update-actions.ts @@ -3,43 +3,78 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from "redux"; -import { initialize, startSubmit, stopSubmit } from 'redux-form'; -import { RootState } from "~/store/store"; -import { dialogActions } from "~/store/dialog/dialog-actions"; -import { getCommonResourceServiceError, CommonResourceServiceError } from "~/services/common-service/common-resource-service"; -import { ServiceRepository } from "~/services/services"; -import { ProjectResource } from '~/models/project'; -import { ContextMenuResource } from "~/store/context-menu/context-menu-actions"; -import { getResource } from '~/store/resources/resources'; +import { FormErrors, formValueSelector, initialize, reset, startSubmit, stopSubmit } from "redux-form"; +import { RootState } from "store/store"; +import { dialogActions } from "store/dialog/dialog-actions"; +import { getCommonResourceServiceError, CommonResourceServiceError } from "services/common-service/common-resource-service"; +import { ServiceRepository } from "services/services"; +import { projectPanelActions } from "store/project-panel/project-panel-action-bind"; +import { GroupClass } from "models/group"; +import { Participant } from "views-components/sharing-dialog/participant-select"; +import { ProjectProperties } from "./project-create-actions"; +import { getResource } from "store/resources/resources"; +import { ProjectResource } from "models/project"; +import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions"; export interface ProjectUpdateFormDialogData { uuid: string; name: string; - description: string; + users?: Participant[]; + description?: string; + properties?: ProjectProperties; } -export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName'; +export const PROJECT_UPDATE_FORM_NAME = "projectUpdateFormName"; +export const PROJECT_UPDATE_PROPERTIES_FORM_NAME = "projectUpdatePropertiesFormName"; +export const PROJECT_UPDATE_FORM_SELECTOR = formValueSelector(PROJECT_UPDATE_FORM_NAME); -export const openProjectUpdateDialog = (resource: ContextMenuResource) => - (dispatch: Dispatch, getState: () => RootState) => { - const project = getResource(resource.uuid)(getState().resources); - dispatch(initialize(PROJECT_UPDATE_FORM_NAME, project)); - dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_UPDATE_FORM_NAME, data: {} })); - }; +export const openProjectUpdateDialog = (resource: ProjectUpdateFormDialogData) => (dispatch: Dispatch, getState: () => RootState) => { + // Get complete project resource from store to handle consumers passing in partial resources + const project = getResource(resource.uuid)(getState().resources); + dispatch(initialize(PROJECT_UPDATE_FORM_NAME, project)); + dispatch( + dialogActions.OPEN_DIALOG({ + id: PROJECT_UPDATE_FORM_NAME, + data: { + sourcePanel: GroupClass.PROJECT, + }, + }) + ); +}; -export const updateProject = (project: Partial) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const uuid = project.uuid || ''; +export const updateProject = + (project: ProjectUpdateFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const uuid = project.uuid || ""; dispatch(startSubmit(PROJECT_UPDATE_FORM_NAME)); try { - const updatedProject = await services.projectService.update(uuid, project); + const updatedProject = await services.projectService.update( + uuid, + { + name: project.name, + description: project.description, + properties: project.properties, + }, + false + ); + dispatch(projectPanelActions.REQUEST_ITEMS()); + dispatch(reset(PROJECT_UPDATE_FORM_NAME)); dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME })); return updatedProject; } catch (e) { const error = getCommonResourceServiceError(e); - if (error === CommonResourceServiceError.UNIQUE_VIOLATION) { - dispatch(stopSubmit(PROJECT_UPDATE_FORM_NAME, { name: 'Project with the same name already exists.' })); + if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) { + dispatch(stopSubmit(PROJECT_UPDATE_FORM_NAME, { name: "Project with the same name already exists." } as FormErrors)); + } else { + dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME })); + const errMsg = e.errors ? e.errors.join("") : "There was an error while updating the project"; + dispatch( + snackbarActions.OPEN_SNACKBAR({ + message: errMsg, + hideDuration: 2000, + kind: SnackbarKind.ERROR, + }) + ); } - return ; + return; } };