mirror of
https://github.com/penpot/penpot.git
synced 2026-11-18 16:12:24 +00:00
🐛 Show the date of a restored autosaved version in the restore notice (#13120)
When a peer restored an autosaved version, the notice said "restored an earlier version" instead of naming it by its date and time. The modal wrapper passes the props map to the component without camelCasing its keys, so the `created-at` prop reached the component as "created-at" while it read `createdAt`, and the date was always nil. Named versions were fine because `label` is one word. The prop is now `date`, and a test renders the registered modal the way the wrapper does. Closes #13037 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
a84d76d397
commit
eb7860fcd7
@ -359,7 +359,7 @@
|
||||
(modal/show :file-restored
|
||||
{:fullname (restorer-fullname state profile-id session-id)
|
||||
:label label
|
||||
:created-at created-at
|
||||
:date created-at
|
||||
;; Made on the replaced version, so the reload drops them
|
||||
:unsaved (boolean (seq (dps/pending-file-changes state file)))}))
|
||||
(rx/empty))))))
|
||||
|
||||
@ -36,7 +36,9 @@
|
||||
which was reloaded, and whether their edits not saved yet were lost."
|
||||
{::mf/register modal/components
|
||||
::mf/register-as :file-restored}
|
||||
[{:keys [fullname label created-at unsaved]}]
|
||||
;; The modal wrapper passes the props map without camelCasing its keys,
|
||||
;; so every prop of this component must be a one-word name.
|
||||
[{:keys [fullname label date unsaved]}]
|
||||
(let [on-close (mf/use-fn #(st/emit! (modal/hide)))]
|
||||
[:div {:class (stl/css :modal-overlay)}
|
||||
[:div {:class (stl/css :modal-dialog)
|
||||
@ -49,7 +51,7 @@
|
||||
:class (stl/css :modal-title)}
|
||||
(tr "workspace.file-restored.title")]
|
||||
[:> text* {:as "p" :typography t/body-large}
|
||||
(restored-message fullname label created-at)]
|
||||
(restored-message fullname label date)]
|
||||
(when unsaved
|
||||
[:> text* {:as "p" :typography t/body-large}
|
||||
(tr "workspace.file-restored.unsaved-changes")])
|
||||
|
||||
@ -140,7 +140,7 @@
|
||||
props (:props (shown-modal events))]
|
||||
(t/is (= "Ada" (:fullname props)))
|
||||
(t/is (= "Hand-off v2" (:label props)))
|
||||
(t/is (= created-at (:created-at props)))
|
||||
(t/is (= created-at (:date props)))
|
||||
(t/is (true? (:unsaved props)))))
|
||||
|
||||
;; Scenario: the restoring session left before its message arrived, so it
|
||||
|
||||
@ -6,10 +6,14 @@
|
||||
|
||||
(ns frontend-tests.ui.file-restored-modal-test
|
||||
(:require
|
||||
["react-dom/server" :as rds]
|
||||
[app.common.time :as ct]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.ui.workspace.file-restored-modal :as frm]
|
||||
[app.util.i18n :as i18n]
|
||||
[cljs.test :as t :include-macros true]))
|
||||
[cljs.test :as t :include-macros true]
|
||||
[cuerdas.core :as str]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defn- message
|
||||
"The translation key and arguments of the restore message."
|
||||
@ -32,3 +36,17 @@
|
||||
(message "Ada" nil nil)))
|
||||
(t/is (= ["workspace.file-restored.message-anonymous"]
|
||||
(message nil nil nil)))))
|
||||
|
||||
(defn- render-modal
|
||||
"Markup of the registered `:file-restored` modal for the `props` map,
|
||||
rendered the way the modal wrapper does it (`mf/element` with the map)."
|
||||
[props]
|
||||
(with-redefs [i18n/tr (fn ([key] key) ([key & args] (str/join "|" (into [key] args))))]
|
||||
(rds/renderToStaticMarkup
|
||||
(mf/element (get @modal/components :file-restored) props))))
|
||||
|
||||
(t/deftest the-modal-shows-the-date-of-an-unnamed-version
|
||||
(let [created-at (ct/now)
|
||||
markup (render-modal {:fullname "Ada" :date created-at :unsaved false})]
|
||||
(t/is (str/includes? markup (str "workspace.file-restored.message-date|Ada|"
|
||||
(ct/format-inst created-at "PPp"))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user