Skip to content

Commit

Permalink
Add default value to rule dropdown selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ckitsanelis committed Dec 21, 2023
1 parent 34f7d74 commit c3be9d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
25 changes: 16 additions & 9 deletions src/viewer/rules/FlagRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export default class FlagRule extends Rule {
<VSCodeDropdown
style={{ width: "100%", marginBottom: "2px" }}
value={sub.Column}
key="Dropdown"
key="editSubconditionColumn"
onChange={(e) => editSubcondition(columnIndex, s_i, "Column", e.target.value)}
>
{allColumns.map((col, col_i) => (
Expand All @@ -299,7 +299,7 @@ export default class FlagRule extends Rule {
<VSCodeDropdown
style={{ width: "100%" }}
value={sub.Operation}
key="Dropdown"
key="editSubconditionOperation"
onChange={(e) => editSubcondition(columnIndex, s_i, "Operation", e.target.value)}
>
<VSCodeOption key="0" value="contains">
Expand All @@ -325,25 +325,32 @@ export default class FlagRule extends Rule {
</VSCodeOption>
</VSCodeDropdown>
);

let isDropdown = false;
let dropdownOptions: string[] = [];
if (user_columns.includes(sub.Column)) {
const dropdownRule = rules.filter(r => r.column === sub.Column)[0];
if (dropdownRule.ruleType === 'Flag rule') {
if (dropdownRule.ruleType === "Flag rule") {
let dropdownFlagRule = dropdownRule as FlagRule;
dropdownOptions = dropdownFlagRule.flags.map(f => f.name);
dropdownOptions.push(dropdownFlagRule.defaultValue);
if (dropdownFlagRule.flagType === "User Defined" && dropdownOptions.length > 0)
isDropdown = true;
}
else if (dropdownRule.ruleType === 'State based rule') {
else if (dropdownRule.ruleType === "State based rule") {
let dropdownStateRule = dropdownRule as StateBasedRule;
dropdownOptions = dropdownStateRule.ruleStates.map(s => s.name)
dropdownOptions = dropdownStateRule.ruleStates.map(s => s.name);
if (dropdownOptions.length > 0)
isDropdown = true;
}
}
console.log(dropdownOptions)
if (dropdownOptions.length === 0 || dropdownOptions[0] === '') {
dropdownOptions = dropdownOptions.filter(opt => opt != "")
if (!isDropdown) {
setMap.push(
<VSCodeTextField
style={{ width: "100%" }}
value={sub.Text}
key="Text"
key="editSubconditionText"
onInput={(e) => editSubcondition(columnIndex, s_i, "Text", e.target.value)}
/>,
);
Expand All @@ -353,7 +360,7 @@ export default class FlagRule extends Rule {
<VSCodeDropdown
style={{ width: "100%" }}
value={sub.Text}
key="Text"
key="editSubconditionTextDropdown"
onChange={(e) => editSubcondition(columnIndex, s_i, "Text", e.target.value)}
>
{dropdownOptions.map((option, optionIndex) => (
Expand Down
24 changes: 16 additions & 8 deletions src/viewer/rules/StateBasedRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default class StateBasedRule extends Rule {
<VSCodeDropdown
style={{ width: "100%", marginBottom: "2px" }}
value={r.Column}
key="Dropdown"
key="editTransitionColumn"
onChange={(e) => editTransition(transitionIndex, c_i, "Column", e.target.value)}
>
{allColumns.map((col, col_i) => (
Expand All @@ -259,7 +259,7 @@ export default class StateBasedRule extends Rule {
<VSCodeDropdown
style={{ width: "100%" }}
value={r.Operation}
key="Operators"
key="editTransitionOperation"
onChange={(e) => editTransition(transitionIndex, c_i, "Operation", e.target.value)}
>
<VSCodeOption key="0" value="contains">
Expand All @@ -285,25 +285,33 @@ export default class StateBasedRule extends Rule {
</VSCodeOption>
</VSCodeDropdown>
);

let isDropdown = false;
let dropdownOptions: string[] = [];
if (user_columns.includes(r.Column)) {
const dropdownRule = rules.filter(rule => rule.column === r.Column)[0];
if (dropdownRule.ruleType === 'Flag rule') {
if (dropdownRule.ruleType === "Flag rule") {
let dropdownFlagRule = dropdownRule as FlagRule;
dropdownOptions = dropdownFlagRule.flags.map(f => f.name);
dropdownOptions.push(dropdownFlagRule.defaultValue);
if (dropdownFlagRule.flagType === "User Defined" && dropdownOptions.length > 0)
isDropdown = true;
}
else if (dropdownRule.ruleType === 'State based rule') {
else if (dropdownRule.ruleType === "State based rule") {
let dropdownStateRule = dropdownRule as StateBasedRule;
dropdownOptions = dropdownStateRule.ruleStates.map(s => s.name)
dropdownOptions = dropdownStateRule.ruleStates.map(s => s.name);
if (dropdownOptions.length > 0)
isDropdown = true;
}
}
if (dropdownOptions.length === 0 || dropdownOptions[0] === '') {
dropdownOptions = dropdownOptions.filter(opt => opt != "")
if (!isDropdown) {
setMap.push(
<VSCodeTextField
style={{ width: "100%" }}
value={r.Text}
onInput={(e) => editTransition(transitionIndex, c_i, "Text", e.target.value)}
key="Text"
key="editTransitionText"
/>
);
}
Expand All @@ -312,7 +320,7 @@ export default class StateBasedRule extends Rule {
<VSCodeDropdown
style={{ width: "100%" }}
value={r.Text}
key="Text"
key="editTransitionTextDropdown"
onChange={(e) => editTransition(transitionIndex, c_i, "Text", e.target.value)}
>
{dropdownOptions.map((option, optionIndex) => (
Expand Down

0 comments on commit c3be9d9

Please sign in to comment.