From 7370716215519a25f05356422e75f511cd8d225b Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Fri, 15 Jul 2022 10:24:21 -0400 Subject: [PATCH] Move editable linkable built-in props to var They were also being referred to elsewhere in block.cljs Also moved filters to editable as that is existing behavior Also disabled verbosity of cli tests to allow graph-parser tests to be more readable --- .../src/logseq/graph_parser/block.cljs | 7 +++-- .../src/logseq/graph_parser/property.cljs | 13 +++++++-- .../test/logseq/graph_parser/block_test.cljs | 29 +++++++++++++------ .../test/logseq/graph_parser/cli_test.cljs | 2 +- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/block.cljs b/deps/graph-parser/src/logseq/graph_parser/block.cljs index c16669e58..239f7910d 100644 --- a/deps/graph-parser/src/logseq/graph_parser/block.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/block.cljs @@ -160,8 +160,9 @@ properties (remove (fn [[k _]] (contains? - (set/union (disj (gp-property/editable-built-in-properties) - :alias :aliases :tags) + (set/union (apply disj + (gp-property/editable-built-in-properties) + gp-property/editable-linkable-built-in-properties) (gp-property/hidden-built-in-properties)) (keyword k)))) (map last) @@ -222,7 +223,7 @@ k (keyword k) v (if (and (string? v) - (contains? #{:alias :aliases :tags} k)) + (contains? gp-property/editable-linkable-built-in-properties k)) (set [v]) v) v (if (coll? v) (set v) v)] diff --git a/deps/graph-parser/src/logseq/graph_parser/property.cljs b/deps/graph-parser/src/logseq/graph_parser/property.cljs index 8c710f05a..936a3ad3b 100644 --- a/deps/graph-parser/src/logseq/graph_parser/property.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/property.cljs @@ -17,15 +17,24 @@ #{"now" "later" "todo" "doing" "done" "wait" "waiting" "canceled" "cancelled" "started" "in-progress"}) +;; Built-in properties are properties that logseq uses for its features. Most of +;; these properties are hidden from the user but a few like the editable ones +;; are visible for the user to edit. + (def built-in-extended-properties (atom #{})) (defn register-built-in-properties [props] (reset! built-in-extended-properties (set/union @built-in-extended-properties props))) +(def editable-linkable-built-in-properties + "Properties used by logseq that user can edit and that can have linkable property values" + #{:alias :aliases :tags}) + (defn editable-built-in-properties "Properties used by logseq that user can edit" [] - #{:title :alias :aliases :tags :icon :template :template-including-parent :public}) + (into #{:title :icon :template :template-including-parent :public :filters} + editable-linkable-built-in-properties)) (defn hidden-built-in-properties "Properties used by logseq that user can't edit or see" @@ -34,7 +43,7 @@ #{:id :custom-id :background-color :background_color :heading :collapsed :created-at :updated-at :last-modified-at :created_at :last_modified_at :query-table :query-properties :query-sort-by :query-sort-desc :ls-type - :hl-type :hl-page :hl-stamp :filters :file-path} + :hl-type :hl-page :hl-stamp :file-path} (set (map keyword markers)) @built-in-extended-properties)) diff --git a/deps/graph-parser/test/logseq/graph_parser/block_test.cljs b/deps/graph-parser/test/logseq/graph_parser/block_test.cljs index d9826e23b..d69b56e21 100644 --- a/deps/graph-parser/test/logseq/graph_parser/block_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser/block_test.cljs @@ -4,10 +4,16 @@ (deftest test-extract-properties (are [x y] (= (:properties (gp-block/extract-properties :markdown x {})) y) - [["year" "1000"]] {:year 1000} - [["year" "\"1000\""]] {:year "\"1000\""} + ;; Built-in properties [["background-color" "#000000"]] {:background-color "#000000"} [["alias" "name/with space"]] {:alias #{"name/with space"}} + [["tags" "foo, bar"]] {:tags #{"foo" "bar"}} + [["tags" "'bar'"]] {:tags #{"'bar'"}} + [["file-path" "file:///home/x, y.pdf"]] {:file-path "file:///home/x, y.pdf"} + + ;; User properties + [["year" "1000"]] {:year 1000} + [["year" "\"1000\""]] {:year "\"1000\""} [["year" "1000"] ["alias" "name/with space"]] {:year 1000, :alias #{"name/with space"}} [["year" "1000"] ["tags" "name/with space"]] {:year 1000, :tags #{"name/with space"}} [["year" "1000"] ["tags" "name/with space, another"]] {:year 1000, :tags #{"name/with space" "another"}} @@ -21,8 +27,7 @@ [["foo" "[[bar]], [[nested [[baz]]]]"]] {:foo #{"bar" "nested [[baz]]"}} [["foo" "[[bar]], [[nested [[baz]]]]"]] {:foo #{"bar" "nested [[baz]]"}} [["foo" "bar, [[baz, test]]"]] {:foo #{"bar" "baz, test"}} - [["foo" "bar, [[baz, test, [[nested]]]]"]] {:foo #{"bar" "baz, test, [[nested]]"}} - [["file-path" "file:///home/x, y.pdf"]] {:file-path "file:///home/x, y.pdf"}) + [["foo" "bar, [[baz, test, [[nested]]]]"]] {:foo #{"bar" "baz, test, [[nested]]"}}) (testing "page-refs" (are [x y] (= (vec (:page-refs @@ -53,9 +58,15 @@ (is (= ["year"] (:page-refs - (gp-block/extract-properties :markdown - [["year" "1000"]] - {}))) - "Default to enabled when :property-pages/enabled? is not in config"))) + (gp-block/extract-properties :markdown + [["year" "1000"]] + {}))) + "Default to enabled when :property-pages/enabled? is not in config") -#_(cljs.test/run-tests) + (is (= ["foo" "bar"] + (:page-refs + (gp-block/extract-properties :markdown + ;; tags is linkable and background-color is not + [["tags" "foo, bar"] ["background-color" "#008000"]] + {:property-pages/enabled? true}))) + "Only editable linkable built-in properties have page-refs in property values"))) diff --git a/deps/graph-parser/test/logseq/graph_parser/cli_test.cljs b/deps/graph-parser/test/logseq/graph_parser/cli_test.cljs index cab27e445..ad4702e59 100644 --- a/deps/graph-parser/test/logseq/graph_parser/cli_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser/cli_test.cljs @@ -8,7 +8,7 @@ (deftest ^:integration parse-graph (let [graph-dir "test/docs" _ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir) - {:keys [conn files asts]} (gp-cli/parse-graph graph-dir)] + {:keys [conn files asts]} (gp-cli/parse-graph graph-dir {:verbose false})] (docs-graph-helper/docs-graph-assertions @conn files)