19049: Make participant select read only when editing vm logins
authorStephen Smith <stephen@curii.com>
Thu, 12 May 2022 17:35:52 +0000 (13:35 -0400)
committerStephen Smith <stephen@curii.com>
Thu, 12 May 2022 19:35:52 +0000 (15:35 -0400)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

src/components/autocomplete/autocomplete.tsx
src/views-components/sharing-dialog/participant-select.tsx
src/views-components/virtual-machines-dialog/add-login-dialog.tsx

index cc1843367eb0b55fb64f36ea6051a398ae7e6f53..0044807b8a9ddb3e2abeb43a546dad5a2ada4d83 100644 (file)
@@ -175,7 +175,7 @@ export class Autocomplete<Value, Suggestion> extends React.Component<Autocomplet
                 <Chip
                     label={this.renderChipValue(item)}
                     key={index}
-                    onDelete={() => onDelete ? onDelete(item, index) : undefined} />
+                    onDelete={onDelete && !this.props.disabled ? (() =>  onDelete(item, index)) : undefined} />
         );
     }
 
index a5d394791f5122d8520871ef526bd8d79288f036..eb7e8d1010afeb096fe33f4c81621fc674435d14 100644 (file)
@@ -28,6 +28,7 @@ interface ParticipantSelectProps {
     label?: string;
     autofocus?: boolean;
     onlyPeople?: boolean;
+    disabled?: boolean;
 
     onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
     onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
@@ -72,11 +73,12 @@ export const ParticipantSelect = connect()(
                     onChange={this.handleChange}
                     onCreate={this.handleCreate}
                     onSelect={this.handleSelect}
-                    onDelete={this.handleDelete}
+                    onDelete={this.props.onDelete && !this.props.disabled ? this.handleDelete : undefined}
                     onFocus={this.props.onFocus}
                     onBlur={this.props.onBlur}
                     renderChipValue={this.renderChipValue}
-                    renderSuggestion={this.renderSuggestion} />
+                    renderSuggestion={this.renderSuggestion}
+                    disabled={this.props.disabled}/>
             );
         }
 
index d9547d7c609a93e3a1e4797e2c9c9cc62c28d733..517734182bb3f037349707b9f37b620eda0d6700 100644 (file)
@@ -35,7 +35,7 @@ const AddLoginFormFields = (props) => {
     return <>
         <ParticipantField
             name={VIRTUAL_MACHINE_ADD_LOGIN_USER_FIELD}
-            component={UserSelect}
+            component={props.data.updating ? ReadOnlyUserSelect : UserSelect}
             excludedParticipants={props.data.excludedParticipants}
         />
         <GroupArrayInput
@@ -46,7 +46,6 @@ const AddLoginFormFields = (props) => {
     </>;
 }
 
-
 interface UserFieldProps {
     excludedParticipants: string[];
 }
@@ -61,3 +60,10 @@ const UserSelect = (props) =>
         excludedParticipants={props.excludedParticipants}
         onSelect={props.input.onChange}
         onDelete={() => (props.input.onChange(''))} />;
+
+const ReadOnlyUserSelect = (props) =>
+        <ParticipantSelect
+            onlyPeople
+            label='User'
+            items={props.input.value ? [props.input.value] : []}
+            disabled={true} />;