diff --git a/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js b/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js index ac57d851f4..b898123a22 100644 --- a/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js +++ b/frontend/playwright/ui/visual-specs/visual-dashboard.spec.js @@ -579,6 +579,42 @@ test.describe("Dashboard list controls", () => { }); }); +test.describe("Progress notification controls", () => { + test("Restore progress and close button", async ({ page }) => { + const shot = { maxDiffPixelRatio: 0, threshold: 0 }; + await DashboardPage.mockConfigFlags(page, ["disable-onboarding"]); + const dashboardPage = new DashboardPage(page); + await dashboardPage.setupDashboardFull(); + // Deleted files due in 2100, so the trash keeps them. + await dashboardPage.mockRPC( + "get-team-deleted-files?team-id=*", + "dashboard/get-team-deleted-files-pending.json", + ); + await dashboardPage.mockRPC( + "get-projects?team-id=*", + "dashboard/get-projects-deleted.json", + ); + // Never answer the restore, so the notification stays on screen. + await page.route(/restore-deleted-team-files/, () => {}); + await dashboardPage.goToDeleted(); + + await page.getByRole("button", { name: "Restore All" }).click(); + await page.getByRole("button", { name: "Continue" }).click(); + + const notification = page.locator( + "[class*='components_progress__progress-modal']", + ); + await expect(notification).toBeVisible(); + await page.mouse.move(10, 10); + await expect(notification).toHaveScreenshot(shot); + await notification.getByRole("button").hover(); + await expect(notification).toHaveScreenshot(shot); + + await notification.getByRole("button").click(); + await expect(notification).toBeHidden(); + }); +}); + test.describe("Team modals controls", () => { const shot = { maxDiffPixelRatio: 0, threshold: 0 }; diff --git a/frontend/src/app/main/data/common.cljs b/frontend/src/app/main/data/common.cljs index 122be2bb5e..a3219f0b64 100644 --- a/frontend/src/app/main/data/common.cljs +++ b/frontend/src/app/main/data/common.cljs @@ -348,6 +348,14 @@ (def ^:private check-progress-params (sm/check-fn schema:progress-params)) +(def ^:private schema:progress-update-params + [:map {:title "ProgressUpdate"} + [:index ::sm/int] + [:total ::sm/int]]) + +(def ^:private check-progress-update-params + (sm/check-fn schema:progress-update-params)) + (defn initialize-progress [& {:keys [key index total hints slow-progress-threshold] :as params}] @@ -372,7 +380,7 @@ (defn update-progress [{:keys [index total] :as params}] - (assert (check-progress-params params)) + (assert (check-progress-update-params params)) (ptk/reify ::update-progress ptk/UpdateEvent @@ -381,7 +389,7 @@ (fn [state] (let [last-update (get state :last-update) hints (get state :hints) - threshold (get state :slow-progress-threshold) + threshold (get state :threshold) time-diff (ct/diff-ms last-update (ct/now)) healthy? (< time-diff threshold) diff --git a/frontend/src/app/main/data/dashboard.cljs b/frontend/src/app/main/data/dashboard.cljs index 38645f91dd..4614048697 100644 --- a/frontend/src/app/main/data/dashboard.cljs +++ b/frontend/src/app/main/data/dashboard.cljs @@ -822,7 +822,7 @@ {:slow-progress-threshold mconst/default-slow-progress-threshold :total (count ids) - :hints {:progress progress-hint + :hints {:normal progress-hint :slow slow-hint}})) (->> stream @@ -942,7 +942,7 @@ {:slow-progress-threshold mconst/default-slow-progress-threshold :total (count ids) - :hints {:progress progress-hint + :hints {:normal progress-hint :slow slow-hint}})) (let [stream (->> (rp/cmd! ::sse/restore-deleted-team-files {:team-id team-id :ids ids}) diff --git a/frontend/src/app/main/ui/components/progress.cljs b/frontend/src/app/main/ui/components/progress.cljs index 35ae9f3101..9015694597 100644 --- a/frontend/src/app/main/ui/components/progress.cljs +++ b/frontend/src/app/main/ui/components/progress.cljs @@ -13,20 +13,12 @@ [app.main.data.common :as dcm] [app.main.refs :as refs] [app.main.store :as st] - [app.main.ui.icons :as deprecated-icons] + [app.main.ui.ds.buttons.icon-button :refer [icon-button*]] + [app.main.ui.ds.foundations.assets.icon :as i :refer [icon*]] [app.util.i18n :as i18n :refer [tr]] [app.util.theme :as theme] [rumext.v2 :as mf])) -(def ^:private neutral-icon - (deprecated-icons/icon-xref :msg-neutral (stl/css :icon))) - -(def ^:private error-icon - (deprecated-icons/icon-xref :delete-text (stl/css :icon))) - -(def ^:private close-icon - (deprecated-icons/icon-xref :close (stl/css :close-icon))) - (mf/defc progress-notification-widget* [] (let [state (mf/deref refs/progress) @@ -67,9 +59,8 @@ (when visible? [:div {:class (stl/css-case :progress-modal true :has-error error?)} - (if error? - error-icon - neutral-icon) + [:> icon* {:icon-id (if error? i/delete-text i/msg-neutral) + :class (stl/css :icon)}] [:div {:class (stl/css :title)} [:div {:class (stl/css :title-text)} hint] @@ -82,9 +73,12 @@ [:span {:class (stl/css :progress)} (dm/str progress " / " total)])] - [:button {:class (stl/css :progress-close-button) - :on-click toggle-detail-visibility} - close-icon] + [:> icon-button* {:variant "action" + :aria-label (tr "labels.close") + :tooltip-class (stl/css :progress-close-button) + :tooltip-placement "top-left" + :on-click toggle-detail-visibility + :icon i/close}] (when-not error? [:svg {:class (stl/css :progress-bar) diff --git a/frontend/src/app/main/ui/components/progress.scss b/frontend/src/app/main/ui/components/progress.scss index 333ec8be1c..215b0cc446 100644 --- a/frontend/src/app/main/ui/components/progress.scss +++ b/frontend/src/app/main/ui/components/progress.scss @@ -4,66 +4,58 @@ // // Copyright (c) KALEIDOS SUBSIDIARY SL -@use "refactor/common-refactor.scss" as deprecated; +@use "ds/_borders.scss" as *; +@use "ds/_sizes.scss" as *; +@use "ds/_utils.scss" as *; +@use "ds/typography.scss" as *; -// PROGRESS WIDGET -.progress-widget { - @include deprecated.flex-center; - - width: deprecated.$s-28; - height: deprecated.$s-28; -} - -// PROGRESS MODAL .progress-modal { - --export-modal-bg-color: var(--alert-background-color-default); - --export-modal-fg-color: var(--alert-text-foreground-color-default); - --export-modal-icon-color: var(--alert-icon-foreground-color-default); - --export-modal-border-color: var(--alert-border-color-default); + --export-modal-bg-color: var(--color-background-primary); + --export-modal-fg-color: var(--color-foreground-primary); + --export-modal-icon-color: var(--color-foreground-primary); + --export-modal-border-color: var(--color-background-quaternary); position: absolute; - right: deprecated.$s-16; - top: deprecated.$s-48; + inset-inline-end: var(--sp-l); + inset-block-start: px2rem(48); display: grid; - grid-template-columns: deprecated.$s-24 1fr deprecated.$s-24; + grid-template-columns: $sz-24 1fr auto; grid-template-areas: "icon text close" "bar bar bar"; - gap: deprecated.$s-4 deprecated.$s-8; - padding-block-start: deprecated.$s-8; + gap: var(--sp-xs) var(--sp-s); + padding-block-start: var(--sp-s); background-color: var(--export-modal-bg-color); - border: deprecated.$s-1 solid var(--export-modal-border-color); - border-radius: deprecated.$br-8; - z-index: deprecated.$z-index-modal; + border: $b-1 solid var(--export-modal-border-color); + border-radius: $br-8; + z-index: var(--z-index-notifications); overflow: hidden; } .has-error { - --export-modal-bg-color: var(--alert-background-color-error); - --export-modal-fg-color: var(--alert-text-foreground-color-error); - --export-modal-icon-color: var(--alert-icon-foreground-color-error); - --export-modal-border-color: var(--alert-border-color-error); + --export-modal-bg-color: var(--color-background-error); + --export-modal-fg-color: var(--color-foreground-primary); + --export-modal-icon-color: var(--color-accent-error); + --export-modal-border-color: var(--color-accent-error); grid-template-areas: "icon text close"; - gap: deprecated.$s-8; - padding-block: deprecated.$s-8; + gap: var(--sp-s); + padding-block: var(--sp-s); } .icon { - @extend %button-icon; - grid-area: icon; align-self: center; - margin-inline-start: deprecated.$s-8; - stroke: var(--export-modal-icon-color); + margin-inline-start: var(--sp-s); + color: var(--export-modal-icon-color); } .title { - @include deprecated.body-medium-typography; + @include use-typography("body-medium"); display: grid; grid-template-columns: auto 1fr; - gap: deprecated.$s-8; + gap: var(--sp-s); grid-area: text; align-self: center; padding: 0; @@ -72,39 +64,33 @@ } .progress { - @include deprecated.body-medium-typography; + @include use-typography("body-medium"); - padding-left: deprecated.$s-8; + padding-inline-start: var(--sp-s); margin: 0; align-self: center; - color: var(--modal-text-foreground-color); + color: var(--color-foreground-secondary); } .retry-btn { - @include deprecated.button-style; - @include deprecated.body-small-typography; + @include use-typography("body-small"); display: inline; - text-align: left; - color: var(--modal-link-foreground-color); + text-align: start; + color: var(--color-accent-primary); margin: 0; padding: 0; + border: none; + background: none; + cursor: pointer; } .progress-close-button { - @include deprecated.button-style; - - padding: 0; - margin-inline-end: deprecated.$s-8; -} - -.close-icon { - @extend %button-icon; - - stroke: var(--export-modal-icon-color); + grid-area: close; + margin-inline-end: var(--sp-xs); } .progress-bar { - margin-top: 0; + margin-block-start: 0; grid-area: bar; } diff --git a/frontend/test/frontend_tests/data/common_test.cljs b/frontend/test/frontend_tests/data/common_test.cljs index 2b596725a7..19098bbfa5 100644 --- a/frontend/test/frontend_tests/data/common_test.cljs +++ b/frontend/test/frontend_tests/data/common_test.cljs @@ -207,3 +207,35 @@ (t/is (false? (get-in state [:team :permissions :can-edit]))) (t/is (false? (get-in state [:teams current-team-id :permissions :can-edit]))) (t/is (true? (get-in state [:teams other-team-id :permissions :can-edit]))))) + +;; --- Progress notification + +(def ^:private progress-hints + {:normal (constantly "Restoring files…") + :slow (constantly "Restore unexpectedly slow")}) + +(defn- progress-state + [threshold] + (ptk/update (dcm/initialize-progress {:total 3 + :slow-progress-threshold threshold + :hints progress-hints}) + {})) + +(t/deftest initialize-progress-shows-the-normal-hint + (let [progress (:progress (progress-state 60000))] + (t/is (= "Restoring files…" (:hint progress))) + (t/is (true? (:healthy progress))) + (t/is (= 0 (:progress progress))))) + +(t/deftest update-progress-within-the-threshold-stays-healthy + (let [state (progress-state 60000) + progress (:progress (ptk/update (dcm/update-progress {:index 1 :total 3}) state))] + (t/is (= 1 (:progress progress))) + (t/is (true? (:healthy progress))) + (t/is (= "Restoring files…" (:hint progress))))) + +(t/deftest update-progress-past-the-threshold-shows-the-slow-hint + (let [state (progress-state 0) + progress (:progress (ptk/update (dcm/update-progress {:index 1 :total 3}) state))] + (t/is (false? (:healthy progress))) + (t/is (= "Restore unexpectedly slow" (:hint progress)))))