diff --git a/src/main/logseq/cli/command/show.cljs b/src/main/logseq/cli/command/show.cljs index 1928687dea..047ef8b826 100644 --- a/src/main/logseq/cli/command/show.cljs +++ b/src/main/logseq/cli/command/show.cljs @@ -595,6 +595,16 @@ {})))) (p/resolved {}))) +(defn- merge-fetched-property-value + [existing value] + (cond + (nil? existing) value + (= existing value) existing + (sequential? existing) (if (some #(= % value) existing) + existing + (conj (vec existing) value)) + :else [existing value])) + (defn- fetch-user-properties [config repo block-ids] (if (seq block-ids) @@ -613,7 +623,7 @@ (p/let [rows (transport/invoke config :thread-api/q false [repo [props-query ids (vec property-idents)]])] (reduce (fn [acc [block-id attr value]] - (update acc block-id assoc attr value)) + (update-in acc [block-id attr] merge-fetched-property-value value)) {} rows)) {}))) diff --git a/src/test/logseq/cli/command/show_test.cljs b/src/test/logseq/cli/command/show_test.cljs index 8d60c487b8..919a5c7508 100644 --- a/src/test/logseq/cli/command/show_test.cljs +++ b/src/test/logseq/cli/command/show_test.cljs @@ -72,3 +72,20 @@ (is (false? (:ok? result))) (is (= :invalid-options (get-in result [:error :code]))) (is (string/includes? (get-in result [:error :message]) "id"))))) + +(deftest test-merge-fetched-property-value + (let [merge-value #'show-command/merge-fetched-property-value] + (testing "first value is kept as scalar" + (is (= "Step 1" (merge-value nil "Step 1")))) + + (testing "second distinct value upgrades scalar to vector" + (is (= ["Step 1" "Step 2"] + (merge-value "Step 1" "Step 2")))) + + (testing "additional values are appended" + (is (= ["Step 1" "Step 2" "Step 3"] + (merge-value ["Step 1" "Step 2"] "Step 3")))) + + (testing "duplicate values are deduplicated" + (is (= ["Step 1" "Step 2"] + (merge-value ["Step 1" "Step 2"] "Step 2"))))))