Просмотр исходного кода

fix: using enum values shouldn't create unknown blocks

also updated enum schema
Gabriel Horner 2 лет назад
Родитель
Сommit
8eeeef536b

+ 10 - 2
deps/db/src/logseq/db/malli_schema.cljs

@@ -143,7 +143,16 @@
        ;; For any types except for :checkbox :default :template :enum
        [:cardinality {:optional true} [:enum :one :many]]
        ;; Just for :enum type
-       [:enum-config {:optional true} :map]
+       [:enum-config {:optional true}
+        [:map {:closed false}
+         [:values
+          [:map-of
+           :uuid [:map {:closed false}
+                  [:name :string]
+                  [:description :string]]]]
+         [:order [:vector :uuid]]]]
+       ;; Just for :enum
+       [:position {:optional true} :string]
        ;; :template uses :sequential and :page uses :set.
        ;; Should :template should use :set?
        [:classes {:optional true} [:or
@@ -210,7 +219,6 @@
    object-block])
 
 ;; TODO: invalid macros should not generate unknown
-;; TODO: Creating an enum property should not generate unknown
 (def unknown-block
   "A block that has an unknown type. This type of block should be removed when
   the above TODOs have been addressed and the frontend ensures no unknown blocks

+ 6 - 2
src/main/frontend/handler/db_based/property.cljs

@@ -189,14 +189,18 @@
 
                                       :else
                                       v*)
-                      ;; don't modify maps
+                          ;; don't modify maps
                           new-value (if (or (sequential? new-value) (set? new-value))
                                       (if (= :coll property-type)
                                         (vec (remove string/blank? new-value))
                                         (set (remove string/blank? new-value)))
                                       new-value)
                           block-properties (assoc properties property-uuid new-value)
-                          refs (outliner-core/rebuild-block-refs block block-properties)]
+                          refs (outliner-core/rebuild-block-refs block
+                                                                 block-properties
+                                                                 ;; enum values aren't actually blocks and shouldn't
+                                                                 ;; be referenced because they create garbage unknown blocks
+                                                                 :no-property-values? (= :enum property-type))]
                       (db/transact! repo
                                     [[:db/retract (:db/id block) :block/refs]
                                      {:block/uuid (:block/uuid block)

+ 2 - 2
src/main/frontend/modules/outliner/core.cljs

@@ -181,7 +181,7 @@
     (reset! (:editor/create-page? @state/state) false)))
 
 (defn rebuild-block-refs
-  [block new-properties & {:keys [skip-content-parsing?]}]
+  [block new-properties & {:keys [skip-content-parsing? no-property-values?]}]
   (let [property-key-refs (keys new-properties)
         property-value-refs (->> (vals new-properties)
                                  (mapcat (fn [v]
@@ -200,7 +200,7 @@
 
                                              :else
                                              nil))))
-        property-refs (->> (concat property-key-refs property-value-refs)
+        property-refs (->> (concat property-key-refs (when-not no-property-values? property-value-refs))
                            (map (fn [id-or-map] (if (uuid? id-or-map) {:block/uuid id-or-map} id-or-map))))
         content-refs (when-not skip-content-parsing?
                        (some-> (:block/content block) block/extract-refs-from-text))]