|
|
@@ -14,7 +14,8 @@
|
|
|
[frontend.components.search.highlight :as highlight]
|
|
|
[frontend.components.svg :as svg]
|
|
|
[frontend.modules.shortcut.core :as shortcut]
|
|
|
- [frontend.context.i18n :refer [t]]))
|
|
|
+ [frontend.context.i18n :refer [t]]
|
|
|
+ [frontend.handler.notification :as notification]))
|
|
|
|
|
|
(rum/defc property-item
|
|
|
[k value]
|
|
|
@@ -22,52 +23,100 @@
|
|
|
[:label.col-span-1.font-medium.py-2 k]
|
|
|
value])
|
|
|
|
|
|
-(rum/defc schema
|
|
|
- [entity]
|
|
|
- [:div.property-schema
|
|
|
- ;; type
|
|
|
- (property-item (t :schema/type)
|
|
|
- (ui/select
|
|
|
- [{:label "Text" :value "text"}
|
|
|
- {:label "Number" :value "number"}
|
|
|
- {:label "Date" :value "date"}
|
|
|
- {:label "Choice" :value "choice"}
|
|
|
- {:label "Url" :value "url"}
|
|
|
- {:label "Object" :value "object"}
|
|
|
- {:label "Any" :value "any"}]
|
|
|
- (fn [selected]
|
|
|
- (prn "selected: " selected))
|
|
|
- "form-select w-32 sm:w-32"))
|
|
|
+(rum/defc schema-type
|
|
|
+ [entity schema]
|
|
|
+ (let [schema-type (:type schema)
|
|
|
+ options (map
|
|
|
+ (fn [item] (if (= schema-type (:value item))
|
|
|
+ (assoc item :selected true)
|
|
|
+ item))
|
|
|
+ [{:label "Text" :value "text"}
|
|
|
+ {:label "Number" :value "number"}
|
|
|
+ {:label "Date" :value "date"}
|
|
|
+ {:label "Choice" :value "choice"}
|
|
|
+ {:label "Url" :value "url"}
|
|
|
+ {:label "Object" :value "object"}
|
|
|
+ {:label "Any" :value "any"}])]
|
|
|
+ (property-item
|
|
|
+ (t :schema/type)
|
|
|
+ (ui/select options
|
|
|
+ (fn [selected]
|
|
|
+ (property-handler/set-property-schema! entity :type (string/lower-case selected)))
|
|
|
+ "form-select w-32 sm:w-32"))))
|
|
|
|
|
|
- ;; icon
|
|
|
+(rum/defc schema-number-range
|
|
|
+ [entity schema]
|
|
|
+ (when (= (:type schema) "number")
|
|
|
+ (let [on-submitted (fn [key]
|
|
|
+ (fn [e]
|
|
|
+ (if-let [result (parse-long (util/evalue e))]
|
|
|
+ (property-handler/set-property-schema! entity key result)
|
|
|
+ (notification/show!
|
|
|
+ [:div "A number is needed"]
|
|
|
+ :warning))))]
|
|
|
+ (property-item
|
|
|
+ (t :schema/number-range)
|
|
|
+ [:div.flex.flex-row.items-center
|
|
|
+ [:input.form-input.simple-input.block.focus:outline-none.col-span-1
|
|
|
+ {:placeholder "Min"
|
|
|
+ :default-value (:min schema)
|
|
|
+ :on-blur (on-submitted :min)
|
|
|
+ :on-key-up (fn [e]
|
|
|
+ (case (util/ekey e)
|
|
|
+ "Enter"
|
|
|
+ ((on-submitted :min) e)
|
|
|
+ nil))}]
|
|
|
+ [:div.px-4 "-"]
|
|
|
+ [:input.form-input.simple-input.block.focus:outline-none.col-span-1
|
|
|
+ {:placeholder "Max"
|
|
|
+ :default-value (:max schema)
|
|
|
+ :on-blur (on-submitted :max)
|
|
|
+ :on-key-up (fn [e]
|
|
|
+ (case (util/ekey e)
|
|
|
+ "Enter"
|
|
|
+ ((on-submitted :max) e)
|
|
|
+ nil))}]]))))
|
|
|
|
|
|
- ;; cardinality
|
|
|
- (property-item
|
|
|
- (t :schema/multiple-values)
|
|
|
- (ui/checkbox
|
|
|
- {:checked true
|
|
|
- :on-change (fn [event]
|
|
|
- (prn "on changed"))}))
|
|
|
+(rum/defc schema-cardinality
|
|
|
+ [entity schema]
|
|
|
+ (let [multiple? (boolean (:multiple-values? schema))]
|
|
|
+ (property-item
|
|
|
+ (t :schema/multiple-values)
|
|
|
+ (ui/checkbox
|
|
|
+ {:checked multiple?
|
|
|
+ :on-change (fn []
|
|
|
+ (property-handler/set-property-schema! entity :multiple-values? (not multiple?)))}))))
|
|
|
|
|
|
- ;; description
|
|
|
- (property-item
|
|
|
- (t :schema/description)
|
|
|
- [:input.form-input.simple-input.block.focus:outline-none.col-span-4
|
|
|
- {:placeholder "Optional"
|
|
|
- :on-blur (fn [e]
|
|
|
- (prn "on-blur: " (util/evalue e))
|
|
|
- )
|
|
|
- :on-key-up (fn [e]
|
|
|
- (prn "on-key-up: " (util/evalue e))
|
|
|
- (case (util/ekey e)
|
|
|
- "Enter"
|
|
|
- (prn "save")
|
|
|
+(rum/defc schema-description
|
|
|
+ [entity schema]
|
|
|
+ (property-item
|
|
|
+ (t :schema/description)
|
|
|
+ (let [description (:description schema)
|
|
|
+ on-submitted (fn [e]
|
|
|
+ (let [desc (util/evalue e)]
|
|
|
+ (when-not (string/blank? desc)
|
|
|
+ (property-handler/set-property-schema! entity :description desc))))]
|
|
|
+ [:input.form-input.simple-input.block.focus:outline-none.col-span-4
|
|
|
+ {:placeholder "Optional"
|
|
|
+ :default-value description
|
|
|
+ :on-blur on-submitted
|
|
|
+ :on-key-up (fn [e]
|
|
|
+ (case (util/ekey e)
|
|
|
+ "Enter"
|
|
|
+ (on-submitted e)
|
|
|
|
|
|
- "Escape"
|
|
|
- (prn "clear")
|
|
|
+ nil))}])))
|
|
|
|
|
|
- nil))}])
|
|
|
+(rum/defc schema
|
|
|
+ [entity]
|
|
|
+ (let [schema (:block/property-schema entity)]
|
|
|
+ [:div.property-schema
|
|
|
+ (schema-type entity schema)
|
|
|
+ (schema-number-range entity schema)
|
|
|
+ (schema-cardinality entity schema)
|
|
|
+ (schema-description entity schema)
|
|
|
|
|
|
- ;; predicates
|
|
|
- ;; integrations
|
|
|
- ])
|
|
|
+ ;; TODO: icon
|
|
|
+ ;; predicates
|
|
|
+ ;; integrations
|
|
|
+ ]))
|