1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { compose } from "redux";
7 import { reduxForm, InjectedFormProps, Field, GenericField } from 'redux-form';
8 import { withDialog, WithDialogProps } from "store/dialog/with-dialog";
9 import { FormDialog } from 'components/form-dialog/form-dialog';
10 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';
11 import { ParticipantSelect } from 'views-components/sharing-dialog/participant-select';
12 import { GroupArrayInput, GroupArrayDataProps } from 'views-components/virtual-machines-dialog/group-array-input';
14 export const VirtualMachineAddLoginDialog = compose(
15 withDialog(VIRTUAL_MACHINE_ADD_LOGIN_DIALOG),
16 reduxForm<AddLoginFormData>({
17 form: VIRTUAL_MACHINE_ADD_LOGIN_FORM,
18 onSubmit: (data, dispatch) => {
19 dispatch(addUpdateVirtualMachineLogin(data));
23 (props: CreateGroupDialogComponentProps) => {
24 const [hasPartialGroupInput, setPartialGroupInput] = React.useState<boolean>(false);
27 dialogTitle={props.data.updating ? "Update login permission" : "Add login permission"}
28 formFields={AddLoginFormFields}
29 submitLabel={props.data.updating ? "Update" : "Add"}
36 invalid={props.invalid || hasPartialGroupInput}
41 type CreateGroupDialogComponentProps = WithDialogProps<{updating: boolean}> & GroupArrayDataProps & InjectedFormProps<AddLoginFormData>;
43 const AddLoginFormFields = (props) => {
46 name={VIRTUAL_MACHINE_ADD_LOGIN_USER_FIELD}
47 component={props.data.updating ? ReadOnlyUserSelect : UserSelect}
48 excludedParticipants={props.data.excludedParticipants}
51 name={VIRTUAL_MACHINE_ADD_LOGIN_GROUPS_FIELD}
52 input={{id:"Add groups to VM login (eg: docker, sudo)", disabled:false}}
54 setPartialGroupInput={props.data.setPartialGroupInput}
55 hasPartialGroupInput={props.data.hasPartialGroupInput}
60 interface UserFieldProps {
61 excludedParticipants: string[];
64 const ParticipantField = Field as new () => GenericField<UserFieldProps>;
66 const UserSelect = (props) =>
70 label='Search for user to grant login permission'
71 items={props.input.value ? [props.input.value] : []}
72 excludedParticipants={props.excludedParticipants}
73 onSelect={props.input.onChange}
74 onDelete={() => (props.input.onChange(''))} />;
76 const ReadOnlyUserSelect = (props) =>
81 items={props.input.value ? [props.input.value] : []}