0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-06 12:01:19 -05:00

🐛 Fix some problems with error handling

This commit is contained in:
Eva Marco 2025-01-14 10:24:04 +01:00
parent dea866d3a3
commit 6eea633ca9
4 changed files with 24 additions and 9 deletions

View file

@ -321,8 +321,9 @@
children]])]))
(mf/defc menu-tree
[{:keys [selected-shapes submenu-offset submenu-direction type] :as context-data}]
(let [entries (if (seq selected-shapes)
[{:keys [selected-shapes submenu-offset submenu-direction type errors] :as context-data}]
(let [entries (if (and (not (some? errors))
(seq selected-shapes))
(if (some? type)
(submenu-actions-selection-actions context-data)
(selection-actions context-data))
@ -343,7 +344,7 @@
:selected? selected?}])])))
(mf/defc token-context-menu-tree
[{:keys [width direction] :as mdata}]
[{:keys [width direction errors] :as mdata}]
(let [objects (mf/deref refs/workspace-page-objects)
selected (mf/deref refs/selected-shapes)
selected-shapes (into [] (keep (d/getf objects)) selected)
@ -354,6 +355,7 @@
[:& menu-tree {:submenu-offset width
:submenu-direction direction
:token token
:errors errors
:selected-token-set-path selected-token-set-path
:selected-shapes selected-shapes}]]))

View file

@ -82,6 +82,7 @@
(st/emit! (dt/show-token-context-menu
{:type :token
:position (dom/get-client-position event)
:errors (:errors token)
:token-name (:name token)}))))
on-toggle-open-click (mf/use-fn
@ -120,6 +121,7 @@
[:> icon-button* {:on-click on-popover-open-click
:variant "ghost"
:icon "add"
;; TODO: This needs translation
:aria-label (str "Add token: " title)}]]
(when open?
[:& cmm/asset-section-block {:role :content}

View file

@ -174,6 +174,7 @@
[err]
(let [[header-1 header-2 & errors] (str/split err "\n")]
(when (and
;; TODO: This needs translations
(= header-1 "Error: ")
(= header-2 "Reference Errors:"))
errors)))
@ -206,10 +207,11 @@
;; === Errors
(defn humanize-errors [{:keys [errors value] :as _token}]
(defn humanize-errors [{:keys [errors] :as token}]
(->> (map (fn [err]
(case err
:error.style-dictionary/missing-reference (str "Could not resolve reference token with the name: " value)
(case (:error/code err)
;; TODO: This needs translations
:error.style-dictionary/missing-reference (str "Could not resolve reference token with the name: " (:error/value err))
nil))
errors)
(str/join "\n")))

View file

@ -7,6 +7,7 @@
[app.main.ui.ds.foundations.utilities.token.token-status :refer [token-status-icon*]]
[app.main.ui.workspace.tokens.style-dictionary :as sd]
[app.main.ui.workspace.tokens.token :as wtt]
[app.util.dom :as dom]
[app.util.i18n :refer [tr]]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
@ -21,6 +22,13 @@
(wtt/resolved-value-hex theme-token))
color (or color (wtt/resolved-value-hex token))
on-click
(mf/use-callback
(mf/deps errors? on-click)
(fn [event]
(dom/stop-propagation event)
(when (and (not (seq errors)) on-click)
(on-click event))))
token-status-id (cond
half-applied
@ -35,14 +43,15 @@
:token-pill-invalid-applied (and full-applied errors?))
:type "button"
:title (cond
errors? (sd/humanize-errors token)
errors? (if (nil? theme-token)
(tr "workspace.token-set.not-active")
(sd/humanize-errors token))
:else (->> [(str "Token: " name)
(tr "workspace.token.original-value" value)
(tr "workspace.token.resolved-value" resolved-value)]
(str/join "\n")))
:on-click on-click
:on-context-menu on-context-menu
:disabled errors?}
:on-context-menu on-context-menu}
(cond
errors?
[:> icon*