Browse Source

fix(regression): checkbox can't have :many cardinality

Also fixed property type enabled in publishing and fixed lint
Gabriel Horner 1 year ago
parent
commit
714130cecd

+ 10 - 3
deps/db/src/logseq/db/frontend/property/type.cljs

@@ -22,13 +22,20 @@
   "Valid property :type for closed values"
   #{:default :number :url})
 
-(def position-property-types
-  "Valid property :type for position"
-  #{:default :number :date :checkbox :url :node})
+(def cardinality-property-types
+  "Valid property types that can change cardinality"
+  #{:default :number :url :date :node})
+
+(assert (set/subset? cardinality-property-types (set user-built-in-property-types))
+        "All closed value types are valid property types")
 
 (assert (set/subset? closed-value-property-types (set user-built-in-property-types))
         "All closed value types are valid property types")
 
+(def position-property-types
+  "Valid property :type for position"
+  #{:default :number :date :checkbox :url :node})
+
 (def original-value-ref-property-types
   "Property value ref types where the refed entity stores its value in
   :property.value/content e.g. :number is stored as a number. new value-ref-property-types

+ 7 - 7
src/main/frontend/components/property/config.cljs

@@ -26,8 +26,7 @@
             [frontend.components.select :as select]
             [frontend.db.model :as model]
             [frontend.handler.page :as page-handler]
-            [frontend.ui :as ui]
-            [frontend.components.svg :as svg]))
+            [frontend.ui :as ui]))
 
 (defn- re-init-commands!
   "Update commands after task status and priority's closed values has been changed"
@@ -490,10 +489,10 @@
     [:<>
      (dropdown-editor-menuitem {:icon :pencil :title "Property name" :desc [:span.flex.items-center.gap-1 icon title]
                                 :submenu-content (fn [ops] (name-edit-pane property (assoc ops :disabled? disabled?)))})
-     (let [disabled? (or (ldb/built-in? property) (and property-type (seq values)))]
+     (let [disabled?' (or disabled? (and property-type (seq values)))]
        (dropdown-editor-menuitem {:icon :letter-t
                                   :title "Property type"
-                                  :desc (if disabled?
+                                  :desc (if disabled?'
                                           (ui/tippy {:html        [:div.w-96
                                                                    "The type of this property is locked once you start using it. This is to make sure all your existing information stays correct if the property type is changed later. To unlock, all uses of a property must be deleted."]
                                                      :class       "tippy-hover ml-2"
@@ -501,7 +500,7 @@
                                                      :disabled    false}
                                                     (str property-type-label'))
                                           (str property-type-label'))
-                                  :disabled? disabled?
+                                  :disabled? disabled?'
                                   :submenu-content (fn [ops]
                                                      (property-type-sub-pane property ops))}))
 
@@ -513,7 +512,7 @@
                                                      [:div.px-4
                                                       (class-select property {:default-open? false})])}))
 
-     (when enable-closed-values? (empty? (:property/schema.classes property))
+     (when enable-closed-values?
            (let [values (:property/closed-values property)]
              (dropdown-editor-menuitem {:icon :list :title "Available choices"
                                         :desc (when (seq values) (str (count values) " choices"))
@@ -521,7 +520,8 @@
 
      (let [many? (db-property/many? property)]
        (dropdown-editor-menuitem {:icon :checks :title "Multiple values"
-                                  :toggle-checked? many? :disabled? disabled?
+                                  :toggle-checked? many?
+                                  :disabled? (or disabled? (not (contains? db-property-type/cardinality-property-types property-type)))
                                   :on-toggle-checked-change #(db-property-handler/upsert-property! (:db/ident property)
                                                                                                    (assoc property-schema :cardinality (if many? :one :many)) {})}))