From caccba8fd8cf66d03c3d068ffa514f12b3276861 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 26 Jul 2021 13:16:45 +0100 Subject: [PATCH] Simplify logic for determine default visibility for a conditional UI component --- packages/client/src/components/Component.svelte | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index 8969395490..8c7437e523 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -159,20 +159,17 @@ } // Default visible to false if there is a show condition - let nextVisible = true - for (let condition of conditions) { - if (condition.action === "show") { - nextVisible = false - } - } + let nextVisible = !conditions.find(condition => condition.action === "show") + // Execute conditions and determine settings and visibility changes const activeConditions = getActiveConditions(conditions) const result = reduceConditionActions(activeConditions) - conditionalSettings = result.settingUpdates if (result.visible != null) { nextVisible = result.visible } + // Update state from condition results + conditionalSettings = result.settingUpdates visible = nextVisible }