Bläddra i källkod

enhance(apis): improve handling of class ident namespaces in tag(class) creation

charlie 3 veckor sedan
förälder
incheckning
b6c9f8136a
2 ändrade filer med 24 tillägg och 17 borttagningar
  1. 19 15
      deps/outliner/src/logseq/outliner/page.cljs
  2. 5 2
      src/main/logseq/api/db_based.cljs

+ 19 - 15
deps/outliner/src/logseq/outliner/page.cljs

@@ -259,9 +259,13 @@
                     (set (map :db/ident tags))
                     :else
                     #{:logseq.class/Page})
-        ;; Check existing page only when not with custom ident namespace
-        existing-page-id (when (not class-ident-namespace?)
-                           (first (ldb/page-exists? db title types)))
+        existing-names-page (ldb/page-exists? db title types)
+        existing-page-id (some->> existing-names-page
+                                  (filter #(try (when-let [e (and class-ident-namespace? (d/entity db %))]
+                                                  (let [ns' (namespace (:db/ident e))]
+                                                    (= (str ns') class-ident-namespace)))
+                                                (catch :default _ false)))
+                                  (first))
         existing-page (some->> existing-page-id (d/entity db))]
     (if (and existing-page (not (:block/parent existing-page)))
       (let [tx-meta {:persist-op? persist-op?
@@ -283,10 +287,10 @@
           ;; Just return existing page info
           {:page-uuid (:block/uuid existing-page)
            :title (:block/title existing-page)}))
-      (let [page           (gp-block/page-name->map title db true date-formatter
-                                                    {:class? class?
-                                                     :page-uuid (when (uuid? uuid') uuid')
-                                                     :skip-existing-page-check? true})
+      (let [page (gp-block/page-name->map title db true date-formatter
+                                          {:class? class?
+                                           :page-uuid (when (uuid? uuid') uuid')
+                                           :skip-existing-page-check? true})
             [page parents'] (if (and (text/namespace-page? title) split-namespace?)
                               (let [pages (split-namespace-pages db page date-formatter class?)]
                                 [(last pages) (butlast pages)])
@@ -302,16 +306,16 @@
               (outliner-validate/validate-page-title-characters (str (:block/title parent)) {:node parent})))
 
           (let [page-uuid (:block/uuid page)
-                page-txs  (build-page-tx db properties page (select-keys options [:whiteboard? :class? :tags :class-ident-namespace]))
-                txs      (concat
-                          ;; transact doesn't support entities
-                          (remove de/entity? parents')
-                          page-txs)
+                page-txs (build-page-tx db properties page (select-keys options [:whiteboard? :class? :tags :class-ident-namespace]))
+                txs (concat
+                     ;; transact doesn't support entities
+                     (remove de/entity? parents')
+                     page-txs)
                 tx-meta (cond-> {:persist-op? persist-op?
                                  :outliner-op :create-page}
-                          today-journal?
-                          (assoc :create-today-journal? true
-                                 :today-journal-name title))]
+                                today-journal?
+                                (assoc :create-today-journal? true
+                                       :today-journal-name title))]
             {:tx-meta tx-meta
              :tx-data txs
              :title title

+ 5 - 2
src/main/logseq/api/db_based.cljs

@@ -222,9 +222,12 @@
    (when (text/namespace-page? title)
      (throw (ex-info "Tag title shouldn't include forward slash" {:title title})))
    (let [opts (bean/->clj opts)
+         custom-ident-namespace (:customIdentNamespace opts)
+         class-ident-namespace (or (some-> custom-ident-namespace (api-block/sanitize-user-property-name))
+                                   (api-block/resolve-class-prefix-for-db this))
          opts' (assoc opts
-                      :redirect? false
-                      :class-ident-namespace (api-block/resolve-class-prefix-for-db this))]
+                 :redirect? false
+                 :class-ident-namespace class-ident-namespace)]
      (p/let [tag (db-page-handler/<create-class! title opts')]
        (sdk-utils/result->js tag)))))