Jelajahi Sumber

fix: delete alias page cause wrong alias relations

rcmerci 4 tahun lalu
induk
melakukan
3ba36da8c9
2 mengubah file dengan 25 tambahan dan 1 penghapusan
  1. 14 0
      src/main/frontend/db_schema.cljs
  2. 11 1
      src/main/frontend/handler/page.cljs

+ 14 - 0
src/main/frontend/db_schema.cljs

@@ -147,3 +147,17 @@
     :block/updated-at
     }
   )
+
+
+;;; use `(map [:db.fn/retractAttribute <id> <attr>] retract-page-attributes)`
+;;; to remove attrs to make the page as it's just created and no file attached to it
+(def retract-page-attributes
+  #{:block/created-at
+    :block/updated-at
+    :block/file
+    :block/format
+    :block/content
+    :block/properties
+    :block/alias
+    :block/tags
+    :block/unordered})

+ 11 - 1
src/main/frontend/handler/page.cljs

@@ -20,6 +20,7 @@
             [frontend.modules.outliner.tree :as outliner-tree]
             [frontend.commands :as commands]
             [frontend.date :as date]
+            [frontend.db-schema :as db-schema]
             [clojure.walk :as walk]
             [frontend.git :as git]
             [frontend.fs :as fs]
@@ -179,7 +180,16 @@
                (p/catch (fn [err]
                           (js/console.error "error: " err))))))
 
-          (db/transact! [[:db.fn/retractEntity [:block/name page-name]]])
+
+          ;; not removing entire entity, because :block/alias still use this entity.
+          ;; so just delete related file and make remove most page-related attrs.
+          ;; (db/transact! [[:db.fn/retractEntity [:block/name page-name]]])
+
+          (when-let [id (:db/id (db/entity [:block/name page-name]))]
+            (let [txs (mapv (fn [attribute]
+                             [:db/retract id attribute])
+                           db-schema/retract-page-attributes)]
+              (db/transact! txs)))
 
           (ok-handler))))))