Skip to content

Commit 8bd6acf

Browse files
committed
fix: relax closed values validation
because we can't ensure this when merging updates from server
1 parent 7b07116 commit 8bd6acf

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

deps/db/src/logseq/db/frontend/malli_schema.cljs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,18 @@
8989
expected to be a coll if the property has a :many cardinality. validate-fn is
9090
a fn that is called directly on each value to return a truthy value.
9191
validate-fn varies by property type"
92-
[db validate-fn [property property-val] & {:keys [new-closed-value? _skip-strict-url-validate?]
92+
[db validate-fn [property property-val] & {:keys [_skip-strict-url-validate?]
9393
:as validate-option}]
9494
;; For debugging
9595
;; (when (not (internal-ident? (:db/ident property))) (prn :validate-val (dissoc property :property/closed-values) property-val))
9696
(let [validate-fn' (if (db-property-type/property-types-with-db (:logseq.property/type property))
9797
(fn [value]
9898
(validate-fn db value validate-option))
99-
validate-fn)
100-
validate-fn'' (if (and (db-property-type/closed-value-property-types (:logseq.property/type property))
101-
;; new closed values aren't associated with the property yet
102-
(not new-closed-value?)
103-
(seq (:property/closed-values property)))
104-
(fn closed-value-valid? [val]
105-
(and (validate-fn' val)
106-
(let [ids (set (map :db/id (:property/closed-values property)))
107-
result (contains? ids val)]
108-
(when-not result
109-
(js/console.error (str "Error: not a closed value, id: " val ", existing choices: " ids ", property: " (:db/ident property))))
110-
result)))
111-
validate-fn')]
99+
validate-fn)]
112100
(if (db-property/many? property)
113-
(or (every? validate-fn'' property-val)
101+
(or (every? validate-fn' property-val)
114102
(empty-placeholder-value? db property (first property-val)))
115-
(or (validate-fn'' property-val)
103+
(or (validate-fn' property-val)
116104
;; also valid if value is empty-placeholder
117105
(empty-placeholder-value? db property property-val)))))
118106

src/main/frontend/components/property/value.cljs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,12 @@
10961096
[:span.number (str value')]
10971097
10981098
:else
1099-
(inline-text {} :markdown (str value'))))))
1099+
[:span.inline-flex.w-full
1100+
(let [value' (str value')
1101+
value' (if (string/blank? value')
1102+
"Empty"
1103+
value')]
1104+
(inline-text {} :markdown value'))]))))
11001105
11011106
(rum/defc select-item
11021107
[property type value {:keys [page-cp inline-text other-position? property-position table-view? _icon?] :as opts}]

0 commit comments

Comments
 (0)