From 6521d10377432141aaec5408dbfba2952bf0656e Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Fri, 17 Dec 2021 18:46:12 -0300 Subject: [PATCH] 18219: Unifies collection/project create/update properties handling actions. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../collections/collection-create-actions.ts | 31 +++++-------------- .../collections/collection-update-actions.ts | 23 -------------- src/store/projects/project-create-actions.ts | 31 +++++-------------- src/store/projects/project-update-actions.ts | 23 -------------- src/store/resources/resources-actions.ts | 22 +++++++++++++ .../create-collection-properties-form.tsx | 5 +-- .../create-collection-properties-list.tsx | 7 +++-- .../update-collection-properties-form.tsx | 4 +-- .../update-collection-properties-list.tsx | 5 +-- .../create-project-properties-form.tsx | 5 +-- .../create-project-properties-list.tsx | 9 ++++-- .../update-project-properties-form.tsx | 5 +-- .../update-project-properties-list.tsx | 5 +-- 13 files changed, 66 insertions(+), 109 deletions(-) diff --git a/src/store/collections/collection-create-actions.ts b/src/store/collections/collection-create-actions.ts index 22202b15..17fecc1e 100644 --- a/src/store/collections/collection-create-actions.ts +++ b/src/store/collections/collection-create-actions.ts @@ -3,7 +3,14 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from "redux"; -import { reset, startSubmit, stopSubmit, initialize, FormErrors, change, formValueSelector } from 'redux-form'; +import { + reset, + startSubmit, + stopSubmit, + initialize, + FormErrors, + formValueSelector +} from 'redux-form'; import { RootState } from 'store/store'; import { getUserUuid } from "common/getuser"; import { dialogActions } from "store/dialog/dialog-actions"; @@ -15,8 +22,6 @@ import { progressIndicatorActions } from "store/progress-indicator/progress-indi import { isProjectOrRunProcessRoute } from 'store/projects/project-create-actions'; import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions'; import { CollectionResource } from "models/collection"; -import { ResourcePropertiesFormData } from "views-components/resource-properties-form/resource-properties-form"; -import { addProperty, deleteProperty } from "lib/resource-properties"; export interface CollectionCreateFormDialogData { ownerUuid: string; @@ -78,23 +83,3 @@ export const createCollection = (data: CollectionCreateFormDialogData) => dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_CREATE_FORM_NAME)); } }; - -export const addPropertyToCreateCollectionForm = (data: ResourcePropertiesFormData) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...COLLECTION_CREATE_FORM_SELECTOR(getState(), 'properties') }; - const key = data.keyID || data.key; - const value = data.valueID || data.value; - dispatch(change( - COLLECTION_CREATE_FORM_NAME, - 'properties', - addProperty(properties, key, value))); - }; - -export const removePropertyFromCreateCollectionForm = (key: string, value: string) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...COLLECTION_CREATE_FORM_SELECTOR(getState(), 'properties') }; - dispatch(change( - COLLECTION_CREATE_FORM_NAME, - 'properties', - deleteProperty(properties, key, value))); - }; diff --git a/src/store/collections/collection-update-actions.ts b/src/store/collections/collection-update-actions.ts index 0096bc48..2caaf88a 100644 --- a/src/store/collections/collection-update-actions.ts +++ b/src/store/collections/collection-update-actions.ts @@ -4,7 +4,6 @@ import { Dispatch } from "redux"; import { - change, FormErrors, formValueSelector, initialize, @@ -23,8 +22,6 @@ import { updateResources } from "../resources/resources-actions"; import { loadDetailsPanel } from "../details-panel/details-panel-action"; import { getResource } from "store/resources/resources"; import { CollectionProperties } from "./collection-create-actions"; -import { ResourcePropertiesFormData } from "views-components/resource-properties-form/resource-properties-form"; -import { addProperty, deleteProperty } from "lib/resource-properties"; export interface CollectionUpdateFormDialogData { uuid: string; @@ -83,23 +80,3 @@ export const updateCollection = (collection: CollectionUpdateFormDialogData) => } ); }; - -export const addPropertyToUpdateCollectionForm = (data: ResourcePropertiesFormData) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...COLLECTION_UPDATE_FORM_SELECTOR(getState(), 'properties') }; - const key = data.keyID || data.key; - const value = data.valueID || data.value; - dispatch(change( - COLLECTION_UPDATE_FORM_NAME, - 'properties', - addProperty(properties, key, value))); - }; - -export const removePropertyFromUpdateCollectionForm = (key: string, value: string) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...COLLECTION_UPDATE_FORM_SELECTOR(getState(), 'properties') }; - dispatch(change( - COLLECTION_UPDATE_FORM_NAME, - 'properties', - deleteProperty(properties, key, value))); - }; diff --git a/src/store/projects/project-create-actions.ts b/src/store/projects/project-create-actions.ts index 352759fa..c7d17c51 100644 --- a/src/store/projects/project-create-actions.ts +++ b/src/store/projects/project-create-actions.ts @@ -3,7 +3,14 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from "redux"; -import { reset, startSubmit, stopSubmit, initialize, FormErrors, formValueSelector, change } from 'redux-form'; +import { + reset, + startSubmit, + stopSubmit, + initialize, + FormErrors, + formValueSelector +} from 'redux-form'; import { RootState } from 'store/store'; import { getUserUuid } from "common/getuser"; import { dialogActions } from "store/dialog/dialog-actions"; @@ -11,9 +18,7 @@ import { getCommonResourceServiceError, CommonResourceServiceError } from 'servi import { ProjectResource } from 'models/project'; import { ServiceRepository } from 'services/services'; import { matchProjectRoute, matchRunProcessRoute } from 'routes/routes'; -import { ResourcePropertiesFormData } from 'views-components/resource-properties-form/resource-properties-form'; import { RouterState } from "react-router-redux"; -import { addProperty, deleteProperty } from "lib/resource-properties"; export interface ProjectCreateFormDialogData { ownerUuid: string; @@ -66,23 +71,3 @@ export const createProject = (project: Partial) => return undefined; } }; - -export const addPropertyToCreateProjectForm = (data: ResourcePropertiesFormData) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...PROJECT_CREATE_FORM_SELECTOR(getState(), 'properties') }; - const key = data.keyID || data.key; - const value = data.valueID || data.value; - dispatch(change( - PROJECT_CREATE_FORM_NAME, - 'properties', - addProperty(properties, key, value))); - }; - -export const removePropertyFromCreateProjectForm = (key: string, value: string) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...PROJECT_CREATE_FORM_SELECTOR(getState(), 'properties') }; - dispatch(change( - PROJECT_CREATE_FORM_NAME, - 'properties', - deleteProperty(properties, key, value))); - }; diff --git a/src/store/projects/project-update-actions.ts b/src/store/projects/project-update-actions.ts index e5fc34d8..36f66ccf 100644 --- a/src/store/projects/project-update-actions.ts +++ b/src/store/projects/project-update-actions.ts @@ -4,7 +4,6 @@ import { Dispatch } from "redux"; import { - change, FormErrors, formValueSelector, initialize, @@ -22,8 +21,6 @@ import { ServiceRepository } from "services/services"; import { projectPanelActions } from 'store/project-panel/project-panel-action'; import { GroupClass } from "models/group"; import { Participant } from "views-components/sharing-dialog/participant-select"; -import { ResourcePropertiesFormData } from "views-components/resource-properties-form/resource-properties-form"; -import { addProperty, deleteProperty } from "lib/resource-properties"; import { ProjectProperties } from "./project-create-actions"; export interface ProjectUpdateFormDialogData { @@ -68,23 +65,3 @@ export const updateProject = (project: ProjectUpdateFormDialogData) => return ; } }; - -export const addPropertyToUpdateProjectForm = (data: ResourcePropertiesFormData) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...PROJECT_UPDATE_FORM_SELECTOR(getState(), 'properties') }; - const key = data.keyID || data.key; - const value = data.valueID || data.value; - dispatch(change( - PROJECT_UPDATE_FORM_NAME, - 'properties', - addProperty(properties, key, value))); - }; - -export const removePropertyFromUpdateProjectForm = (key: string, value: string) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const properties = { ...PROJECT_UPDATE_FORM_SELECTOR(getState(), 'properties') }; - dispatch(change( - PROJECT_UPDATE_FORM_NAME, - 'properties', - deleteProperty(properties, key, value))); - }; diff --git a/src/store/resources/resources-actions.ts b/src/store/resources/resources-actions.ts index 8e6d16f9..1d1355a8 100644 --- a/src/store/resources/resources-actions.ts +++ b/src/store/resources/resources-actions.ts @@ -12,6 +12,8 @@ import { addProperty, deleteProperty } from 'lib/resource-properties'; import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions'; import { getResource } from './resources'; import { TagProperty } from 'models/tag'; +import { change, formValueSelector } from 'redux-form'; +import { ResourcePropertiesFormData } from 'views-components/resource-properties-form/resource-properties-form'; export const resourcesActions = unionize({ SET_RESOURCES: ofType(), @@ -93,3 +95,23 @@ export const createResourceProperty = (data: TagProperty) => dispatch(snackbarActions.OPEN_SNACKBAR({ message: errorMsg, hideDuration: 2000, kind: SnackbarKind.ERROR })); } }; + +export const addPropertyToResourceForm = (data: ResourcePropertiesFormData, formName: string) => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const properties = { ...formValueSelector(formName)(getState(), 'properties') }; + const key = data.keyID || data.key; + const value = data.valueID || data.value; + dispatch(change( + formName, + 'properties', + addProperty(properties, key, value))); + }; + +export const removePropertyFromResourceForm = (key: string, value: string, formName: string) => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const properties = { ...formValueSelector(formName)(getState(), 'properties') }; + dispatch(change( + formName, + 'properties', + deleteProperty(properties, key, value))); + }; diff --git a/src/views-components/collection-properties/create-collection-properties-form.tsx b/src/views-components/collection-properties/create-collection-properties-form.tsx index 8e3f8eb8..ab389ddc 100644 --- a/src/views-components/collection-properties/create-collection-properties-form.tsx +++ b/src/views-components/collection-properties/create-collection-properties-form.tsx @@ -6,12 +6,13 @@ import { reduxForm, reset } from 'redux-form'; import { withStyles } from '@material-ui/core'; import { COLLECTION_CREATE_PROPERTIES_FORM_NAME, - addPropertyToCreateCollectionForm + COLLECTION_CREATE_FORM_NAME } from 'store/collections/collection-create-actions'; import { ResourcePropertiesForm, ResourcePropertiesFormData } from 'views-components/resource-properties-form/resource-properties-form'; +import { addPropertyToResourceForm } from 'store/resources/resources-actions'; const Form = withStyles( ({ spacing }) => ( @@ -26,7 +27,7 @@ const Form = withStyles( export const CreateCollectionPropertiesForm = reduxForm({ form: COLLECTION_CREATE_PROPERTIES_FORM_NAME, onSubmit: (data, dispatch) => { - dispatch(addPropertyToCreateCollectionForm(data)); + dispatch(addPropertyToResourceForm(data, COLLECTION_CREATE_FORM_NAME)); dispatch(reset(COLLECTION_CREATE_PROPERTIES_FORM_NAME)); } })(Form); \ No newline at end of file diff --git a/src/views-components/collection-properties/create-collection-properties-list.tsx b/src/views-components/collection-properties/create-collection-properties-list.tsx index 9784b55e..b6e02cb6 100644 --- a/src/views-components/collection-properties/create-collection-properties-list.tsx +++ b/src/views-components/collection-properties/create-collection-properties-list.tsx @@ -12,12 +12,13 @@ import { } from '@material-ui/core'; import { RootState } from 'store/store'; import { - removePropertyFromCreateCollectionForm, COLLECTION_CREATE_FORM_SELECTOR, - CollectionProperties + CollectionProperties, + COLLECTION_CREATE_FORM_NAME } from 'store/collections/collection-create-actions'; import { ArvadosTheme } from 'common/custom-theme'; import { getPropertyChip } from '../resource-properties-form/property-chip'; +import { removePropertyFromResourceForm } from 'store/resources/resources-actions'; type CssRules = 'tag'; @@ -42,7 +43,7 @@ const mapStateToProps = (state: RootState): CreateCollectionPropertiesListDataPr }; const mapDispatchToProps = (dispatch: Dispatch): CreateCollectionPropertiesListActionProps => ({ - handleDelete: (key: string, value: string) => dispatch(removePropertyFromCreateCollectionForm(key, value)) + handleDelete: (key: string, value: string) => dispatch(removePropertyFromResourceForm(key, value, COLLECTION_CREATE_FORM_NAME)) }); type CreateCollectionPropertiesListProps = CreateCollectionPropertiesListDataProps & diff --git a/src/views-components/collection-properties/update-collection-properties-form.tsx b/src/views-components/collection-properties/update-collection-properties-form.tsx index dc00de30..13a29ad4 100644 --- a/src/views-components/collection-properties/update-collection-properties-form.tsx +++ b/src/views-components/collection-properties/update-collection-properties-form.tsx @@ -5,13 +5,13 @@ import { reduxForm, reset } from 'redux-form'; import { withStyles } from '@material-ui/core'; import { - addPropertyToUpdateCollectionForm, COLLECTION_UPDATE_PROPERTIES_FORM_NAME } from 'store/collections/collection-update-actions'; import { ResourcePropertiesForm, ResourcePropertiesFormData } from 'views-components/resource-properties-form/resource-properties-form'; +import { addPropertyToResourceForm } from 'store/resources/resources-actions'; const Form = withStyles( ({ spacing }) => ( @@ -26,7 +26,7 @@ const Form = withStyles( export const UpdateCollectionPropertiesForm = reduxForm({ form: COLLECTION_UPDATE_PROPERTIES_FORM_NAME, onSubmit: (data, dispatch) => { - dispatch(addPropertyToUpdateCollectionForm(data)); + dispatch(addPropertyToResourceForm(data, COLLECTION_UPDATE_PROPERTIES_FORM_NAME)); dispatch(reset(COLLECTION_UPDATE_PROPERTIES_FORM_NAME)); } })(Form); \ No newline at end of file diff --git a/src/views-components/collection-properties/update-collection-properties-list.tsx b/src/views-components/collection-properties/update-collection-properties-list.tsx index 26cf5e70..792786f2 100644 --- a/src/views-components/collection-properties/update-collection-properties-list.tsx +++ b/src/views-components/collection-properties/update-collection-properties-list.tsx @@ -12,12 +12,13 @@ import { } from '@material-ui/core'; import { RootState } from 'store/store'; import { - removePropertyFromUpdateCollectionForm, COLLECTION_UPDATE_FORM_SELECTOR, + COLLECTION_UPDATE_FORM_NAME, } from 'store/collections/collection-update-actions'; import { ArvadosTheme } from 'common/custom-theme'; import { getPropertyChip } from '../resource-properties-form/property-chip'; import { CollectionProperties } from 'store/collections/collection-create-actions'; +import { removePropertyFromResourceForm } from 'store/resources/resources-actions'; type CssRules = 'tag'; @@ -42,7 +43,7 @@ const mapStateToProps = (state: RootState): UpdateCollectionPropertiesListDataPr }; const mapDispatchToProps = (dispatch: Dispatch): UpdateCollectionPropertiesListActionProps => ({ - handleDelete: (key: string, value: string) => dispatch(removePropertyFromUpdateCollectionForm(key, value)) + handleDelete: (key: string, value: string) => dispatch(removePropertyFromResourceForm(key, value, COLLECTION_UPDATE_FORM_NAME)) }); type UpdateCollectionPropertiesListProps = UpdateCollectionPropertiesListDataProps & diff --git a/src/views-components/project-properties/create-project-properties-form.tsx b/src/views-components/project-properties/create-project-properties-form.tsx index c49d738a..aa9965b5 100644 --- a/src/views-components/project-properties/create-project-properties-form.tsx +++ b/src/views-components/project-properties/create-project-properties-form.tsx @@ -6,12 +6,13 @@ import { reduxForm, reset } from 'redux-form'; import { withStyles } from '@material-ui/core'; import { PROJECT_CREATE_PROPERTIES_FORM_NAME, - addPropertyToCreateProjectForm + PROJECT_CREATE_FORM_NAME } from 'store/projects/project-create-actions'; import { ResourcePropertiesForm, ResourcePropertiesFormData } from 'views-components/resource-properties-form/resource-properties-form'; +import { addPropertyToResourceForm } from 'store/resources/resources-actions'; const Form = withStyles( ({ spacing }) => ( @@ -26,7 +27,7 @@ const Form = withStyles( export const CreateProjectPropertiesForm = reduxForm({ form: PROJECT_CREATE_PROPERTIES_FORM_NAME, onSubmit: (data, dispatch) => { - dispatch(addPropertyToCreateProjectForm(data)); + dispatch(addPropertyToResourceForm(data, PROJECT_CREATE_FORM_NAME)); dispatch(reset(PROJECT_CREATE_PROPERTIES_FORM_NAME)); } })(Form); \ No newline at end of file diff --git a/src/views-components/project-properties/create-project-properties-list.tsx b/src/views-components/project-properties/create-project-properties-list.tsx index 8a61dcf7..ac7dc6fd 100644 --- a/src/views-components/project-properties/create-project-properties-list.tsx +++ b/src/views-components/project-properties/create-project-properties-list.tsx @@ -11,9 +11,14 @@ import { WithStyles, } from '@material-ui/core'; import { RootState } from 'store/store'; -import { removePropertyFromCreateProjectForm, PROJECT_CREATE_FORM_SELECTOR, ProjectProperties } from 'store/projects/project-create-actions'; +import { + PROJECT_CREATE_FORM_SELECTOR, + ProjectProperties, + PROJECT_CREATE_FORM_NAME +} from 'store/projects/project-create-actions'; import { ArvadosTheme } from 'common/custom-theme'; import { getPropertyChip } from '../resource-properties-form/property-chip'; +import { removePropertyFromResourceForm } from 'store/resources/resources-actions'; type CssRules = 'tag'; @@ -38,7 +43,7 @@ const mapStateToProps = (state: RootState): CreateProjectPropertiesListDataProps }; const mapDispatchToProps = (dispatch: Dispatch): CreateProjectPropertiesListActionProps => ({ - handleDelete: (key: string, value: string) => dispatch(removePropertyFromCreateProjectForm(key, value)) + handleDelete: (key: string, value: string) => dispatch(removePropertyFromResourceForm(key, value, PROJECT_CREATE_FORM_NAME)) }); type CreateProjectPropertiesListProps = CreateProjectPropertiesListDataProps & diff --git a/src/views-components/project-properties/update-project-properties-form.tsx b/src/views-components/project-properties/update-project-properties-form.tsx index e6e78e34..e6151229 100644 --- a/src/views-components/project-properties/update-project-properties-form.tsx +++ b/src/views-components/project-properties/update-project-properties-form.tsx @@ -6,12 +6,13 @@ import { reduxForm, reset } from 'redux-form'; import { withStyles } from '@material-ui/core'; import { PROJECT_UPDATE_PROPERTIES_FORM_NAME, - addPropertyToUpdateProjectForm + PROJECT_UPDATE_FORM_NAME } from 'store/projects/project-update-actions'; import { ResourcePropertiesForm, ResourcePropertiesFormData } from 'views-components/resource-properties-form/resource-properties-form'; +import { addPropertyToResourceForm } from 'store/resources/resources-actions'; const Form = withStyles( ({ spacing }) => ( @@ -26,7 +27,7 @@ const Form = withStyles( export const UpdateProjectPropertiesForm = reduxForm({ form: PROJECT_UPDATE_PROPERTIES_FORM_NAME, onSubmit: (data, dispatch) => { - dispatch(addPropertyToUpdateProjectForm(data)); + dispatch(addPropertyToResourceForm(data, PROJECT_UPDATE_FORM_NAME)); dispatch(reset(PROJECT_UPDATE_PROPERTIES_FORM_NAME)); } })(Form); \ No newline at end of file diff --git a/src/views-components/project-properties/update-project-properties-list.tsx b/src/views-components/project-properties/update-project-properties-list.tsx index 5572af73..5ac22b92 100644 --- a/src/views-components/project-properties/update-project-properties-list.tsx +++ b/src/views-components/project-properties/update-project-properties-list.tsx @@ -12,12 +12,13 @@ import { } from '@material-ui/core'; import { RootState } from 'store/store'; import { - removePropertyFromUpdateProjectForm, PROJECT_UPDATE_FORM_SELECTOR, + PROJECT_UPDATE_FORM_NAME, } from 'store/projects/project-update-actions'; import { ArvadosTheme } from 'common/custom-theme'; import { getPropertyChip } from '../resource-properties-form/property-chip'; import { ProjectProperties } from 'store/projects/project-create-actions'; +import { removePropertyFromResourceForm } from 'store/resources/resources-actions'; type CssRules = 'tag'; @@ -42,7 +43,7 @@ const mapStateToProps = (state: RootState): UpdateProjectPropertiesListDataProps }; const mapDispatchToProps = (dispatch: Dispatch): UpdateProjectPropertiesListActionProps => ({ - handleDelete: (key: string, value: string) => dispatch(removePropertyFromUpdateProjectForm(key, value)) + handleDelete: (key: string, value: string) => dispatch(removePropertyFromResourceForm(key, value, PROJECT_UPDATE_FORM_NAME)) }); type UpdateProjectPropertiesListProps = UpdateProjectPropertiesListDataProps & -- 2.30.2