Przeglądaj źródła

fix: import doesn't fail if it has a page with new class name

fixes LOG-3039
Gabriel Horner 1 rok temu
rodzic
commit
4a69e75e88

+ 1 - 3
deps/db/src/logseq/db/frontend/class.cljs

@@ -11,9 +11,7 @@
    {:title "Task"
     :schema {:properties [:logseq.task/status :logseq.task/priority :logseq.task/deadline]}}
 
-   :logseq.class/Card {:title "Card"
-                       ;; :schema {:property []}
-                       }
+   :logseq.class/Card {:title "Card"}
    ;; TODO: Add more classes such as :book, :paper, :movie, :music, :project
    })
 

+ 10 - 3
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -308,6 +308,13 @@
       ;; :filters is not in built-in-properties because it maps to 2 new properties
       (conj :filters)))
 
+(def all-built-in-names
+  "All built-in properties and classes as a set of keywords"
+  (set/union all-built-in-property-names
+             (set (->> db-class/built-in-classes
+                       vals
+                       (map #(-> % :title string/lower-case keyword))))))
+
 (def file-built-in-property-names
   "Built-in property names for file graphs that are imported. Expressed as set of keywords"
   (-> all-built-in-property-names
@@ -700,8 +707,8 @@
         existing-page-names-to-uuids (into {} (map (juxt :block/name :block/uuid) existing-pages))
         new-pages (->> all-pages
                        (remove #(contains? existing-page-names-to-uuids (:block/name %)))
-                       ;; fix extract incorrectly assigning user properties built-in property uuids
-                       (map #(if (contains? all-built-in-property-names (keyword (:block/name %)))
+                       ;; fix extract incorrectly assigning user pages built-in uuids
+                       (map #(if (contains? all-built-in-names (keyword (:block/name %)))
                                (assoc % :block/uuid (d/squuid))
                                %)))
         page-names-to-uuids (merge existing-page-names-to-uuids
@@ -734,7 +741,7 @@
                                      ;; Don't build a new page if it overwrites an existing class
                                      (not (some-> (get @(:all-idents import-state) (keyword (:block/title m)))
                                                   db-malli-schema/class?)))
-                             (let [m' (if (contains? all-built-in-property-names (keyword (:block/name m)))
+                             (let [m' (if (contains? all-built-in-names (keyword (:block/name m)))
                                         ;; Use fixed uuid from above
                                         (cond-> (assoc m :block/uuid (get page-names-to-uuids (:block/name m)))
                                           ;; only happens for few file built-ins like tags and alias

+ 9 - 1
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -170,7 +170,7 @@
       (is (= 18 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
 
       ;; Don't count pages like url.md that have properties but no content
-      (is (= 6
+      (is (= 7
              (count (->> (d/q '[:find [(pull ?b [:block/title :block/type]) ...]
                                 :where [?b :block/title] [_ :block/page ?b]] @conn)
                          (filter #(= "page" (:block/type %))))))
@@ -346,6 +346,14 @@
                   count))
           "A block with different case of same ref names has 1 distinct ref"))
 
+    (testing "imported concepts can have names of new-built concepts"
+      (is (= #{:logseq.property/description :user.property/description}
+             (set (d/q '[:find [?ident ...] :where [?b :db/ident ?ident] [?b :block/name "description"]] @conn)))
+          "user description property is separate from built-in one")
+      (is (= #{"page" "class"}
+             (set (d/q '[:find [?type ...] :where [?b :block/type ?type] [?b :block/name "task"]] @conn)))
+          "user page is separate from built-in class"))
+
     (testing "multiline blocks"
       (is (= "|markdown| table|\n|some|thing|" (:block/title (find-block-by-content @conn #"markdown.*table"))))
       (is (= "multiline block\na 2nd\nand a 3rd" (:block/title (find-block-by-content @conn #"multiline block"))))

+ 1 - 0
deps/graph-parser/test/resources/exporter-test-graph/pages/Task.md

@@ -0,0 +1 @@
+- Notes not about new Task class