Simplify logic for determine default visibility for a conditional UI component

This commit is contained in:
Andrew Kingston 2021-07-26 13:16:45 +01:00
parent 93d6da7ebe
commit 73643793c9
1 changed files with 4 additions and 7 deletions

View File

@ -159,20 +159,17 @@
} }
// Default visible to false if there is a show condition // Default visible to false if there is a show condition
let nextVisible = true let nextVisible = !conditions.find(condition => condition.action === "show")
for (let condition of conditions) {
if (condition.action === "show") {
nextVisible = false
}
}
// Execute conditions and determine settings and visibility changes
const activeConditions = getActiveConditions(conditions) const activeConditions = getActiveConditions(conditions)
const result = reduceConditionActions(activeConditions) const result = reduceConditionActions(activeConditions)
conditionalSettings = result.settingUpdates
if (result.visible != null) { if (result.visible != null) {
nextVisible = result.visible nextVisible = result.visible
} }
// Update state from condition results
conditionalSettings = result.settingUpdates
visible = nextVisible visible = nextVisible
} }
</script> </script>