X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/2129d2a8fc553a0e89b374bdad2226ff3b3d377e..db1c206c8403ed2b874625f1d1afc7af85dde25c:/src/views/run-process-panel/inputs/project-input.tsx

diff --git a/src/views/run-process-panel/inputs/project-input.tsx b/src/views/run-process-panel/inputs/project-input.tsx
index 95f3ad89..9cf16c31 100644
--- a/src/views/run-process-panel/inputs/project-input.tsx
+++ b/src/views/run-process-panel/inputs/project-input.tsx
@@ -4,7 +4,7 @@
 
 import React from 'react';
 import { connect, DispatchProp } from 'react-redux';
-import { Field, WrappedFieldProps } from 'redux-form';
+import { Field } from 'redux-form';
 import { Input, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@material-ui/core';
 import {
     GenericCommandInputParameter
@@ -13,12 +13,16 @@ import { GenericInput, GenericInputProps } from './generic-input';
 import { ProjectsTreePicker } from 'views-components/projects-tree-picker/projects-tree-picker';
 import { initProjectsTreePicker } from 'store/tree-picker/tree-picker-actions';
 import { TreeItem } from 'components/tree/tree';
-import { ProjectsTreePickerItem } from 'views-components/projects-tree-picker/generic-projects-tree-picker';
+import { ProjectsTreePickerItem } from 'store/tree-picker/tree-picker-middleware';
 import { ProjectResource } from 'models/project';
 import { ResourceKind } from 'models/resource';
+import { RootState } from 'store/store';
+import { getUserUuid } from 'common/getuser';
 
 export type ProjectCommandInputParameter = GenericCommandInputParameter<ProjectResource, ProjectResource>;
 
+const require: any = (value?: ProjectResource) => (value === undefined);
+
 export interface ProjectInputProps {
     input: ProjectCommandInputParameter;
     options?: { showOnlyOwned: boolean, showOnlyWritable: boolean };
@@ -29,6 +33,7 @@ export const ProjectInput = ({ input, options }: ProjectInputProps) =>
         commandInput={input}
         component={ProjectInputComponent as any}
         format={format}
+        validate={require}
         {...{
             options
         }} />;
@@ -40,8 +45,14 @@ interface ProjectInputComponentState {
     project?: ProjectResource;
 }
 
-export const ProjectInputComponent = connect()(
-    class ProjectInputComponent extends React.Component<GenericInputProps & DispatchProp & {
+interface HasUserUuid {
+    userUuid: string;
+};
+
+const mapStateToProps = (state: RootState) => ({ userUuid: getUserUuid(state) });
+
+export const ProjectInputComponent = connect(mapStateToProps)(
+    class ProjectInputComponent extends React.Component<GenericInputProps & DispatchProp & HasUserUuid & {
         options?: { showOnlyOwned: boolean, showOnlyWritable: boolean };
     }, ProjectInputComponentState> {
         state: ProjectInputComponentState = {
@@ -61,6 +72,7 @@ export const ProjectInputComponent = connect()(
         }
 
         openDialog = () => {
+            this.componentDidMount();
             this.setState({ open: true });
         }
 
@@ -81,6 +93,8 @@ export const ProjectInputComponent = connect()(
             }
         }
 
+        invalid = () => (!this.state.project || this.state.project.writableBy.indexOf(this.props.userUuid) === -1);
+
         renderInput() {
             return <GenericInput
                 component={props =>
@@ -96,7 +110,7 @@ export const ProjectInputComponent = connect()(
         }
 
         renderDialog() {
-            return <Dialog
+            return this.state.open ? <Dialog
                 open={this.state.open}
                 onClose={this.closeDialog}
                 fullWidth
@@ -112,12 +126,12 @@ export const ProjectInputComponent = connect()(
                 <DialogActions>
                     <Button onClick={this.closeDialog}>Cancel</Button>
                     <Button
-                        disabled={!this.state.project}
+                        disabled={this.invalid()}
                         variant='contained'
                         color='primary'
                         onClick={this.submit}>Ok</Button>
                 </DialogActions>
-            </Dialog>;
+            </Dialog> : null;
         }
 
     });
