Skip to content

Commit

Permalink
Merge pull request #60 from TNO/bugfix-conditions-empty
Browse files Browse the repository at this point in the history
Discard empty conditions and subconditions
  • Loading branch information
TuenDeBuis authored Oct 3, 2023
2 parents 532397c + ac6e8a8 commit 29df1fc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/viewer/rules/Dialogs/FlagsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class FlagsDialog extends React.Component<Props, State> {
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 }, () => {
Expand Down
2 changes: 1 addition & 1 deletion src/viewer/rules/Dialogs/StatesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class StatesDialog extends React.Component<Props, State> {
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 }, () => {
Expand Down
13 changes: 13 additions & 0 deletions src/viewer/rules/FlagRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/viewer/rules/StateBasedRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 29df1fc

Please sign in to comment.