diff --git a/src/viewer/rules/Dialogs/FlagsDialog.tsx b/src/viewer/rules/Dialogs/FlagsDialog.tsx index 0a5a50a..5e102c1 100644 --- a/src/viewer/rules/Dialogs/FlagsDialog.tsx +++ b/src/viewer/rules/Dialogs/FlagsDialog.tsx @@ -98,7 +98,7 @@ export default class FlagsDialog extends React.Component { onDialogClick(isClose: boolean) { const ruleIndex = this.state.selectedRule; if (ruleIndex !== -1) { - const rule = this.state.rules[ruleIndex].reset(); + const rule = FlagRule.cleanConditions(this.state.rules[ruleIndex].reset()); this.updateRule(rule, ruleIndex); } this.setState({ selectedRule: -1, showEdit: false }, () => { diff --git a/src/viewer/rules/Dialogs/StatesDialog.tsx b/src/viewer/rules/Dialogs/StatesDialog.tsx index b032d94..be87931 100644 --- a/src/viewer/rules/Dialogs/StatesDialog.tsx +++ b/src/viewer/rules/Dialogs/StatesDialog.tsx @@ -85,7 +85,7 @@ export default class StatesDialog extends React.Component { onDialogClick(isClose: boolean) { const ruleIndex = this.state.selectedRule; if (ruleIndex !== -1) { - const rule = this.state.rules[ruleIndex].reset(); + const rule = StateBasedRule.cleanConditions(this.state.rules[ruleIndex].reset()); this.updateRule(rule, ruleIndex); } this.setState({ selectedRule: -1, showEdit: false }, () => { diff --git a/src/viewer/rules/FlagRule.tsx b/src/viewer/rules/FlagRule.tsx index 464d484..08581fa 100644 --- a/src/viewer/rules/FlagRule.tsx +++ b/src/viewer/rules/FlagRule.tsx @@ -122,6 +122,19 @@ export default class FlagRule extends Rule { ); } + static cleanConditions(rule: Rule) { + const flagRule = rule as FlagRule; + let newFlags = flagRule.flags; + for (let i = 0; i < newFlags.length; i++) { + for (let j = 0; j < newFlags[i].conditions.length; j++) + newFlags[i].conditions[j] = newFlags[i].conditions[j].filter(subCondition => ((subCondition.Column !== "") && (subCondition.Text !== ""))) + newFlags[i].conditions = newFlags[i].conditions.filter(li => li.length !== 0) + } + // Could also remove flags without any conditions + // newFlags = newFlags.filter(i => i.conditions.length !== 0) + return flagRule.setFlags(newFlags); + } + public renderEdit( onEdit: (newRule: Rule) => void, keyWidth: string, diff --git a/src/viewer/rules/StateBasedRule.tsx b/src/viewer/rules/StateBasedRule.tsx index 2fadb9b..c754375 100644 --- a/src/viewer/rules/StateBasedRule.tsx +++ b/src/viewer/rules/StateBasedRule.tsx @@ -125,6 +125,19 @@ export default class StateBasedRule extends Rule { ); } + static cleanConditions(rule: Rule) { + const stateRule = rule as StateBasedRule; + let newStates = stateRule.ruleStates; + for (let i = 0; i < newStates.length; i++) { + for (let j = 0; j < newStates[i].transitions.length; j++) { + for (let k = 0; k < newStates[i].transitions[j].conditions.length; k++) + newStates[i].transitions[j].conditions[k] = newStates[i].transitions[j].conditions[k].filter(subCondition => ((subCondition.Column !== "") && (subCondition.Text !== ""))) + newStates[i].transitions[j].conditions = newStates[i].transitions[j].conditions.filter(li => li.length !== 0) + } + } + return stateRule.setStates(newStates, stateRule.initialStateIndex); + } + public renderEdit( onEdit: (newRule: Rule) => void, keyWidth: string,