X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/a14e75ef7270c29001e8ca462b35bf58588674ed..2d04921ec52baaa9da2e0ffee436ad24e13e9921:/src/views-components/form-fields/resource-form-fields.tsx?ds=inline

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
index 00000000..0ba357c3
--- /dev/null
+++ b/src/views-components/form-fields/resource-form-fields.tsx
@@ -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} />
+    );
