From 56a81f9671a48e630c9091cbe7a96369cbd7bfdb Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Tue, 2 Jan 2024 15:10:39 -0500 Subject: [PATCH] fix: allow UI and validation to know what property types have :position this is done by configuring user-built-in-allowed-schema-attributes and then using the helper fn to check it Fix LOG-2955 --- deps/db/src/logseq/db/frontend/property/type.cljs | 7 ++----- src/main/frontend/components/property.cljs | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/deps/db/src/logseq/db/frontend/property/type.cljs b/deps/db/src/logseq/db/frontend/property/type.cljs index 2cf0e2d68..0437f0517 100644 --- a/deps/db/src/logseq/db/frontend/property/type.cljs +++ b/deps/db/src/logseq/db/frontend/property/type.cljs @@ -21,17 +21,14 @@ "Valid schema :type for closed values" #{:default :number :url :date :page}) -(def closed-value-property-position-types - "Valid schema :type for closed values" - #{:default :number :url}) - (assert (set/subset? closed-value-property-types (set user-built-in-property-types)) "All closed value types are valid property types") (def ^:private user-built-in-allowed-schema-attributes "Map of types to their set of allowed :schema attributes" (merge-with into - (zipmap closed-value-property-types (repeat #{:values :position})) + (zipmap closed-value-property-types (repeat #{:values})) + (zipmap #{:default :number :url} (repeat #{:position})) {:number #{:cardinality} :date #{:cardinality} :url #{:cardinality} diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index aa156dfdf..23554f989 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -141,8 +141,7 @@ class? (contains? (:block/type block) "class") property-type (get-in property [:block/schema :type]) save-property-fn (fn [] (components-pu/update-property! property @*property-name @*property-schema)) - enable-closed-values? (contains? db-property-type/closed-value-property-types (or property-type :default)) - enable-position? (contains? db-property-type/closed-value-property-position-types (or property-type :default))] + enable-closed-values? (contains? db-property-type/closed-value-property-types (or property-type :default))] [:div.property-configure.flex.flex-1.flex-col {:on-mouse-down #(state/set-state! :editor/mouse-down-from-property-configure? true) :on-mouse-up #(state/set-state! :editor/mouse-down-from-property-configure? nil)} @@ -252,7 +251,7 @@ (closed-value/choices property *property-name *property-schema opts)]]) (when (and enable-closed-values? - enable-position? + (db-property-type/property-type-allows-schema-attribute? (:type @*property-schema) :position) (seq (:values @*property-schema))) (let [position (:position @*property-schema) choices (map