/
project-role-groups-edit.tsx
89 lines (82 loc) · 3.05 KB
/
project-role-groups-edit.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {FormField} from 'argo-ui';
import * as React from 'react';
import * as ReactForm from 'react-form';
import {Form, Text} from 'react-form';
interface ProjectRoleGroupsProps {
projName: string;
roleName: string;
groups: string[];
formApi: ReactForm.FormApi;
newRole: boolean;
}
export const ProjectRoleGroupsEdit = (props: ProjectRoleGroupsProps) => (
<React.Fragment>
<h4>Groups</h4>
<div>OIDC group names to bind to this role</div>
{
<div className='argo-table-list'>
<div className='argo-table-list__row'>
{(props.groups || []).map((groupName, i) => (
<Group
key={i}
field={['groups', i]}
formApi={props.formApi}
projName={props.projName}
roleName={props.roleName}
groupName={groupName}
deleteGroup={() => props.formApi.setValue('groups', removeEl(props.groups, i))}
/>
))}
</div>
</div>
}
<Form>
{api => (
<div className='argo-table-list'>
<div className='argo-table-list__row'>
<div className='row'>
<div className='columns small-9'>
<FormField formApi={api} label='' field='groupName' component={Text} />
</div>
<div className='columns small-3'>
<a
onClick={() => {
if (api.values.groupName.length > 0) {
props.formApi.setValue('groups', (props.formApi.values.groups || []).concat(api.values.groupName));
api.values.groupName = '';
}
}}>
Add group
</a>
</div>
</div>
</div>
</div>
)}
</Form>
</React.Fragment>
);
interface GroupProps {
projName: string;
roleName: string;
groupName: string;
fieldApi: ReactForm.FieldApi;
deleteGroup: () => void;
}
function removeEl(items: any[], index: number) {
items.splice(index, 1);
return items;
}
class GroupWrapper extends React.Component<GroupProps, any> {
public render() {
return (
<div className='row'>
<div className='columns small-11'>{this.props.groupName}</div>
<div className='columns small-1'>
<i className='fa fa-times' onClick={() => this.props.deleteGroup()} style={{cursor: 'pointer'}} />
</div>
</div>
);
}
}
const Group = ReactForm.FormField(GroupWrapper);