Skip to content

Commit

Permalink
fix: labels, image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Dec 21, 2023
1 parent e0ba2bf commit cf625cd
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 39 deletions.
8 changes: 2 additions & 6 deletions src/sb/app/account/data.cljc
Expand Up @@ -50,12 +50,8 @@
{:member/entity [:entity/id
:entity/kind
:entity/title
{:image/avatar [:asset/link
:entity/id
{:asset/provider [:s3/bucket-host]}]}
{:image/background [:asset/link
:entity/id
{:asset/provider [:s3/bucket-host]}]}]}]}]
{:image/avatar [:entity/id]}
{:image/background [:entity/id]}]}]}]
account-id)
:member/_account
(map #(u/lift-key % :member/entity))))
Expand Down
2 changes: 1 addition & 1 deletion src/sb/app/domain_name/data.cljc
Expand Up @@ -32,7 +32,7 @@
(when domain
(if (str/includes? domain ".")
domain
(str domain ".sb.com"))))
(str domain ".sparkboard.com"))))

(defn unqualify-domain [domain]
(when domain
Expand Down
21 changes: 20 additions & 1 deletion src/sb/app/entity/data.cljc
Expand Up @@ -25,7 +25,26 @@
s- :string
:db/fulltext true}
:entity/parent (sch/ref :one)
:entity/kind {s- [:enum :board :org :collection :member :project :chat :chat.message :field]}
:entity/kind {s- [:enum
:org
:board
:collection
:member
:project
:field
:discussion
:post
:comment
:notification
:tag
:chat
:message
:roles
:account
:ballot
:site
:asset
:chat.message]}
:entity/draft? {:doc "Entity is not yet published - visible only to creator/team"
s- :boolean}
:entity/description {:doc "Description of an entity (for card/header display)"
Expand Down
34 changes: 17 additions & 17 deletions src/sb/app/field/admin_ui.cljc
Expand Up @@ -2,7 +2,7 @@
(:require [applied-science.js-interop :as j]
[clojure.set :as set]
[clojure.string :as str]
[inside-out.forms :as forms]
[inside-out.forms :as io]
[promesa.core :as p]
[re-db.api :as db]
[sb.app.entity.data :as entity.data]
Expand Down Expand Up @@ -99,10 +99,10 @@
(orderable-props {:group-id (goog/getUid ?options)
:id (:sym ?option)
:on-move (fn [{:keys [source side destination]}]
(forms/swap-many! ?options re-order
(get ?options source)
side
(get ?options destination))
(io/swap-many! ?options re-order
(get ?options source)
side
(get ?options destination))
(save!))})]
[:div.flex.gap-2.items-center.group.relative.-ml-6.py-1
(merge {:key @?value}
Expand Down Expand Up @@ -130,7 +130,7 @@
(radix/simple-alert! {:message "Are you sure you want to remove this?"
:confirm-text (tr :tr/remove)
:confirm-fn (fn []
(forms/remove-many! ?option)
(io/remove-many! ?option)
(p/do (save!)
(radix/close-alert!)))}))}
(tr :tr/remove)]]}]]))
Expand All @@ -139,10 +139,10 @@
persisted-value]}]
(let [memo-by [(str (map :field-option/value persisted-value))]
{:syms [?options]} (h/use-memo (fn []
(forms/form (?options :many {:field-option/label ?label
(io/form (?options :many {:field-option/label ?label
:field-option/value ?value
:field-option/color ?color}
:init (mapv #(set/rename-keys % '{:field-option/label ?label
:init (mapv #(set/rename-keys % '{:field-option/label ?label
:field-option/value ?value
:field-option/color ?color}) @?field))))
memo-by)]
Expand All @@ -155,13 +155,13 @@
(into [:div.flex-v]
(map (partial show-option {:?options ?options
:save! save!}) ?options))
(let [?new (h/use-memo #(forms/field :init "") memo-by)]
(let [?new (h/use-memo #(io/field :init "") memo-by)]
[:form.flex.gap-2 {:on-submit (fn [^js e]
(.preventDefault e)
(forms/add-many! ?options {'?value (str (random-uuid))
(io/add-many! ?options {'?value (str (random-uuid))
'?label @?new
'?color "#ffffff"})
(forms/try-submit+ ?new (save!)))}
(io/try-submit+ ?new (save!)))}
[field.ui/text-field ?new {:placeholder "Option label" :wrapper-class "flex-auto"}]
[:div.btn.bg-white.px-3.py-1.shadow "Add Option"]])
#_[ui/pprinted @?options]])))
Expand Down Expand Up @@ -236,13 +236,13 @@
(field-editor-detail parent attribute field))]))

(ui/defview fields-editor [entity attribute]
(let [label (:label (forms/global-meta attribute))
(let [label (:label (io/global-meta attribute))
!new-field (h/use-state nil)
!autofocus-ref (ui/use-autofocus-ref)
fields (get entity attribute)
[expanded expand!] (h/use-state nil)]
[:div.field-wrapper {:class "labels-semibold"}
(when-let [label (or label (form.ui/attribute-label attribute))]
(when-let [label (or label (:label (io/global-meta attribute)))]
[:label.field-label {:class "flex items-center"}
label
[:div.flex.ml-auto.items-center
Expand All @@ -252,13 +252,13 @@
"Add Field"]
:children (for [[type {:keys [icon label]}] data/field-types]
[{:on-select #(reset! !new-field
(forms/form {:field/type ?type
(io/form {:field/type ?type
:field/label ?label
:field/published? (case type
:field.type/select false
true)}
:init {'?type type}
:required [?label]))}
:init {'?type type}
:required [?label]))}
[:div.flex.gap-4.items-center.cursor-default [icon "text-gray-600"] label]])}))]])
[:div.flex-v.border.rounded.labels-sm
(->> fields
Expand All @@ -277,7 +277,7 @@
[:form.flex.gap-2.items-start.relative
{:on-submit (ui/prevent-default
(fn [e]
(forms/try-submit+ ?new-field
(io/try-submit+ ?new-field
(p/let [{:as result :keys [field/id]} (data/add-field nil (:entity/id entity) attribute @?new-field)]
(expand! id)
(reset! !new-field nil)
Expand Down
2 changes: 1 addition & 1 deletion src/sb/app/field/ui.cljc
Expand Up @@ -82,7 +82,7 @@
[:input.h-5.w-5.rounded.border-gray-300.text-primary
(form.ui/pass-props props)]
[:div.flex-v.gap-1.ml-2
(when-let [label (form.ui/get-label ?field (:label props))]
(when-let [label (form.ui/get-label (:label props) ?field)]
[:div.flex.items-center.h-5 label])
(when (seq messages)
(into [:div.text-gray-500] (map form.ui/view-message) messages))]]]))
Expand Down
12 changes: 3 additions & 9 deletions src/sb/app/form/ui.cljc
Expand Up @@ -30,17 +30,11 @@
:can-edit?
:label))

(defn attribute-label [attribute]
(or (get-in forms/global-meta [attribute :label])
(tr* (keyword "tr" (name attribute)))))

(defn get-label [?field label]
(u/some-or label
(:label ?field)
(some->> (:attribute ?field) attribute-label)))
(defn get-label [label ?field]
(u/some-or label (:label ?field)))

(defn show-label [?field & [label]]
(when-let [label (get-label ?field label)]
(when-let [label (get-label label ?field)]
[:label.field-label {:for (field-id ?field)} label]))

(defn ?field-props [?field
Expand Down
5 changes: 4 additions & 1 deletion src/sb/client/core.cljs
Expand Up @@ -65,7 +65,10 @@
(cond-> (k field-meta)
validator
(update :validators conj validator))))
(forms/set-global-meta! app/global-field-meta)
(forms/set-global-meta! (fn [k]
(when k
(merge {:label (sb.i18n/tr* (keyword "tr" (name k)))}
(app/global-field-meta k)))))
)

(defn ^:dev/after-load init-endpoints! []
Expand Down
2 changes: 0 additions & 2 deletions src/sb/schema.cljc
Expand Up @@ -218,13 +218,11 @@
:member "a3"
:project "a4"
:field "a5"
:entry "a6"
:discussion "a7"
:post "a8"
:comment "a9"
:notification "aa"
:tag "ab"
:tag-spec "ac"
:chat "ad"
:message "ae"
:roles "af"
Expand Down
2 changes: 1 addition & 1 deletion src/sb/server/assets.clj
Expand Up @@ -103,7 +103,7 @@
:entity/created-by account-id}
(validate/assert :asset/as-map))])
{:status 200
:body {:entity/id asset-id}})))
:body [:entity/id asset-id]})))

(defn resizable? [content-type]
(not (contains? #{"image/svg+xml" "image/gif"} content-type)))
Expand Down

0 comments on commit cf625cd

Please sign in to comment.