16439: Adds read-only field 'Location' to project/collection creation dialogs.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 29 May 2020 14:05:24 +0000 (11:05 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 29 May 2020 14:05:24 +0000 (11:05 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/store/collections/collection-create-actions.ts
src/store/projects/project-create-actions.ts
src/views-components/dialog-create/dialog-collection-create.tsx
src/views-components/dialog-create/dialog-project-create.tsx
src/views-components/form-fields/resource-form-fields.tsx [new file with mode: 0644]

index 39565f1d43b095c22470926e4f3d0f4d98f6c151..140756bfe6f85973688df0eaa04fa35f37435fc8 100644 (file)
@@ -31,7 +31,7 @@ export const openCollectionCreateDialog = (ownerUuid: string) =>
         if (isItemNotInProject(properties) || !isProjectOrRunProcessRoute(router)) {
             const userUuid = getUserUuid(getState());
             if (!userUuid) { return; }
-            dispatch(initialize(COLLECTION_CREATE_FORM_NAME, { userUuid }));
+            dispatch(initialize(COLLECTION_CREATE_FORM_NAME, { ownerUuid: userUuid }));
         } else {
             dispatch(initialize(COLLECTION_CREATE_FORM_NAME, { ownerUuid }));
         }
index a303b5518dc7a5b43ceb28cc7028c89764dea4c7..6f45bc38e7858516e1c1571e6dcdd0b694c88d26 100644 (file)
@@ -50,7 +50,7 @@ export const openProjectCreateDialog = (ownerUuid: string) =>
         if (isItemNotInProject(properties) || !isProjectOrRunProcessRoute(router)) {
             const userUuid = getUserUuid(getState());
             if (!userUuid) { return; }
-            dispatch(initialize(PROJECT_CREATE_FORM_NAME, { userUuid }));
+            dispatch(initialize(PROJECT_CREATE_FORM_NAME, { ownerUuid: userUuid }));
         } else {
             dispatch(initialize(PROJECT_CREATE_FORM_NAME, { ownerUuid }));
         }
index fb492c43813d7f8e53498dfc41808aa7f4ce815f..86d6a217e5639071a62b4b7840d19aeb155994a8 100644 (file)
@@ -9,7 +9,7 @@ import { CollectionCreateFormDialogData } from '~/store/collections/collection-c
 import { FormDialog } from '~/components/form-dialog/form-dialog';
 import { CollectionNameField, CollectionDescriptionField } from '~/views-components/form-fields/collection-form-fields';
 import { FileUploaderField } from '../file-uploader/file-uploader';
-
+import { ResourceLocationField } from '../form-fields/resource-form-fields';
 
 type DialogCollectionProps = WithDialogProps<{}> & InjectedFormProps<CollectionCreateFormDialogData>;
 
@@ -22,6 +22,7 @@ export const DialogCollectionCreate = (props: DialogCollectionProps) =>
     />;
 
 const CollectionAddFields = () => <span>
+    <ResourceLocationField />
     <CollectionNameField />
     <CollectionDescriptionField />
     <Field
index 02fb67e5f202c8b70b96c1bb59f76587998edf40..7359ba84c32970d54078732674166f301fb6dc55 100644 (file)
@@ -10,6 +10,7 @@ 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 { ResourceLocationField } from '../form-fields/resource-form-fields';
 
 type DialogProjectProps = WithDialogProps<{}> & InjectedFormProps<ProjectCreateFormDialogData>;
 
@@ -22,6 +23,7 @@ export const DialogProjectCreate = (props: DialogProjectProps) =>
     />;
 
 const ProjectAddFields = () => <span>
+    <ResourceLocationField />
     <ProjectNameField />
     <ProjectDescriptionField />
     <CreateProjectPropertiesForm />
diff --git a/src/views-components/form-fields/resource-form-fields.tsx b/src/views-components/form-fields/resource-form-fields.tsx
new file mode 100644 (file)
index 0000000..0ba357c
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { connect } from "react-redux";
+import { RootState } from "~/store/store";
+import { Field } from "redux-form";
+import { ResourcesState, getResource } from "~/store/resources/resources";
+import { GroupResource } from "~/models/group";
+import { TextField } from "~/components/text-field/text-field";
+import { getUserUuid } from "~/common/getuser";
+
+interface ResourceLocationFieldProps {
+    resources: ResourcesState;
+    userUuid: string|undefined;
+}
+
+export const ResourceLocationField = connect(
+    (state: RootState) => {
+        return {
+            resources: state.resources,
+            userUuid: getUserUuid(state),
+        };
+    })
+    ((props: ResourceLocationFieldProps) =>
+        <Field
+            name='ownerUuid'
+            disabled={true}
+            label='Location'
+            format={
+                (value, name) => {
+                    if (value === props.userUuid) {
+                        return 'Home project';
+                    }
+                    const rsc = getResource<GroupResource>(value)(props.resources);
+                    if (rsc !== undefined) {
+                        return `Project '${rsc.name}' (${rsc.uuid})`;
+                    }
+                    return value;
+                }
+            }
+            component={TextField} />
+    );