18219: Unifies code for showing the list of properties on rsc forms.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 17 Dec 2021 22:31:03 +0000 (19:31 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 17 Dec 2021 22:41:19 +0000 (19:41 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/views-components/collection-properties/create-collection-properties-list.tsx [deleted file]
src/views-components/collection-properties/update-collection-properties-list.tsx [deleted file]
src/views-components/dialog-create/dialog-collection-create.tsx
src/views-components/dialog-create/dialog-project-create.tsx
src/views-components/dialog-update/dialog-collection-update.tsx
src/views-components/dialog-update/dialog-project-update.tsx
src/views-components/project-properties/update-project-properties-list.tsx [deleted file]
src/views-components/resource-properties/resource-properties-list.tsx [moved from src/views-components/project-properties/create-project-properties-list.tsx with 58% similarity]

diff --git a/src/views-components/collection-properties/create-collection-properties-list.tsx b/src/views-components/collection-properties/create-collection-properties-list.tsx
deleted file mode 100644 (file)
index b6e02cb..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import React from 'react';
-import { connect } from 'react-redux';
-import { Dispatch } from 'redux';
-import {
-    withStyles,
-    StyleRulesCallback,
-    WithStyles,
-} from '@material-ui/core';
-import { RootState } from 'store/store';
-import {
-    COLLECTION_CREATE_FORM_SELECTOR,
-    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';
-
-const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    tag: {
-        marginRight: theme.spacing.unit,
-        marginBottom: theme.spacing.unit
-    }
-});
-
-interface CreateCollectionPropertiesListDataProps {
-    properties: CollectionProperties;
-}
-
-interface CreateCollectionPropertiesListActionProps {
-    handleDelete: (key: string, value: string) => void;
-}
-
-const mapStateToProps = (state: RootState): CreateCollectionPropertiesListDataProps => {
-    const properties = COLLECTION_CREATE_FORM_SELECTOR(state, 'properties');
-    return { properties };
-};
-
-const mapDispatchToProps = (dispatch: Dispatch): CreateCollectionPropertiesListActionProps => ({
-    handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, COLLECTION_CREATE_FORM_NAME))
-});
-
-type CreateCollectionPropertiesListProps = CreateCollectionPropertiesListDataProps &
-    CreateCollectionPropertiesListActionProps & WithStyles<CssRules>;
-
-const List = withStyles(styles)(
-    ({ classes, handleDelete, properties }: CreateCollectionPropertiesListProps) =>
-        <div>
-            {properties &&
-                Object.keys(properties).map(k =>
-                    Array.isArray(properties[k])
-                    ? (properties[k] as string[]).map((v: string) =>
-                        getPropertyChip(
-                            k, v,
-                            () => handleDelete(k, v),
-                            classes.tag))
-                    : getPropertyChip(
-                        k, (properties[k] as string),
-                        () => handleDelete(k, (properties[k] as string)),
-                        classes.tag))
-                }
-        </div>
-);
-
-export const CreateCollectionPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);
\ 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
deleted file mode 100644 (file)
index 792786f..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import React from 'react';
-import { connect } from 'react-redux';
-import { Dispatch } from 'redux';
-import {
-    withStyles,
-    StyleRulesCallback,
-    WithStyles,
-} from '@material-ui/core';
-import { RootState } from 'store/store';
-import {
-    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';
-
-const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    tag: {
-        marginRight: theme.spacing.unit,
-        marginBottom: theme.spacing.unit
-    }
-});
-
-interface UpdateCollectionPropertiesListDataProps {
-    properties: CollectionProperties;
-}
-
-interface UpdateCollectionPropertiesListActionProps {
-    handleDelete: (key: string, value: string) => void;
-}
-
-const mapStateToProps = (state: RootState): UpdateCollectionPropertiesListDataProps => {
-    const properties = COLLECTION_UPDATE_FORM_SELECTOR(state, 'properties');
-    return { properties };
-};
-
-const mapDispatchToProps = (dispatch: Dispatch): UpdateCollectionPropertiesListActionProps => ({
-    handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, COLLECTION_UPDATE_FORM_NAME))
-});
-
-type UpdateCollectionPropertiesListProps = UpdateCollectionPropertiesListDataProps &
-    UpdateCollectionPropertiesListActionProps & WithStyles<CssRules>;
-
-const List = withStyles(styles)(
-    ({ classes, handleDelete, properties }: UpdateCollectionPropertiesListProps) =>
-        <div>
-            {properties &&
-                Object.keys(properties).map(k =>
-                    Array.isArray(properties[k])
-                    ? (properties[k] as string[]).map((v: string) =>
-                        getPropertyChip(
-                            k, v,
-                            () => handleDelete(k, v),
-                            classes.tag))
-                    : getPropertyChip(
-                        k, (properties[k] as string),
-                        () => handleDelete(k, (properties[k] as string)),
-                        classes.tag))
-                }
-        </div>
-);
-
-export const UpdateCollectionPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);
\ No newline at end of file
index b75ad50f7cf10fedbbebab81947f72961f62d565..163eb9831ec9a0b6a4ad52abb3dca89d48a05820 100644 (file)
@@ -5,7 +5,7 @@
 import React from 'react';
 import { InjectedFormProps, Field } from 'redux-form';
 import { WithDialogProps } from 'store/dialog/with-dialog';
