Răsfoiți Sursa

fix: recycled/deleted page can't be restored by user

When a user deletes a page and then restores it by creating it again with cmd-k,
the page wasn't restored. The previously recycled page and its block are
now restored when the page is re-created
Gabriel Horner 1 zi în urmă
părinte
comite
963cdf9234

+ 2 - 2
deps/outliner/src/logseq/outliner/page.cljs

@@ -408,7 +408,7 @@
 
 (defn create!
   [conn title opts]
-  (let [{:keys [tx-meta tx-data title' page-uuid]} (create @conn title opts)]
+  (let [{:keys [tx-meta tx-data title page-uuid]} (create @conn title opts)]
     (when (seq tx-data)
       (ldb/transact! conn tx-data tx-meta))
-    [title' page-uuid]))
+    [title page-uuid]))

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

@@ -66,7 +66,7 @@
          :else
          (when-not (string/blank? title')
            (p/let [existing-page (when-not class? (db/get-page title'))]
-             (if existing-page
+             (if (and existing-page (not (ldb/recycled? existing-page)))
                existing-page
                (p/let [options' (cond-> (update options :tags concat (:block/tags parsed-result))
                                   (nil? (:split-namespace? options))

+ 36 - 0
src/test/frontend/handler/common/page_test.cljs

@@ -0,0 +1,36 @@
+(ns frontend.handler.common.page-test
+  (:require [clojure.test :refer [async is use-fixtures]]
+            [datascript.core :as d]
+            [frontend.db :as db]
+            [frontend.handler.common.page :as page-common-handler]
+            [frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
+            [logseq.db :as ldb]
+            [logseq.db.test.helper :as db-test]
+            [logseq.outliner.page :as outliner-page]
+            [promesa.core :as p]))
+
+(use-fixtures :each
+  {:before (fn []
+             (async done
+                    (test-helper/start-test-db!)
+                    (done)))
+   :after test-helper/destroy-test-db!})
+
+(deftest-async create-page-restores-recycled-page
+  (test-helper/load-test-files [{:page {:block/title "foo"}
+                                 :blocks [{:block/title "child block"}]}])
+  (p/let [conn (db/get-db test-helper/test-db false)
+          page (db-test/find-page-by-title @conn "foo")
+          page-uuid (:block/uuid page)
+          _ (outliner-page/delete! conn page-uuid {})
+          recycled-page (d/entity @conn [:block/uuid page-uuid])
+          _ (is (ldb/recycled? recycled-page)
+                "Page should be recycled after deletion")
+          restored-page (page-common-handler/<create! "foo" {:redirect? false})]
+    (is (= (:db/id restored-page) (:db/id page))
+        "create! should return the restored page")
+    (let [page' (d/entity @conn [:block/uuid page-uuid])]
+      (is (not (ldb/recycled? page'))
+          "Page should no longer be recycled after re-creation")
+      (is (= "foo" (get-in (db-test/find-block-by-content @conn "child block") [:block/page :block/title]))
+          "Restored page still has its block(s)"))))