mirror of
https://github.com/logseq/logseq.git
synced 2026-05-18 01:42:19 +00:00
enhance: list commands can sort by all visibile fields
Remove outdated name field which had no effect. Also remove duplication of these values in option declaration, completion declaration and completion tests
This commit is contained in:
@@ -20,10 +20,15 @@
|
||||
:order {:desc "Sort order. Default: asc"
|
||||
:values ["asc" "desc"]}})
|
||||
|
||||
(def ^:private list-sort-fields
|
||||
{:list-page #{"title" "id" "ident" "created-at" "updated-at"}
|
||||
:list-tag #{"title" "id" "ident" "created-at" "updated-at"}
|
||||
:list-property #{"title" "id" "ident" "created-at" "updated-at"}})
|
||||
|
||||
(def ^:private list-page-spec
|
||||
(merge list-common-spec
|
||||
{:sort {:desc "Sort field"
|
||||
:values ["title" "created-at" "updated-at"]}
|
||||
:values (:list-page list-sort-fields)}
|
||||
:include-journal {:desc "Include journal pages"
|
||||
:coerce :boolean}
|
||||
:journal-only {:desc "Only journal pages"
|
||||
@@ -37,7 +42,7 @@
|
||||
(def ^:private list-tag-spec
|
||||
(merge list-common-spec
|
||||
{:sort {:desc "Sort field"
|
||||
:values ["name" "title"]}
|
||||
:values (:list-tag list-sort-fields)}
|
||||
:include-built-in {:desc "Include built-in tags"
|
||||
:coerce :boolean}
|
||||
:with-properties {:desc "Include tag properties"
|
||||
@@ -49,7 +54,7 @@
|
||||
(def ^:private list-property-spec
|
||||
(merge list-common-spec
|
||||
{:sort {:desc "Sort field"
|
||||
:values ["name" "title"]}
|
||||
:values (:list-property list-sort-fields)}
|
||||
:include-built-in {:desc "Include built-in properties"
|
||||
:coerce :boolean}
|
||||
:with-classes {:desc "Include property classes"
|
||||
@@ -63,11 +68,6 @@
|
||||
(core/command-entry ["list" "tag"] :list-tag "List tags" list-tag-spec)
|
||||
(core/command-entry ["list" "property"] :list-property "List properties" list-property-spec)])
|
||||
|
||||
(def ^:private list-sort-fields
|
||||
{:list-page #{"title" "created-at" "updated-at"}
|
||||
:list-tag #{"name" "title"}
|
||||
:list-property #{"name" "title"}})
|
||||
|
||||
(defn invalid-options?
|
||||
[command opts]
|
||||
(let [{:keys [order include-journal journal-only]} opts
|
||||
|
||||
@@ -44,15 +44,12 @@
|
||||
page-entry (first (filter #(= :list-page (:command %)) entries))
|
||||
tag-entry (first (filter #(= :list-tag (:command %)) entries))
|
||||
property-entry (first (filter #(= :list-property (:command %)) entries))]
|
||||
(testing "page-spec :sort has correct values"
|
||||
(is (= ["title" "created-at" "updated-at"]
|
||||
(get-in page-entry [:spec :sort :values]))))
|
||||
(testing "tag-spec :sort has correct values"
|
||||
(is (= ["name" "title"]
|
||||
(get-in tag-entry [:spec :sort :values]))))
|
||||
(testing "property-spec :sort has correct values"
|
||||
(is (= ["name" "title"]
|
||||
(get-in property-entry [:spec :sort :values]))))
|
||||
(testing "page-spec :sort has some correct values"
|
||||
(is (contains? (get-in page-entry [:spec :sort :values]) "title")))
|
||||
(testing "tag-spec :sort has some correct values"
|
||||
(is (contains? (get-in tag-entry [:spec :sort :values]) "title")))
|
||||
(testing "property-spec :sort has some correct values"
|
||||
(is (contains? (get-in property-entry [:spec :sort :values]) "title")))
|
||||
(testing "common :order has correct values"
|
||||
(is (= ["asc" "desc"]
|
||||
(get-in page-entry [:spec :order :values]))))))
|
||||
@@ -214,12 +211,7 @@
|
||||
(deftest test-zsh-command-specific-values
|
||||
(let [output (gen/generate-completions "zsh" full-table)]
|
||||
(testing "--pos under upsert block offers correct values"
|
||||
(is (re-find #"--pos=.*\(first-child last-child sibling\)" output)))
|
||||
(testing "--sort for list page offers correct values"
|
||||
(is (re-find #"--sort=.*\(title created-at updated-at\)" output)))
|
||||
(testing "--sort for list tag offers name title"
|
||||
;; Just check globally that name title appears in sort context
|
||||
(is (re-find #"\(name title\)" output)))))
|
||||
(is (re-find #"--pos=.*\(first-child last-child sibling\)" output)))))
|
||||
|
||||
(deftest test-zsh-all-commands-present
|
||||
(let [output (gen/generate-completions "zsh" full-table)]
|
||||
@@ -346,8 +338,6 @@
|
||||
(is (contains? varied :type)))
|
||||
(testing "--name is detected as varied"
|
||||
(is (contains? varied :name)))
|
||||
(testing "--sort is detected as varied"
|
||||
(is (contains? varied :sort)))
|
||||
(testing "uniform options like --pos are not varied"
|
||||
(is (not (contains? varied :pos))))
|
||||
(testing "uniform options like --cardinality are not varied"
|
||||
|
||||
Reference in New Issue
Block a user