-import { CollectionCreateFormDialogData } from 'store/collections/collection-create-actions';
+import { CollectionCreateFormDialogData, COLLECTION_CREATE_FORM_NAME } from 'store/collections/collection-create-actions';
 import { FormDialog } from 'components/form-dialog/form-dialog';
 import {
     CollectionNameField,
@@ -14,9 +14,9 @@ import {
 } from 'views-components/form-fields/collection-form-fields';
 import { FileUploaderField } from '../file-uploader/file-uploader';
 import { ResourceParentField } from '../form-fields/resource-form-fields';
-import { CreateCollectionPropertiesList } from 'views-components/collection-properties/create-collection-properties-list';
 import { CreateCollectionPropertiesForm } from 'views-components/collection-properties/create-collection-properties-form';
 import { FormGroup, FormLabel } from '@material-ui/core';
+import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
 
 type DialogCollectionProps = WithDialogProps<{}> & InjectedFormProps<CollectionCreateFormDialogData>;
 
@@ -28,6 +28,8 @@ export const DialogCollectionCreate = (props: DialogCollectionProps) =>
         {...props}
     />;
 
+const CreateCollectionPropertiesList = resourcePropertiesList(COLLECTION_CREATE_FORM_NAME);
+
 const CollectionAddFields = () => <span>
     <ResourceParentField />
     <CollectionNameField />
index 81e9485c12ef9819eca731f99f58ce127c16c8c5..34860599516bf4af234912d5f52f2245a6b20969 100644 (file)
@@ -5,13 +5,13 @@
 import React from 'react';
 import { InjectedFormProps } from 'redux-form';
 import { WithDialogProps } from 'store/dialog/with-dialog';
-import { ProjectCreateFormDialogData } from 'store/projects/project-create-actions';
+import { ProjectCreateFormDialogData, PROJECT_CREATE_FORM_NAME } from 'store/projects/project-create-actions';
 import { FormDialog } from 'components/form-dialog/form-dialog';
 import { ProjectNameField, ProjectDescriptionField } from 'views-components/form-fields/project-form-fields';
 import { CreateProjectPropertiesForm } from 'views-components/project-properties/create-project-properties-form';
-import { CreateProjectPropertiesList } from 'views-components/project-properties/create-project-properties-list';
 import { ResourceParentField } from '../form-fields/resource-form-fields';
 import { FormGroup, FormLabel } from '@material-ui/core';
+import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
 
 type DialogProjectProps = WithDialogProps<{}> & InjectedFormProps<ProjectCreateFormDialogData>;
 
@@ -23,6 +23,8 @@ export const DialogProjectCreate = (props: DialogProjectProps) =>
         {...props}
     />;
 
+const CreateProjectPropertiesList = resourcePropertiesList(PROJECT_CREATE_FORM_NAME);
+
 const ProjectAddFields = () => <span>
     <ResourceParentField />
     <ProjectNameField />
index 5bdaa4f408e659a390d03152ecb7316fffbf2a87..852dab1a354b874cb1273340f48b752342df3dc8 100644 (file)
@@ -5,7 +5,7 @@
 import React from 'react';
 import { InjectedFormProps } from 'redux-form';
 import { WithDialogProps } from 'store/dialog/with-dialog';
-import { CollectionUpdateFormDialogData } from 'store/collections/collection-update-actions';
+import { CollectionUpdateFormDialogData, COLLECTION_UPDATE_FORM_NAME } from 'store/collections/collection-update-actions';
 import { FormDialog } from 'components/form-dialog/form-dialog';
 import {
     CollectionNameField,
@@ -13,8 +13,8 @@ import {
     CollectionStorageClassesField
 } from 'views-components/form-fields/collection-form-fields';
 import { UpdateCollectionPropertiesForm } from 'views-components/collection-properties/update-collection-properties-form';
-import { UpdateCollectionPropertiesList } from 'views-components/collection-properties/update-collection-properties-list';
 import { FormGroup, FormLabel } from '@material-ui/core';
+import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
 
 type DialogCollectionProps = WithDialogProps<{}> & InjectedFormProps<CollectionUpdateFormDialogData>;
 
@@ -26,6 +26,8 @@ export const DialogCollectionUpdate = (props: DialogCollectionProps) =>
         {...props}
     />;
 
+const UpdateCollectionPropertiesList = resourcePropertiesList(COLLECTION_UPDATE_FORM_NAME);
+
 const CollectionEditFields = () => <span>
     <CollectionNameField />
     <CollectionDescriptionField />
index 96e6d927751d092ee48af40d65a3512241ce1475..9737858a3f385ca5552b1e65a077c273e5fb5ccb 100644 (file)
@@ -5,13 +5,13 @@
 import React from 'react';
 import { InjectedFormProps } from 'redux-form';
 import { WithDialogProps } from 'store/dialog/with-dialog';
-import { ProjectUpdateFormDialogData } from 'store/projects/project-update-actions';
+import { ProjectUpdateFormDialogData, PROJECT_UPDATE_FORM_NAME } from 'store/projects/project-update-actions';
 import { FormDialog } from 'components/form-dialog/form-dialog';
 import { ProjectNameField, ProjectDescriptionField, UsersField } from 'views-components/form-fields/project-form-fields';
 import { GroupClass } from 'models/group';
 import { FormGroup, FormLabel } from '@material-ui/core';
 import { UpdateProjectPropertiesForm } from 'views-components/project-properties/update-project-properties-form';
-import { UpdateProjectPropertiesList } from 'views-components/project-properties/update-project-properties-list';
+import { resourcePropertiesList } from 'views-components/resource-properties/resource-properties-list';
 
 type DialogProjectProps = WithDialogProps<{sourcePanel: GroupClass, create?: boolean}> & InjectedFormProps<ProjectUpdateFormDialogData>;
 
@@ -34,6 +34,8 @@ export const DialogProjectUpdate = (props: DialogProjectProps) => {
     />;
 };
 
+const UpdateProjectPropertiesList = resourcePropertiesList(PROJECT_UPDATE_FORM_NAME);
+
 // Also used as "Group Edit Fields"
 const ProjectEditFields = () => <span>
     <ProjectNameField />
diff --git a/src/views-components/project-properties/update-project-properties-list.tsx b/src/views-components/project-properties/update-project-properties-list.tsx
deleted file mode 100644 (file)
index 5ac22b9..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import React from 'react';
-import { connect } from 'react-redux';
-import { Dispatch } from 'redux';
-import {
-    withStyles,
-    StyleRulesCallback,
-    WithStyles,
-} from '@material-ui/core';
-import { RootState } from 'store/store';
-import {
-    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';
-
-const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    tag: {
-        marginRight: theme.spacing.unit,
-        marginBottom: theme.spacing.unit
-    }
-});
-
-interface UpdateProjectPropertiesListDataProps {
-    properties: ProjectProperties;
-}
-
-interface UpdateProjectPropertiesListActionProps {
-    handleDelete: (key: string, value: string) => void;
-}
-
-const mapStateToProps = (state: RootState): UpdateProjectPropertiesListDataProps => {
-    const properties = PROJECT_UPDATE_FORM_SELECTOR(state, 'properties');
-    return { properties };
-};
-
-const mapDispatchToProps = (dispatch: Dispatch): UpdateProjectPropertiesListActionProps => ({
-    handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, PROJECT_UPDATE_FORM_NAME))
-});
-
-type UpdateProjectPropertiesListProps = UpdateProjectPropertiesListDataProps &
-    UpdateProjectPropertiesListActionProps & WithStyles<CssRules>;
-
-const List = withStyles(styles)(
-    ({ classes, handleDelete, properties }: UpdateProjectPropertiesListProps) =>
-        <div>
-            {properties &&
-                Object.keys(properties).map(k =>
-                    Array.isArray(properties[k])
-                    ? (properties[k] as string[]).map((v: string) =>
-                        getPropertyChip(
-                            k, v,
-                            () => handleDelete(k, v),
-                            classes.tag))
-                    : getPropertyChip(
-                        k, (properties[k] as string),
-                        () => handleDelete(k, (properties[k] as string)),
-                        classes.tag))
-                }
-        </div>
-);
-
-export const UpdateProjectPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);
\ No newline at end of file
similarity index 58%
rename from src/views-components/project-properties/create-project-properties-list.tsx
rename to src/views-components/resource-properties/resource-properties-list.tsx
index ac7dc6fddd39d4255865faa6ebb3a853379ce60b..a7b5825244abc7c2e859e676db49a32321fa2b67 100644 (file)
@@ -11,14 +11,10 @@ import {
     WithStyles,
 } from '@material-ui/core';
 import { RootState } from 'store/store';
