19049: Exclude existing users with logins in create login user picker
[arvados-workbench2.git] / src / views-components / virtual-machines-dialog / add-login-dialog.tsx
index bfc047164a4bc8d00bdb15f82c8db19b422c6521..d9547d7c609a93e3a1e4797e2c9c9cc62c28d733 100644 (file)
@@ -4,7 +4,7 @@
 
 import React from 'react';
 import { compose } from "redux";
-import { reduxForm, InjectedFormProps, WrappedFieldProps, Field } from 'redux-form';
+import { reduxForm, InjectedFormProps, WrappedFieldProps, Field, GenericField } from 'redux-form';
 import { withDialog, WithDialogProps } from "store/dialog/with-dialog";
 import { FormDialog } from 'components/form-dialog/form-dialog';
 import { VIRTUAL_MACHINE_ADD_LOGIN_DIALOG, VIRTUAL_MACHINE_ADD_LOGIN_FORM, addUpdateVirtualMachineLogin, AddLoginFormData, VIRTUAL_MACHINE_ADD_LOGIN_USER_FIELD, VIRTUAL_MACHINE_ADD_LOGIN_GROUPS_FIELD } from 'store/virtual-machines/virtual-machines-actions';
@@ -31,26 +31,33 @@ export const VirtualMachineAddLoginDialog = compose(
 
 type CreateGroupDialogComponentProps = WithDialogProps<{updating: boolean}> & InjectedFormProps<AddLoginFormData>;
 
-const AddLoginFormFields = () =>
-    <>
-        <UserField />
+const AddLoginFormFields = (props) => {
+    return <>
+        <ParticipantField
+            name={VIRTUAL_MACHINE_ADD_LOGIN_USER_FIELD}
+            component={UserSelect}
+            excludedParticipants={props.data.excludedParticipants}
+        />
         <GroupArrayInput
             name={VIRTUAL_MACHINE_ADD_LOGIN_GROUPS_FIELD}
             input={{id:"Add groups to VM login (eg: docker, sudo)", disabled:false}}
             required={false}
         />
     </>;
+}
+
+
+interface UserFieldProps {
+    excludedParticipants: string[];
+}
 
-const UserField = () =>
-    <Field
-        name={VIRTUAL_MACHINE_ADD_LOGIN_USER_FIELD}
-        component={UserSelect}
-        />;
+const ParticipantField = Field as new () => GenericField<UserFieldProps>;
 
-const UserSelect = ({ input, meta }: WrappedFieldProps) =>
+const UserSelect = (props) =>
     <ParticipantSelect
         onlyPeople
         label='Search for user to grant login permission'
-        items={input.value ? [input.value] : []}
-        onSelect={input.onChange}
-        onDelete={() => (input.onChange(''))} />;
+        items={props.input.value ? [props.input.value] : []}
+        excludedParticipants={props.excludedParticipants}
+        onSelect={props.input.onChange}
+        onDelete={() => (props.input.onChange(''))} />;