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 property-common-schema-attrs
(remove #(not (db-property-type/property-type-allows-schema-attribute? prop-type (first %))) (remove #(not (db-property-type/property-type-allows-schema-attribute? prop-type (first %)))
property-type-schema-attrs)))]) property-type-schema-attrs)))])
;; TODO: Remove :string once it is user facing or unused db-property-type/user-built-in-property-types)))
(conj db-property-type/user-built-in-property-types :string))))
(def user-property (def user-property
(vec (vec

View File

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

View File

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

View File

@ -609,7 +609,7 @@
popup-content (fn content-fn [_] popup-content (fn content-fn [_]
[:div.property-select [:div.property-select
(case type (case type
(:string :number :url :default) (:number :url :default)
(select block property select-opts' opts) (select block property select-opts' opts)
(:page :date) (:page :date)
@ -629,49 +629,13 @@
(property-empty-text-value) (property-empty-text-value)
(value-f)))))) (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 (defn- property-editing
[block property value schema editor-box editor-args editor-id] [block property schema]
[:div.flex.flex-1 [:div.flex.flex-1
(case (:type schema) (case (:type schema)
:template :template
(when-let [template (first (:property/schema.classes property))] (when-let [template (first (:property/schema.classes property))]
(<create-new-block-from-template! block property template)) (<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)]) nil)])
(defn- property-value-inner (defn- property-value-inner
@ -723,13 +687,12 @@
(inline-text {} :markdown (macro-util/expand-value-if-macro (str value) (state/get-macros)))))])) (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 (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 [state block property value {:keys [container-id editor-id editing? on-chosen]
on-chosen]
:as opts}] :as opts}]
(let [property (model/sub-block (:db/id property)) (let [property (model/sub-block (:db/id property))
schema (:block/schema property) schema (:block/schema property)
type (get schema :type :default) type (get schema :type :default)
editing? (or (and editing? (not= :string type)) editing? (or editing?
(state/sub-property-value-editing? editor-id) (state/sub-property-value-editing? editor-id)
(state/sub-editing? [container-id (:block/uuid block) (:block/uuid property)])) (state/sub-editing? [container-id (:block/uuid block) (:block/uuid property)]))
select-type? (select-type? property type) select-type? (select-type? property type)
@ -764,7 +727,7 @@
;; :others ;; :others
[:div.flex.flex-1 [:div.flex.flex-1
(if editing? (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))]))))) (property-value-inner block property value opts))])))))
(rum/defc multiple-values < rum/static (rum/defc multiple-values < rum/static
@ -836,9 +799,6 @@
type (some-> schema (get :type :default)) type (some-> schema (get :type :default))
multiple-values? (db-property/many? property) multiple-values? (db-property/many? property)
empty-value? (= :logseq.property/empty-placeholder v) empty-value? (= :logseq.property/empty-placeholder v)
editor-args {:block property
:parent-block block
:format :markdown}
v (cond v (cond
(and multiple-values? (or (set? v) (and (coll? v) (empty? v)) (nil? v))) (and multiple-values? (or (set? v) (and (coll? v) (empty? v)) (nil? v)))
v v
@ -859,6 +819,5 @@
(property-scalar-value block property v (property-scalar-value block property v
(merge (merge
opts opts
{:editor-args editor-args {:editor-id editor-id
:editor-id editor-id
:dom-id dom-id})))]))) :dom-id dom-id})))])))