fix: hide recycled property values and choices

This commit is contained in:
Tienson Qin
2026-04-09 13:55:49 +08:00
parent 8dc6d817cb
commit a37dad9cfa
3 changed files with 71 additions and 22 deletions

View File

@@ -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))))

View File

@@ -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)

View 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)))))