mirror of
https://github.com/logseq/logseq.git
synced 2026-05-21 19:24:17 +00:00
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
This commit is contained in:
committed by
Tienson Qin
parent
f504563f0e
commit
eb09f0c30f
4
deps/outliner/src/logseq/outliner/page.cljs
vendored
4
deps/outliner/src/logseq/outliner/page.cljs
vendored
@@ -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]))
|
||||
|
||||
@@ -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
src/test/frontend/handler/common/page_test.cljs
Normal file
36
src/test/frontend/handler/common/page_test.cljs
Normal file
@@ -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)"))))
|
||||
Reference in New Issue
Block a user