@@ -10,6 +10,14 @@ import { Group } from 'services/AuthService';
1010import { Role } from 'services/RolesService' ;
1111import SelectSingle from 'Components/SelectSingle' ;
1212
13+ export type RuleGroupErrors = {
14+ roleName ?: string ;
15+ props ?: {
16+ key ?: string ;
17+ value ?: string ;
18+ } ;
19+ } ;
20+
1321export type RuleGroupsProps = {
1422 authProviderId : string ;
1523 onChange : (
@@ -20,17 +28,18 @@ export type RuleGroupsProps = {
2028 groups : Group [ ] ;
2129 setFieldValue : ( name : string , value : string ) => void ;
2230 disabled : boolean | undefined ;
31+ errors ?: RuleGroupErrors [ ] ;
2332} ;
2433
2534const ruleKeys = [ 'userid' , 'name' , 'email' , 'groups' ] ;
2635
27- function getAugmentedRuleKeys ( existingKeys , groups ) {
36+ function getAugmentedRuleKeys ( groups ) {
2837 const newRuleKeys = [ ...ruleKeys ] ;
2938
3039 groups . forEach ( ( group ) => {
3140 const alreadyInList = newRuleKeys . find ( ( key ) => key === group ?. props ?. key ) ;
3241
33- if ( ! alreadyInList ) {
42+ if ( group . props . key && ! alreadyInList ) {
3443 newRuleKeys . push ( group . props . key ) ;
3544 }
3645 } ) ;
@@ -45,8 +54,9 @@ function RuleGroups({
4554 groups = [ ] ,
4655 roles = [ ] ,
4756 disabled = false ,
57+ errors = [ ] ,
4858} : RuleGroupsProps ) : ReactElement {
49- const augmentedRuleKeys = getAugmentedRuleKeys ( ruleKeys , groups ) ;
59+ const augmentedRuleKeys = getAugmentedRuleKeys ( groups ) ;
5060
5161 return (
5262 < FieldArray
@@ -58,7 +68,12 @@ function RuleGroups({
5868 groups . map ( ( group , index : number ) => (
5969 < Flex key = { `${ group . props . authProviderId } _custom_rule_${ index } ` } >
6070 < FlexItem >
61- < FormGroup label = "Key" fieldId = { `groups[${ index } ].props.key` } >
71+ < FormGroup
72+ label = "Key"
73+ fieldId = { `groups[${ index } ].props.key` }
74+ helperTextInvalid = { errors [ index ] ?. props ?. key || '' }
75+ validated = { errors [ index ] ?. props ?. key ? 'error' : 'default' }
76+ >
6277 < SelectSingle
6378 id = { `groups[${ index } ].props.key` }
6479 value = { groups [ `${ index } ` ] . props . key }
@@ -67,6 +82,7 @@ function RuleGroups({
6782 direction = "up"
6883 isCreatable
6984 variant = "typeahead"
85+ placeholderText = "Select or enter a key"
7086 >
7187 { augmentedRuleKeys . map ( ( ruleKey ) => (
7288 < SelectOption key = { ruleKey } value = { ruleKey } />
@@ -78,6 +94,10 @@ function RuleGroups({
7894 < FormGroup
7995 label = "Value"
8096 fieldId = { `groups[${ index } ].props.value` }
97+ helperTextInvalid = { errors [ index ] ?. props ?. value || '' }
98+ validated = {
99+ errors [ index ] ?. props ?. value ? 'error' : 'default'
100+ }
81101 >
82102 < TextInput
83103 type = "text"
@@ -92,13 +112,19 @@ function RuleGroups({
92112 < ArrowRightIcon style = { { transform : 'translate(0, 42px)' } } />
93113 </ FlexItem >
94114 < FlexItem >
95- < FormGroup label = "Role" fieldId = { `groups[${ index } ].roleName` } >
115+ < FormGroup
116+ label = "Role"
117+ fieldId = { `groups[${ index } ].roleName` }
118+ helperTextInvalid = { errors [ index ] ?. roleName || '' }
119+ validated = { errors [ index ] ?. roleName ? 'error' : 'default' }
120+ >
96121 < SelectSingle
97122 id = { `groups[${ index } ].roleName` }
98123 value = { groups [ `${ index } ` ] . roleName }
99124 isDisabled = { disabled }
100125 handleSelect = { setFieldValue }
101126 direction = "up"
127+ placeholderText = "Select a role"
102128 >
103129 { roles . map ( ( { name } ) => (
104130 < SelectOption key = { name } value = { name } />
@@ -126,13 +152,14 @@ function RuleGroups({
126152 < Button
127153 variant = "link"
128154 isInline
155+ isDisabled = { ! ! errors ?. length }
129156 icon = { < PlusCircleIcon className = "pf-u-mr-sm" /> }
130157 onClick = { ( ) =>
131158 arrayHelpers . push ( {
132- roleName : roles [ 0 ] ?. name || '' ,
159+ roleName : '' ,
133160 props : {
134161 authProviderId : authProviderId || '' ,
135- key : augmentedRuleKeys [ 0 ] ,
162+ key : '' ,
136163 value : '' ,
137164 } ,
138165 } )
0 commit comments