mirror of
https://github.com/logseq/logseq.git
synced 2026-05-19 02:12:41 +00:00
fix: hide recycled property values and choices
This commit is contained in:
@@ -179,6 +179,7 @@
|
||||
|
||||
:property/closed-values
|
||||
(some->> (lookup-entity e :block/_closed-value-property default-value)
|
||||
(remove entity-util/recycled?)
|
||||
(sort-by :block/order))
|
||||
|
||||
(lookup-kv-with-default-value db e k default-value))))
|
||||
|
||||
46
deps/db/src/logseq/db/common/view.cljs
vendored
46
deps/db/src/logseq/db/common/view.cljs
vendored
@@ -373,13 +373,14 @@
|
||||
entities)
|
||||
(remove nil?)
|
||||
(keep (fn [e]
|
||||
(when-let [label (get-property-value-content db e)]
|
||||
(when-not (or (string/blank? (str label))
|
||||
(= empty-id (:db/id e)))
|
||||
{:label (str label)
|
||||
:value (if (de/entity? e)
|
||||
(select-keys e [:db/id :block/uuid])
|
||||
e)}))))
|
||||
(when-not (and (de/entity? e) (entity-util/recycled? e))
|
||||
(when-let [label (get-property-value-content db e)]
|
||||
(when-not (or (string/blank? (str label))
|
||||
(= empty-id (:db/id e)))
|
||||
{:label (str label)
|
||||
:value (if (de/entity? e)
|
||||
(select-keys e [:db/id :block/uuid])
|
||||
e)})))))
|
||||
(common-util/distinct-by :label))))
|
||||
|
||||
(defn ^:api get-property-values
|
||||
@@ -394,22 +395,23 @@
|
||||
(map (fn [d]
|
||||
(:v d)))
|
||||
distinct
|
||||
(map (fn [v]
|
||||
(let [e (when ref-type? (d/entity db v))
|
||||
[label value] (cond ref-type?
|
||||
[(db-property/property-value-content e)
|
||||
(select-keys e [:db/id :block/uuid])]
|
||||
;; FIXME: Move query concerns out of :label as UI labels are usually strings
|
||||
;; All non-string values need to be passed to the query builder since non-ref prop values use the actual value
|
||||
;; This check is less fragile than listing all the property types to support e.g. :datetime, :checkbox, :keyword, :any
|
||||
(not (string? v))
|
||||
[v v]
|
||||
:else
|
||||
[(str v) v])]
|
||||
{:label label
|
||||
:value value})))))]
|
||||
(keep (fn [v]
|
||||
(let [e (when ref-type? (d/entity db v))]
|
||||
(when-not (and ref-type? (entity-util/recycled? e))
|
||||
(let [[label value] (cond ref-type?
|
||||
[(db-property/property-value-content e)
|
||||
(select-keys e [:db/id :block/uuid])]
|
||||
;; FIXME: Move query concerns out of :label as UI labels are usually strings
|
||||
;; All non-string values need to be passed to the query builder since non-ref prop values use the actual value
|
||||
;; This check is less fragile than listing all the property types to support e.g. :datetime, :checkbox, :keyword, :any
|
||||
(not (string? v))
|
||||
[v v]
|
||||
:else
|
||||
[(str v) v])]
|
||||
{:label label
|
||||
:value value})))))))]
|
||||
(->>
|
||||
(if default-value
|
||||
(if (and default-value (not (entity-util/recycled? default-value)))
|
||||
(cons {:label (get-property-value-content db default-value)
|
||||
:value (select-keys default-value [:db/id :block/uuid])}
|
||||
values)
|
||||
|
||||
46
src/test/frontend/db/property_values_test.cljs
Normal file
46
src/test/frontend/db/property_values_test.cljs
Normal file
@@ -0,0 +1,46 @@
|
||||
(ns frontend.db.property-values-test
|
||||
(:require [cljs.test :refer [deftest is use-fixtures]]
|
||||
[datascript.core :as d]
|
||||
[frontend.db :as db]
|
||||
[frontend.test.helper :as test-helper]
|
||||
[logseq.db.common.entity-plus :as entity-plus]
|
||||
[logseq.db.common.view :as db-view]))
|
||||
|
||||
(def repo test-helper/test-db)
|
||||
|
||||
(defn start-and-destroy-db
|
||||
[f]
|
||||
(test-helper/start-and-destroy-db f))
|
||||
|
||||
(use-fixtures :each start-and-destroy-db)
|
||||
|
||||
(deftest get-property-values-filters-recycled-ref-values-test
|
||||
(let [property-ident :block/tags
|
||||
active-title "Active ref value"
|
||||
recycled-title "Recycled ref value"]
|
||||
(d/transact! (db/get-db repo false)
|
||||
[[:db/add -2 :block/title active-title]
|
||||
[:db/add -3 :block/title recycled-title]
|
||||
[:db/add -3 :logseq.property/deleted-at 1]
|
||||
[:db/add -10 property-ident -2]
|
||||
[:db/add -11 property-ident -3]])
|
||||
(let [result (db-view/get-property-values @(db/get-db repo false) property-ident {})]
|
||||
(is (contains? (set (map :label result)) active-title))
|
||||
(is (not (contains? (set (map :label result)) recycled-title))))))
|
||||
|
||||
(deftest property-closed-values-hide-recycled-values-test
|
||||
(d/transact! (db/get-db repo false)
|
||||
[{:db/id -1 :db/ident :user.property/closed-values-visibility}
|
||||
{:db/id -2
|
||||
:block/title "Visible closed value"
|
||||
:block/order "a"
|
||||
:block/closed-value-property -1}
|
||||
{:db/id -3
|
||||
:block/title "Recycled closed value"
|
||||
:block/order "b"
|
||||
:block/closed-value-property -1
|
||||
:logseq.property/deleted-at 1}])
|
||||
(let [db @(db/get-db repo false)
|
||||
property (d/entity db :user.property/closed-values-visibility)
|
||||
values (entity-plus/lookup-kv-then-entity property :property/closed-values)]
|
||||
(is (= ["Visible closed value"] (map :block/title values)))))
|
||||
Reference in New Issue
Block a user