X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3408a97206bfac10d8ecc6e30cf0b28d66697b9b..4cad4c0d882111b0eb5576005108a62ff30b143d:/src/store/projects/project-create-actions.ts diff --git a/src/store/projects/project-create-actions.ts b/src/store/projects/project-create-actions.ts index f4883eb9..a303b551 100644 --- a/src/store/projects/project-create-actions.ts +++ b/src/store/projects/project-create-actions.ts @@ -3,8 +3,9 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from "redux"; -import { reset, startSubmit, stopSubmit, initialize, FormErrors, formValueSelector, change, arrayPush } from 'redux-form'; +import { reset, startSubmit, stopSubmit, initialize, FormErrors, formValueSelector, change } from 'redux-form'; import { RootState } from '~/store/store'; +import { getUserUuid } from "~/common/getuser"; import { dialogActions } from "~/store/dialog/dialog-actions"; import { getCommonResourceServiceError, CommonResourceServiceError } from '~/services/common-service/common-resource-service'; import { ProjectResource } from '~/models/project'; @@ -16,11 +17,16 @@ export interface ProjectCreateFormDialogData { ownerUuid: string; name: string; description: string; - properties: any; + properties: ProjectProperties; +} + +export interface ProjectProperties { + [key: string]: string; } export const PROJECT_CREATE_FORM_NAME = 'projectCreateFormName'; export const PROJECT_CREATE_PROPERTIES_FORM_NAME = 'projectCreatePropertiesFormName'; +export const PROJECT_CREATE_FORM_SELECTOR = formValueSelector(PROJECT_CREATE_FORM_NAME); export const isProjectOrRunProcessRoute = ({ router }: RootState) => { const pathname = router.location ? router.location.pathname : ''; @@ -33,7 +39,7 @@ export const isItemNotInProject = (properties: any) => { if (properties.breadcrumbs) { return Boolean(properties.breadcrumbs[0].label !== 'Projects'); } else { - return ; + return; } }; @@ -42,7 +48,8 @@ export const openProjectCreateDialog = (ownerUuid: string) => const router = getState(); const properties = getState().properties; if (isItemNotInProject(properties) || !isProjectOrRunProcessRoute(router)) { - const userUuid = getState().auth.user!.uuid; + const userUuid = getUserUuid(getState()); + if (!userUuid) { return; } dispatch(initialize(PROJECT_CREATE_FORM_NAME, { userUuid })); } else { dispatch(initialize(PROJECT_CREATE_FORM_NAME, { ownerUuid })); @@ -60,7 +67,7 @@ export const createProject = (project: Partial) => return newProject; } catch (e) { const error = getCommonResourceServiceError(e); - if (error === CommonResourceServiceError.UNIQUE_VIOLATION) { + if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) { dispatch(stopSubmit(PROJECT_CREATE_FORM_NAME, { name: 'Project with the same name already exists.' } as FormErrors)); } return undefined; @@ -69,16 +76,14 @@ export const createProject = (project: Partial) => export const addPropertyToCreateProjectForm = (data: ResourcePropertiesFormData) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const selector = formValueSelector(PROJECT_CREATE_FORM_NAME); - const properties = selector(getState(), 'properties') || {}; + const properties = { ...PROJECT_CREATE_FORM_SELECTOR(getState(), 'properties') }; properties[data.key] = data.value; - dispatch(change(PROJECT_CREATE_FORM_NAME, 'properties', {...properties } )); + dispatch(change(PROJECT_CREATE_FORM_NAME, 'properties', properties)); }; export const removePropertyFromCreateProjectForm = (key: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const selector = formValueSelector(PROJECT_CREATE_FORM_NAME); - const properties = selector(getState(), 'properties'); + const properties = { ...PROJECT_CREATE_FORM_SELECTOR(getState(), 'properties') }; delete properties[key]; - dispatch(change(PROJECT_CREATE_FORM_NAME, 'properties', { ...properties } )); - }; \ No newline at end of file + dispatch(change(PROJECT_CREATE_FORM_NAME, 'properties', properties)); + };