-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';
+import { formValueSelector } from 'redux-form';
 
 type CssRules = 'tag';
 
@@ -29,28 +25,19 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
-interface CreateProjectPropertiesListDataProps {
-    properties: ProjectProperties;
+interface ResourcePropertiesListDataProps {
+    properties: {[key: string]: string | string[]};
 }
 
-interface CreateProjectPropertiesListActionProps {
+interface ResourcePropertiesListActionProps {
     handleDelete: (key: string, value: string) => void;
 }
 
-const mapStateToProps = (state: RootState): CreateProjectPropertiesListDataProps => {
-    const properties = PROJECT_CREATE_FORM_SELECTOR(state, 'properties');
-    return { properties };
-};
-
-const mapDispatchToProps = (dispatch: Dispatch): CreateProjectPropertiesListActionProps => ({
-    handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, PROJECT_CREATE_FORM_NAME))
-});
-
-type CreateProjectPropertiesListProps = CreateProjectPropertiesListDataProps &
-    CreateProjectPropertiesListActionProps & WithStyles<CssRules>;
+type ResourcePropertiesListProps = ResourcePropertiesListDataProps &
+ResourcePropertiesListActionProps & WithStyles<CssRules>;
 
 const List = withStyles(styles)(
-    ({ classes, handleDelete, properties }: CreateProjectPropertiesListProps) =>
+    ({ classes, handleDelete, properties }: ResourcePropertiesListProps) =>
         <div>
             {properties &&
                 Object.keys(properties).map(k =>
@@ -68,4 +55,12 @@ const List = withStyles(styles)(
         </div>
 );
 
-export const CreateProjectPropertiesList = connect(mapStateToProps, mapDispatchToProps)(List);
\ No newline at end of file
+export const resourcePropertiesList = (formName: string) =>
+    connect(
+        (state: RootState): ResourcePropertiesListDataProps => ({
+            properties: formValueSelector(formName)(state, 'properties')
+        }),
+        (dispatch: Dispatch): ResourcePropertiesListActionProps => ({
+                handleDelete: (key: string, value: string) => dispatch<any>(removePropertyFromResourceForm(key, value, formName))
+        })
+    )(List);
\ No newline at end of file