From d218db4e6f3997bf1b29429190c0b98ab9c192d4 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Wed, 29 Nov 2023 17:15:35 -0500 Subject: [PATCH] fix: fixes bug with unusuable :default property Part of LOG-2953. Also fixes bug when a new property first displays configure modal and incorrectly shows cardinality for :default property --- deps/db/.carve/ignore | 2 ++ deps/db/src/logseq/db/frontend/property/type.cljs | 3 +++ src/main/frontend/components/property.cljs | 11 ++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/deps/db/.carve/ignore b/deps/db/.carve/ignore index 953cfea20b..eaae9a2143 100644 --- a/deps/db/.carve/ignore +++ b/deps/db/.carve/ignore @@ -10,3 +10,5 @@ logseq.db.frontend.rules/extract-rules logseq.db.frontend.property.type/type-or-closed-value? ;; Internal API logseq.db.frontend.rules/rules +;; API +logseq.db.frontend.property.type/property-types-with-cardinality diff --git a/deps/db/src/logseq/db/frontend/property/type.cljs b/deps/db/src/logseq/db/frontend/property/type.cljs index 44490d3905..01f0b0045d 100644 --- a/deps/db/src/logseq/db/frontend/property/type.cljs +++ b/deps/db/src/logseq/db/frontend/property/type.cljs @@ -97,6 +97,9 @@ :coll coll? :any some?}) +(def property-types-with-cardinality + #{:number :date :url :page}) + (def property-types-with-db "Property types whose validation fn requires a datascript db" #{:date :page :template}) diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 93b6100a34..b956f19a8c 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -188,11 +188,16 @@ [:div.col-span-2 (ui/select schema-types (fn [_e v] - (let [type (keyword (string/lower-case v))] - (swap! *property-schema assoc :type type) + (let [type (keyword (string/lower-case v)) + update-schema-fn (comp + (if (contains? db-property-type/property-types-with-cardinality type) + identity + #(dissoc % :cardinality)) + #(assoc % :type type))] + (swap! *property-schema update-schema-fn) (components-pu/update-property! property @*property-name @*property-schema))))]))] - (when-not (contains? #{:checkbox :default :template} (:type @*property-schema)) + (when (contains? db-property-type/property-types-with-cardinality (:type @*property-schema)) [:div.grid.grid-cols-4.gap-1.items-center.leading-8 [:label "Multiple values:"] (let [many? (boolean (= :many (:cardinality @*property-schema)))]