Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add/remove subconditions for grouped conditions #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/components/editor/Conditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,18 @@ class And extends Component<Props> {

render() {
let conditional = ((this.props.conditional: any): AndConditional);
let onChange = this.props.onChange('conditions');
return (
<label> And:
{conditional.conditions.map((cond, i) => {
return (
<div className="section" key={i}>
<ConditionalEditor {...this.props} conditional={cond} onChange={this.props.onChange(`conditions.${i}`)} />
<ConditionalEditor {...this.props} conditional={cond} onChange={onChange(`[${i}]`)} />
<a className="editable-text delete-button" onClick={() => onChange(`[${i}]`)({val: {id: null}})}>remove</a>
</div>
)
})}
<a className='editable-text add-button' onClick={() => onChange(`[${conditional.conditions.length}]`)({val: {id: getTemplate('Type.Condition.Age')}})}>+</a>
</label>
);
}
Expand All @@ -550,15 +553,18 @@ class Or extends Component<Props> {

render() {
let conditional = ((this.props.conditional: any): OrConditional);
let onChange = this.props.onChange('conditions');
return (
<label> Or:
{conditional.conditions.map((cond, i) => {
return (
<div className="section" key={i}>
<ConditionalEditor {...this.props} conditional={cond} onChange={this.props.onChange(`conditions.${i}`)} />
</div>
<div className="section" key={i}>
<ConditionalEditor {...this.props} conditional={cond} onChange={onChange(`[${i}]`)} />
<a className="editable-text delete-button" onClick={() => onChange(`[${i}]`)({val: {id: null}})}>remove</a>
</div>
)
})}
<a className='editable-text add-button' onClick={() => onChange(`[${conditional.conditions.length}]`)({val: {id: getTemplate('Type.Condition.Age')}})}>+</a>
</label>
);
}
Expand All @@ -569,16 +575,19 @@ class AtLeast extends Component<Props> {

render() {
let conditional = ((this.props.conditional: any): AtLeastConditional);
let onChange = this.props.onChange('conditions');
return (
<label> At Least
<RIENumber className='editable-text' value={conditional.minimum||0} propName='minimum' change={this.props.onChange('minimum')} />:
{conditional.conditions.map((cond, i) => {
return (
<div className="section" key={i}>
<ConditionalEditor {...this.props} conditional={cond} onChange={this.props.onChange(`conditions.${i}`)} />
<div className="section" key={i}>
<ConditionalEditor {...this.props} conditional={cond} onChange={onChange(`[${i}]`)} />
<a className="editable-text delete-button" onClick={() => onChange(`[${i}]`)({val: {id: null}})}>remove</a>
</div>
)
})}
<a className='editable-text add-button' onClick={() => onChange(`[${conditional.conditions.length}]`)({val: {id: getTemplate('Type.Condition.Age')}})}>+</a>
</label>
);
}
Expand All @@ -589,17 +598,20 @@ class AtMost extends Component<Props> {

render() {
let conditional = ((this.props.conditional: any): AtMostConditional);
let onChange = this.props.onChange('conditions');
return (
<label> At Most
<RIENumber className='editable-text' value={conditional.maximum||0} propName='maximum' change={this.props.onChange('maximum')} />:

{conditional.conditions.map((cond, i) => {
return (
<div className="section" key={i}>
<ConditionalEditor {...this.props} conditional={cond} onChange={this.props.onChange(`conditions.${i}`)} />
<div className="section" key={i}>
<ConditionalEditor {...this.props} conditional={cond} onChange={onChange(`[${i}]`)} />
<a className="editable-text delete-button" onClick={() => onChange(`[${i}]`)({val: {id: null}})}>remove</a>
</div>
)
})}
<a className='editable-text add-button' onClick={() => onChange(`[${conditional.conditions.length}]`)({val: {id: getTemplate('Type.Condition.Age')}})}>+</a>
</label>
);
}
Expand Down
112 changes: 112 additions & 0 deletions src/reducers/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,117 @@ const orphanStateWarnings = (module) => {

}


const GROUPED_CONDITION_TYPES = ['And', 'Or', 'At Least', 'At Most', 'Not'];

/**
* Look for "And", "At Least", "At Most", "Or" type conditionals
* and make sure the numbers make sense.
*/
const groupedConditionalWarnings = (module) => {
debugger;
const warnings = [];
Object.keys(module.states).forEach(stateName => {
const state = module.states[stateName];

if (state.type == 'Guard') {
if (GROUPED_CONDITION_TYPES.includes(state.allow.condition_type)) {
const message = checkGroupedCondition(state.allow);
if (message) {
warnings.push({stateName, message});
}
}
}

if (state.conditional_transition) {
state.conditional_transition.forEach(transition => {
if (transition.condition && GROUPED_CONDITION_TYPES.includes(transition.condition.condition_type)) {
const message = checkGroupedCondition(transition.condition);
if (message) {
warnings.push({stateName, message});
}
}
});
} else if (state.complex_transition) {
state.complex_transition.forEach(transition => {
if (transition.condition && GROUPED_CONDITION_TYPES.includes(transition.condition.condition_type)) {
const message = checkGroupedCondition(transition.condition);
if (message) {
warnings.push({stateName, message});
}
}
});
}
});
return warnings;
}

const checkGroupedCondition = (condition) => {
switch(condition.condition_type) {
case 'And':
if (condition.conditions.length < 2) {
return "'And' condition should have at minimum 2 sub-conditions";
} else {
for (const subcondition of condition.conditions) {
if (GROUPED_CONDITION_TYPES.includes(subcondition.condition_type)) {
const message = checkGroupedCondition(subcondition);
if (message) {
return message;
}
}
}
}
break;
case 'Or':
if (condition.conditions.length < 2) {
return "'Or' condition should have at minimum 2 sub-conditions";
} else {
for (const subcondition of condition.conditions) {
if (GROUPED_CONDITION_TYPES.includes(subcondition.condition_type)) {
const message = checkGroupedCondition(subcondition);
if (message) {
return message;
}
}
}
}
break;
case 'At Least':
if (condition.conditions.length <= condition.minimum) {
return "'At Least' condition should have more sub-conditions than the selected minimum";
} else {
for (const subcondition of condition.conditions) {
if (GROUPED_CONDITION_TYPES.includes(subcondition.condition_type)) {
const message = checkGroupedCondition(subcondition);
if (message) {
return message;
}
}
}
}
break;
case 'At Most':
if (condition.conditions.length <= condition.maximum) {
return "'At Most' condition should have more sub-conditions than the selected maximum";
} else {
for (const subcondition of condition.conditions) {
if (GROUPED_CONDITION_TYPES.includes(subcondition.condition_type)) {
const message = checkGroupedCondition(subcondition);
if (message) {
return message;
}
}
}
}
break;
case 'Not':
if (GROUPED_CONDITION_TYPES.includes(condition.condition.condition_type)) {
return checkGroupedCondition(condition.condition);
}
break;
}
}

const libraryModuleCodes = (modules) => {
const libraryModuleCodes = {};

Expand Down Expand Up @@ -403,6 +514,7 @@ export default (state = initialState, action) => {
...placeholderCodeWarnings(action.data.module),
...tableTransitionWarnings(action.data.module),
...gmfVersionWarnings(action.data.module),
...groupedConditionalWarnings(action.data.module),
...telemedicineWarnings(action.data.module)
];

Expand Down