Browse Source

fix: refs to hidden block property values doesn't make sense

part of LOG-2819
Gabriel Horner 1 year ago
parent
commit
ade1af5874

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

@@ -127,7 +127,7 @@
                 (upsert-property! repo k-name (assoc property-schema :type property-type)
                                   {:property-uuid property-uuid})
                 (let [block-properties (assoc properties property-uuid values')
-                      refs (outliner-core/rebuild-block-refs block block-properties)]
+                      refs (outliner-core/rebuild-block-refs repo block block-properties)]
                   (db/transact! repo
                                 [[:db/retract (:db/id block) :block/refs]
                                  {:block/uuid (:block/uuid block)
@@ -222,7 +222,8 @@
                                         (set (remove string/blank? new-value)))
                                       new-value)
                           block-properties (assoc properties property-uuid new-value)
-                          refs (outliner-core/rebuild-block-refs block
+                          refs (outliner-core/rebuild-block-refs repo
+                                                                 block
                                                                  block-properties)]
                       (db/transact! repo
                                     [[:db/retract (:db/id block) :block/refs]
@@ -333,7 +334,7 @@
                                 nil))
                          properties (:block/properties block)
                          block-properties (assoc properties property-uuid v*)
-                         refs (outliner-core/rebuild-block-refs block block-properties)]
+                         refs (outliner-core/rebuild-block-refs repo block block-properties)]
                      [[:db/retract (:db/id block) :block/refs]
                       {:block/uuid (:block/uuid block)
                        :block/properties block-properties
@@ -353,7 +354,7 @@
                    (let [origin-properties (:block/properties block)]
                      (when (contains? (set (keys origin-properties)) property-uuid)
                        (let [properties' (dissoc origin-properties property-uuid)
-                             refs (outliner-core/rebuild-block-refs block properties')
+                             refs (outliner-core/rebuild-block-refs repo block properties')
                              property (db/entity [:block/uuid property-uuid])
                              value (get origin-properties property-uuid)
                              block-value? (and (= :default (get-in property [:block/schema :type] :default))
@@ -422,7 +423,7 @@
                     properties' (update properties property-id
                                         (fn [col]
                                           (set (remove #{property-value} col))))
-                    refs (outliner-core/rebuild-block-refs block properties')]
+                    refs (outliner-core/rebuild-block-refs repo block properties')]
                 (db/transact! repo
                               [[:db/retract (:db/id block) :block/refs]
                                {:block/uuid (:block/uuid block)

+ 9 - 6
src/main/frontend/modules/outliner/core.cljs

@@ -192,7 +192,7 @@
     (reset! (:editor/create-page? @state/state) false)))
 
 (defn rebuild-block-refs
-  [block new-properties & {:keys [skip-content-parsing?]}]
+  [repo block new-properties & {:keys [skip-content-parsing?]}]
   (let [property-key-refs (keys new-properties)
         property-value-refs (->> (vals new-properties)
                                  (mapcat (fn [v]
@@ -201,7 +201,10 @@
                                              v
 
                                              (uuid? v)
-                                             [v]
+                                             (if (get-in (db/entity repo [:block/uuid v]) [:block/metadata :created-from-property])
+                                               ;; don't reference hidden block property values
+                                               []
+                                               [v])
 
                                              (and (coll? v) (string? (first v)))
                                              (mapcat block/extract-refs-from-text v)
@@ -219,9 +222,9 @@
     (concat property-refs content-refs)))
 
 (defn- rebuild-refs
-  [txs-state block m]
-  (when (config/db-based-graph? (state/get-current-repo))
-    (let [refs (->> (rebuild-block-refs block (:block/properties block)
+  [repo txs-state block m]
+  (when (config/db-based-graph? repo)
+    (let [refs (->> (rebuild-block-refs repo block (:block/properties block)
                                         :skip-content-parsing? true)
                     (concat (:block/refs m)))]
       (swap! txs-state (fn [txs] (concat txs [{:db/id (:db/id block)
@@ -347,7 +350,7 @@
 
       (create-object-when-save txs-state block-entity m structured-tags?)
 
-      (rebuild-refs txs-state block-entity m)
+      (rebuild-refs repo txs-state block-entity m)
 
       this))