@@ -16,7 +16,7 @@ import { withRouter } from 'react-router-dom'
1616import { RouteComponentProps } from 'react-router'
1717import Component , { IEnumValueForDisplay } from './EntityCreatorComponent'
1818import { autobind } from 'core-decorators'
19- import { getUniqueConditions , getUpdatedActionsUsingCondition } from 'src/Utils/actionCondition'
19+ import { getUniqueConditions , getUpdatedActionsUsingCondition , isEntityAllowedInCondition } from 'src/Utils/actionCondition'
2020import { NONE_RESOLVER_KEY } from '../../../types/const'
2121
2222const entityNameMaxLength = 30
@@ -29,6 +29,7 @@ const initState: ComponentState = {
2929 entityResolverVal : NONE_RESOLVER_KEY ,
3030 isPrebuilt : false ,
3131 isMultivalueVal : false ,
32+ isMultiValueDisabled : false ,
3233 isNegatableVal : false ,
3334 isResolutionRequired : false ,
3435 enumValues : [ ] ,
@@ -53,6 +54,7 @@ interface ComponentState {
5354 entityResolverVal : string
5455 isPrebuilt : boolean
5556 isMultivalueVal : boolean
57+ isMultiValueDisabled : boolean
5658 isNegatableVal : boolean
5759 isResolutionRequired : boolean
5860 enumValues : ( CLM . EnumValue | null ) [ ]
@@ -172,12 +174,15 @@ class Container extends React.Component<Props, ComponentState> {
172174 ? NONE_RESOLVER_KEY
173175 : nextProps . entity . resolverType
174176
177+ const isMultiValueDisabled = this . isMultiValueDisabled ( nextProps . entity , this . props . actions )
178+
175179 this . setState ( {
176180 entityNameVal : nextProps . entity . entityName ,
177181 entityTypeVal : entityType ,
178182 entityResolverVal : resolverType ,
179183 isPrebuilt : isPrebuilt ,
180184 isMultivalueVal : nextProps . entity . isMultivalue ,
185+ isMultiValueDisabled,
181186 isNegatableVal : nextProps . entity . isNegatible ,
182187 isResolutionRequired : nextProps . entity . isResolutionRequired ,
183188 title : nextProps . intl . formatMessage ( {
@@ -325,6 +330,13 @@ class Container extends React.Component<Props, ComponentState> {
325330 return newOrEditedEntity
326331 }
327332
333+ isMultiValueDisabled ( entity : CLM . EntityBase , actions : CLM . ActionBase [ ] ) {
334+ // If entity is already used in condition and changing multivalue to false would prevent entity from being valid in condition
335+ const entityWithMultiValueFalse : CLM . EntityBase = { ...entity , isMultivalue : false }
336+ return actions . some ( a => a . requiredConditions . some ( condition => condition . entityId === entity . entityId ) ) === true
337+ && isEntityAllowedInCondition ( entityWithMultiValueFalse ) === false
338+ }
339+
328340 @autobind
329341 async onClickSaveCreate ( ) {
330342 const newOrEditedEntity = this . convertStateToEntity ( this . state , this . props . entity ? this . props . entity : undefined )
@@ -849,7 +861,7 @@ class Container extends React.Component<Props, ComponentState> {
849861 onKeyDownName = { this . onKeyDownName }
850862
851863 isMultiValue = { this . state . isMultivalueVal }
852- isMultiValueDisabled = { false }
864+ isMultiValueDisabled = { this . state . isMultiValueDisabled }
853865 onChangeMultiValue = { this . onChangeMultivalue }
854866
855867 isNegatable = { this . state . isNegatableVal }
0 commit comments