fix: remove :string property type as :default

does everything it used to do. Also remove component behavior specific to :string
experiment/tanstack-table
Gabriel Horner 2024-05-20 11:34:36 -04:00
parent c5911a571b
commit 0cfc90e0ef
4 changed files with 11 additions and 65 deletions

View File

@ -291,8 +291,7 @@
property-common-schema-attrs
(remove #(not (db-property-type/property-type-allows-schema-attribute? prop-type (first %)))
property-type-schema-attrs)))])
;; TODO: Remove :string once it is user facing or unused
(conj db-property-type/user-built-in-property-types :string))))
db-property-type/user-built-in-property-types)))
(def user-property
(vec

View File

@ -11,7 +11,7 @@
(def internal-built-in-property-types
"Valid property types only for use by internal built-in-properties"
#{:string :keyword :map :coll :any :entity})
#{:keyword :map :coll :any :entity})
(def user-built-in-property-types
"Valid property types for users in order they appear in the UI"
@ -40,9 +40,8 @@
"Map of types to their set of allowed :schema attributes"
(merge-with into
(zipmap closed-value-property-types (repeat #{:values}))
(zipmap #{:string :number :url} (repeat #{:position}))
(zipmap #{:number :url} (repeat #{:position}))
{:default #{:cardinality}
:string #{:cardinality}
:number #{:cardinality}
:date #{:cardinality}
:url #{:cardinality}
@ -50,7 +49,7 @@
:template #{:classes}
:checkbox #{}}))
(assert (= (set user-built-in-property-types) (set (remove #{:string} (keys user-built-in-allowed-schema-attributes))))
(assert (= (set user-built-in-property-types) (set (keys user-built-in-allowed-schema-attributes)))
"Each user built in type should have an allowed schema attribute")
;; Property value validation
@ -79,12 +78,6 @@
(when-let [ent (d/entity db val)]
(url? (:block/content ent)))))
(defn- string-entity?
[db id-or-value _opts]
(or (string? id-or-value)
(when-let [entity (d/entity db id-or-value)]
(string? (:block/content entity)))))
(defn- number-entity?
[db id-or-value {:keys [new-closed-value?]}]
(if new-closed-value?
@ -118,9 +111,6 @@
{:default [:fn
{:error/message "should be a text block"}
text-entity?]
:string [:fn
{:error/message "should be a string"}
string-entity?]
:number [:fn
{:error/message "should be a number"}
number-entity?]
@ -156,7 +146,7 @@
(def property-types-with-db
"Property types whose validation fn requires a datascript db"
#{:default :string :url :number :date :page :template :entity})
#{:default :url :number :date :page :template :entity})
;; Helper fns
;; ==========

View File

@ -100,8 +100,6 @@
(case property-type
:default
"Text"
:string
"Text"
((comp string/capitalize name) property-type)))
(defn- handle-delete-property!

View File

@ -609,7 +609,7 @@
popup-content (fn content-fn [_]
[:div.property-select
(case type
(:string :number :url :default)
(:number :url :default)
(select block property select-opts' opts)
(:page :date)
@ -629,49 +629,13 @@
(property-empty-text-value)
(value-f))))))
(defn- save-text!
[repo block property value _editor-id e]
(let [new-value (util/evalue e)]
(when (not (state/get-editor-action))
(util/stop e)
(p/do!
(when (not= new-value value)
(property-handler/set-block-property! repo (:block/uuid block)
(:db/ident property)
(string/trim new-value)))
(exit-edit-property)))))
(defn- new-text-editor-opts
[repo block property value editor-id]
{:style {:padding 0
:background "none"}
:on-blur
(fn [e]
(save-text! repo block property value editor-id e))
:on-key-down
(fn [e]
(let [enter? (= (util/ekey e) "Enter")
esc? (= (util/ekey e) "Escape")
backspace? (= (util/ekey e) "Backspace")]
;; FIXME: backspace not working
(when (and (or enter? esc? backspace?)
(not (state/get-editor-action)))
(when-not backspace? (util/stop e))
(when (or esc? enter?)
(save-text! repo block property value editor-id e)))))})
(defn- property-editing
[block property value schema editor-box editor-args editor-id]
[block property schema]
[:div.flex.flex-1
(case (:type schema)
:template
(when-let [template (first (:property/schema.classes property))]
(<create-new-block-from-template! block property template))
:string
(let [repo (state/get-current-repo)
config {:editor-opts (new-text-editor-opts repo block property value editor-id)}]
[:div
(editor-box editor-args editor-id config)])
nil)])
(defn- property-value-inner
@ -723,13 +687,12 @@
(inline-text {} :markdown (macro-util/expand-value-if-macro (str value) (state/get-macros)))))]))
(rum/defcs property-scalar-value < rum/reactive db-mixins/query rum/static
[state block property value {:keys [container-id editor-id editing? editor-box editor-args
on-chosen]
[state block property value {:keys [container-id editor-id editing? on-chosen]
:as opts}]
(let [property (model/sub-block (:db/id property))
schema (:block/schema property)
type (get schema :type :default)
editing? (or (and editing? (not= :string type))
editing? (or editing?
(state/sub-property-value-editing? editor-id)
(state/sub-editing? [container-id (:block/uuid block) (:block/uuid property)]))
select-type? (select-type? property type)
@ -764,7 +727,7 @@
;; :others
[:div.flex.flex-1
(if editing?
(property-editing block property value schema editor-box editor-args editor-id)
(property-editing block property schema)
(property-value-inner block property value opts))])))))
(rum/defc multiple-values < rum/static
@ -836,9 +799,6 @@
type (some-> schema (get :type :default))
multiple-values? (db-property/many? property)
empty-value? (= :logseq.property/empty-placeholder v)
editor-args {:block property
:parent-block block
:format :markdown}
v (cond
(and multiple-values? (or (set? v) (and (coll? v) (empty? v)) (nil? v)))
v
@ -859,6 +819,5 @@
(property-scalar-value block property v
(merge
opts
{:editor-args editor-args
:editor-id editor-id
{:editor-id editor-id
:dom-id dom-id})))])))