Browse Source

enhance(api): add get_page_properties function and update related tests

charlie 1 month ago
parent
commit
2236f3fc14
3 changed files with 11 additions and 9 deletions
  1. 3 1
      clj-e2e/test/logseq/e2e/plugins_basic_test.clj
  2. 1 0
      libs/src/LSPlugin.ts
  3. 7 8
      src/main/logseq/api.cljs

+ 3 - 1
clj-e2e/test/logseq/e2e/plugins_basic_test.clj

@@ -77,11 +77,13 @@
     (let [ret (ls-api-call! :editor.appendBlockInPage "test-block-properties-apis" "block-in-page-0" {:properties {:p1 1}})
           uuid' (assert-api-ls-block! ret)
           prop1 (ls-api-call! :editor.getBlockProperty uuid' "p1")
-          props1 (ls-api-call! :editor.getBlockProperties uuid' "p1")]
+          props1 (ls-api-call! :editor.getBlockProperties uuid' "p1")
+          props2 (ls-api-call! :editor.getPageProperties "test-block-properties-apis")]
       (w/wait-for ".property-k:text('p1')")
       (is (= 1 (get prop1 "value")))
       (is (= (get prop1 "ident") ":plugin.property._api/p1"))
       (is (= 1 (get props1 ":plugin.property._api/p1")))
+      (is (= ["Page"] (get props2 ":block/tags")))
       (ls-api-call! :editor.upsertBlockProperty uuid' "p2" "p2")
       (ls-api-call! :editor.upsertBlockProperty uuid' "p3" true)
       (ls-api-call! :editor.upsertBlockProperty uuid' "p4" {:a 1, :b [2, 3]})

+ 1 - 0
libs/src/LSPlugin.ts

@@ -834,6 +834,7 @@ export interface IEditorProxy extends Record<string, any> {
   getBlockProperty: (block: BlockIdentity, key: string) => Promise<BlockEntity | unknown>
 
   getBlockProperties: (block: BlockIdentity) => Promise<Record<string, any> | null>
+  getPageProperties: (page: PageIdentity) => Promise<Record<string, any> | null>
 
   scrollToBlockInPage: (
     pageName: BlockPageName,

+ 7 - 8
src/main/logseq/api.cljs

@@ -620,14 +620,7 @@
 
 (defn ^:export get_page
   [id-or-page-name]
-  (p/let [page (db-async/<pull (state/get-current-repo)
-                               (cond
-                                 (number? id-or-page-name)
-                                 id-or-page-name
-                                 (util/uuid-string? id-or-page-name)
-                                 [:block/uuid (uuid id-or-page-name)]
-                                 :else
-                                 [:block/name (util/page-name-sanity-lc id-or-page-name)]))]
+  (p/let [page (<pull-block id-or-page-name)]
     (when-let [page (and (:block/name page)
                          (some->> page (api-block/into-properties (state/get-current-repo))))]
       (bean/->js (sdk-utils/normalize-keyword-for-json page)))))
@@ -1011,6 +1004,12 @@
                            (:block/properties block))]
           (bean/->js (sdk-utils/normalize-keyword-for-json properties)))))))
 
+(defn ^:export get_page_properties
+  [id-or-page-name]
+  (p/let [page (<pull-block id-or-page-name)]
+    (when-let [id (:block/uuid page)]
+      (get_block_properties id))))
+
 (def ^:export get_current_page_blocks_tree
   (fn []
     (when-let [page (state/get-current-page)]