From afd373ffeefaf6b8992b449d8ab54d4e6b3a46ec Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 5 Mar 2024 17:07:41 +0100 Subject: [PATCH] :sparkles: Simplify implementation of d/name --- common/src/app/common/data.cljc | 21 +++++++++---------- .../sidebar/options/menus/constraints.cljs | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 0dcf23e7e..736803631 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -716,20 +716,19 @@ (defn name "Improved version of name that won't fail if the input is not a keyword" - ([maybe-keyword] (name maybe-keyword nil)) - ([maybe-keyword default-value] - (cond - (keyword? maybe-keyword) - (c/name maybe-keyword) + [maybe-keyword] + (cond + (nil? maybe-keyword) + nil - (string? maybe-keyword) - maybe-keyword + (keyword? maybe-keyword) + (c/name maybe-keyword) - (nil? maybe-keyword) default-value + (string? maybe-keyword) + maybe-keyword - :else - (or default-value - (str maybe-keyword))))) + :else + (str maybe-keyword))) (defn prefix-keyword "Given a keyword and a prefix will return a new keyword with the prefix attached diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/constraints.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/constraints.cljs index 44d5182ec..538b4f960 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/constraints.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/constraints.cljs @@ -209,12 +209,12 @@ [:div {:class (stl/css :contraints-selects)} [:div {:class (stl/css :horizontal-select)} [:& select - {:default-value (d/name constraints-h "scale") + {:default-value (d/nilv (d/name constraints-h) "scale") :options options-h :on-change on-constraint-h-select-changed}]] [:div {:class (stl/css :vertical-select)} [:& select - {:default-value (d/name constraints-v "scale") + {:default-value (d/nilv (d/name constraints-v) "scale") :options options-v :on-change on-constraint-v-select-changed}]] (when first-level?