X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/0d01430667a2a8d19e02f0b7d10bb5ba4ff9e00e..188fed64a7cfe68460f64a874dba3fd280d5d561:/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 92994d65..d226048b 100644 --- a/src/store/projects/project-create-actions.ts +++ b/src/store/projects/project-create-actions.ts @@ -3,13 +3,13 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from "redux"; -import { reset, startSubmit, stopSubmit, initialize } from 'redux-form'; +import { reset, startSubmit, stopSubmit, initialize, FormErrors } 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 { ProjectResource } from '~/models/project'; import { ServiceRepository } from '~/services/services'; -import { matchProjectRoute } from '~/routes/routes'; +import { matchProjectRoute, matchRunProcessRoute } from '~/routes/routes'; export interface ProjectCreateFormDialogData { ownerUuid: string; @@ -19,37 +19,31 @@ export interface ProjectCreateFormDialogData { export const PROJECT_CREATE_FORM_NAME = 'projectCreateFormName'; -export const isProjectRoute = ({ router }: RootState) => { +export const isProjectOrRunProcessRoute = ({ router }: RootState) => { const pathname = router.location ? router.location.pathname : ''; - const match = matchProjectRoute(pathname); - return !!match; + const matchProject = matchProjectRoute(pathname); + const matchRunProcess = matchRunProcessRoute(pathname); + return Boolean(matchProject || matchRunProcess); }; -interface Properties { - breadcrumbs: Array<{ uuid: string, label: string }>; -} - -export const isItemNotInProject = (properties: Properties) => { +export const isItemNotInProject = (properties: any) => { if (properties.breadcrumbs) { - const isItemSharedWithMe = properties.breadcrumbs[0].label !== 'Projects'; - return isItemSharedWithMe; + return Boolean(properties.breadcrumbs[0].label !== 'Projects'); } else { - return false; + return ; } }; -export const isNotProjectItem = () => { - return isItemNotInProject || !isProjectRoute; -}; - export const openProjectCreateDialog = (ownerUuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - if (isNotProjectItem) { + const router = getState(); + const properties = getState().properties; + if (isItemNotInProject(properties) || !isProjectOrRunProcessRoute(router)) { const userUuid = getState().auth.user!.uuid; dispatch(initialize(PROJECT_CREATE_FORM_NAME, { userUuid })); } else { dispatch(initialize(PROJECT_CREATE_FORM_NAME, { ownerUuid })); - } + } dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_CREATE_FORM_NAME, data: {} })); }; @@ -64,7 +58,7 @@ export const createProject = (project: Partial) => } catch (e) { const error = getCommonResourceServiceError(e); if (error === CommonResourceServiceError.UNIQUE_VIOLATION) { - dispatch(stopSubmit(PROJECT_CREATE_FORM_NAME, { name: 'Project with the same name already exists.' })); + dispatch(stopSubmit(PROJECT_CREATE_FORM_NAME, { name: 'Project with the same name already exists.' } as FormErrors)); } return undefined; }