From 070f84137b216212da7eac806710df5d0c479bba Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Wed, 5 Feb 2020 12:23:14 -0300 Subject: [PATCH] 16116: Unifies collections and projects update handling with process. Fields should be passed explicitly to the api server to avoid unwanted (and illegal) fields to eventually infiltrate on the api request call. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/store/collections/collection-update-actions.ts | 9 ++++----- src/store/projects/project-update-actions.ts | 14 +++++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/store/collections/collection-update-actions.ts b/src/store/collections/collection-update-actions.ts index 5b176bea..f8fac398 100644 --- a/src/store/collections/collection-update-actions.ts +++ b/src/store/collections/collection-update-actions.ts @@ -10,30 +10,29 @@ import { dialogActions } from "~/store/dialog/dialog-actions"; import { getCommonResourceServiceError, CommonResourceServiceError } from "~/services/common-service/common-resource-service"; import { ServiceRepository } from "~/services/services"; import { CollectionResource } from '~/models/collection'; -import { ContextMenuResource } from "~/store/context-menu/context-menu-actions"; import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions"; export interface CollectionUpdateFormDialogData { uuid: string; name: string; - description: string; + description?: string; } export const COLLECTION_UPDATE_FORM_NAME = 'collectionUpdateFormName'; -export const openCollectionUpdateDialog = (resource: ContextMenuResource) => +export const openCollectionUpdateDialog = (resource: CollectionUpdateFormDialogData) => (dispatch: Dispatch) => { dispatch(initialize(COLLECTION_UPDATE_FORM_NAME, resource)); dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_UPDATE_FORM_NAME, data: {} })); }; -export const updateCollection = (collection: Partial) => +export const updateCollection = (collection: CollectionUpdateFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const uuid = collection.uuid || ''; dispatch(startSubmit(COLLECTION_UPDATE_FORM_NAME)); dispatch(progressIndicatorActions.START_WORKING(COLLECTION_UPDATE_FORM_NAME)); try { - const updatedCollection = await services.collectionService.update(uuid, collection); + const updatedCollection = await services.collectionService.update(uuid, { name: collection.name, description: collection.description }); dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: updatedCollection as CollectionResource })); dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_UPDATE_FORM_NAME })); dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPDATE_FORM_NAME)); diff --git a/src/store/projects/project-update-actions.ts b/src/store/projects/project-update-actions.ts index 2449b9ce..2cb02788 100644 --- a/src/store/projects/project-update-actions.ts +++ b/src/store/projects/project-update-actions.ts @@ -8,32 +8,28 @@ 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 { projectPanelActions } from '~/store/project-panel/project-panel-action'; export interface ProjectUpdateFormDialogData { uuid: string; name: string; - description: string; + description?: string; } export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName'; -export const openProjectUpdateDialog = (resource: ContextMenuResource) => +export const openProjectUpdateDialog = (resource: ProjectUpdateFormDialogData) => (dispatch: Dispatch, getState: () => RootState) => { - const project = getResource(resource.uuid)(getState().resources); - dispatch(initialize(PROJECT_UPDATE_FORM_NAME, project)); + dispatch(initialize(PROJECT_UPDATE_FORM_NAME, resource)); dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_UPDATE_FORM_NAME, data: {} })); }; -export const updateProject = (project: Partial) => +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 }); dispatch(projectPanelActions.REQUEST_ITEMS()); dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME })); return updatedProject; -- 2.30.2