Browse Source

enhance: import cards correctly regardless of tag options

and also ignore card properties which can't be applied in db version.
Fixes LOG-3062
Gabriel Horner 11 months ago
parent
commit
a987826a48

+ 7 - 5
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -100,7 +100,9 @@
 
 (defn- convert-tag? [tag-name {:keys [convert-all-tags? tag-classes]}]
   (and (or convert-all-tags?
-           (contains? tag-classes tag-name))
+           (contains? tag-classes tag-name)
+           ;; built-in tags that always convert
+           (contains? #{"card"} tag-name))
        ;; Disallow tags as it breaks :block/tags
        (not (contains? #{"tags"} tag-name))))
 
@@ -636,6 +638,8 @@
    :now :later :doing :done :canceled :cancelled :in-progress :todo :wait :waiting
    ;; deprecated in db graphs
    :macros :logseq.query/nlp-date
+   :card-last-interval :card-repeats :card-last-reviewed :card-next-schedule
+   :card-ease-factor :card-last-score
    :logseq.color :logseq.table.borders :logseq.table.stripes :logseq.table.max-width
    :logseq.table.version :logseq.table.compact :logseq.table.headers :logseq.table.hover])
 
@@ -643,10 +647,8 @@
   "Updates page and block properties before their property types are inferred"
   [properties class-related-properties]
   (let [dissoced-props (concat ignored-built-in-properties
-                               ;; TODO: Add import support for these dissoced built-in properties
-                               [:title :created-at :updated-at
-                                :card-last-interval :card-repeats :card-last-reviewed :card-next-schedule
-                                :card-ease-factor :card-last-score]
+                               ;; TODO: Deal with these dissoced built-in properties
+                               [:title :created-at :updated-at]
                                class-related-properties)]
     (->> (apply dissoc properties dissoced-props)
          (keep (fn [[prop val]]

+ 15 - 4
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -193,11 +193,12 @@
 
       ;; Counts
       ;; Includes journals as property values e.g. :logseq.task/deadline
-      (is (= 23 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
-      (is (= 23 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn))))
+      (is (= 24 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
+      (is (= 24 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn))))
 
       (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Task]] @conn))))
       (is (= 3 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Query]] @conn))))
+      (is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Card]] @conn))))
 
       ;; Don't count pages like url.md that have properties but no content
       (is (= 10
@@ -325,8 +326,9 @@
               :logseq.property.linked-references/excludes #{"ref2"}}
              (select-keys (readable-properties @conn (find-page-by-name @conn "chat-gpt"))
                           [:logseq.property.linked-references/excludes :logseq.property.linked-references/includes]))
-          "linked ref filters set correctly")
+          "linked ref filters set correctly"))
 
+    (testing "built-in classes and their properties"
       ;; Queries
       (is (= {:logseq.property.table/sorting [{:id :user.property/prop-num, :asc? false}]
               :logseq.property.view/type "Table View"
@@ -346,7 +348,12 @@
           "Advanced query has correct query properties")
       (is (= "tasks with todo and doing"
              (:block/title (find-block-by-content @conn #"tasks with")))
-          "Advanced query has custom title migrated"))
+          "Advanced query has custom title migrated")
+
+      ;; Cards
+      (is (= {:block/tags [:logseq.class/Card]}
+             (readable-properties @conn (find-block-by-content @conn "card 1")))
+          "None of the card properties are imported since they are deprecated"))
 
     (testing "tags convert to classes"
       (is (= :user.class/Quotes___life
@@ -480,6 +487,10 @@
                   count))
         "Correct number of user classes")
 
+    (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Task]] @conn))))
+    (is (= 3 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Query]] @conn))))
+    (is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Card]] @conn))))
+
     (testing "replacing refs in :block/title when :remove-inline-tags? set"
       (is (= 2
              (->> (find-block-by-content @conn #"replace with same start string")

+ 9 - 0
deps/graph-parser/test/resources/exporter-test-graph/journals/2024_11_26.md

@@ -0,0 +1,9 @@
+- card 1 #card
+  card-last-score:: 3
+  card-repeats:: 1
+  card-next-schedule:: 2024-11-30T20:27:33.372Z
+  card-last-interval:: 4
+  card-ease-factor:: 2.36
+  card-last-reviewed:: 2024-11-26T20:27:33.373Z
+- card 2 with cloze {{cloze surprise!}} #card
+  card-next-schedule:: 2024-11-27T05:00:00.000Z

+ 1 - 0
deps/graph-parser/test/resources/exporter-test-graph/logseq/srs-of-matrix.edn

@@ -0,0 +1 @@
+{0 {2.5 3.45}}