π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(photos):surface-upload-failures-in-red
Aswin Asok23330b3a7d65
diff --git a/web/apps/photos/tests/upload-progress.test.ts b/web/apps/photos/tests/upload-progress.test.tsnew file mode 100644index 0000000000..689c715589--- /dev/null+++ b/web/apps/photos/tests/upload-progress.test.ts@@ -0,0 +1,126 @@+import { ThemeProvider } from "@mui/material/styles";+import { photosTheme } from "ente-base/components/utils/theme";+import translation from "ente-base/locales/en-US/translation.json";+import type { SegregatedFinishedUploads } from "ente-gallery/components/upload-progress-stats";+import {+ UploadProgressContext,+ type UploadProgressContextT,+} from "ente-gallery/components/upload-progress/context";+import { uploadCountsText } from "ente-gallery/components/upload-progress/helpers";+import { MinimizedUploadProgress } from "ente-gallery/components/upload-progress/MinimizedUploadProgress";+import i18n from "i18next";+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { beforeAll, expect, test } from "vitest";++beforeAll(async () => {+ await i18n.init({+ lng: "en-US",+ resources: { "en-US": { translation } },+ interpolation: { escapeValue: false },+ });+});++const context: UploadProgressContextT = {+ onClose: () => undefined,+ uploadCounter: { finished: 0, total: 0 },+ uploadPhase: "done",+ percentComplete: 100,+ retryFailed: () => undefined,+ inProgressUploads: [],+ uploadFileNames: new Map(),+ finishedUploads: new Map(),+ preUploadSkippedFiles: [],+ hasLivePhotos: false,+ setExpanded: () => undefined,+ dragPosition: undefined,+ setDragPosition: () => undefined,+};++const renderProgress = (value: UploadProgressContextT) =>+ renderToStaticMarkup(+ createElement(+ ThemeProvider,+ { theme: photosTheme },+ createElement(+ UploadProgressContext.Provider,+ { value },+ createElement(MinimizedUploadProgress),+ ),+ ),+ );++test.each(["failed", "blocked"] as const)(+ "%s uploads show failure text and a red popup",+ (type) => {+ const value = { ...context, finishedUploads: new Map([[type, [1]]]) };+ expect(uploadCountsText(value)).toBe("1 failed");+ const html = renderProgress(value);+ expect(html).toContain(">Failed uploads<");+ expect(html).toContain(">1 failed<");+ expect(html).not.toContain(">Upload complete<");+ expect(html).toContain(+ "background-color:var(--mui-palette-critical-main)",+ );+ },+);++test("mixed results keep completed, skipped, and failed counts separate", () => {+ const finishedUploads: SegregatedFinishedUploads = new Map([+ ["uploaded", [1, 2]],+ ["alreadyUploaded", [3]],+ ["failed", [4]],+ ["blocked", [5]],+ ]);+ const value = { ...context, finishedUploads };+ expect(uploadCountsText(value)).toBe("2 uploaded, 1 skipped, 2 failed");+ expect(renderProgress(value)).toContain(+ ">2 uploaded, 1 skipped, 2 failed<",+ );+});++test("failures remain visible while other files are still uploading", () => {+ const value: UploadProgressContextT = {+ ...context,+ uploadPhase: "uploading",+ uploadCounter: { finished: 2, total: 4 },+ finishedUploads: new Map([["failed", [1]]]),+ };+ expect(uploadCountsText(value)).toBe("2 of 4 items, 1 failed");+ expect(renderProgress(value)).toContain(+ "background-color:var(--mui-palette-critical-main)",+ );+});++test("ordinary skips keep the neutral popup and their own count", () => {+ const value: UploadProgressContextT = {+ ...context,+ finishedUploads: new Map([+ ["alreadyUploaded", [1]],+ ["unsupported", [2]],+ ]),+ preUploadSkippedFiles: [{ type: "hiddenFile", name: ".hidden.jpg" }],+ };+ expect(uploadCountsText(value)).toBe("3 skipped");+ const html = renderProgress(value);+ expect(html).toContain(">Upload complete<");+ expect(html).not.toContain(+ "background-color:var(--mui-palette-critical-main)",+ );+});++test("a successful retry clears the failure title and red popup", () => {+ const value: UploadProgressContextT = {+ ...context,+ finishedUploads: new Map([["failed", [1]]]),+ };+ expect(renderProgress(value)).toContain(">Failed uploads<");+ value.finishedUploads = new Map([["uploaded", [1]]]);+ expect(uploadCountsText(value)).toBe("1 uploaded");+ const html = renderProgress(value);+ expect(html).toContain(">Upload complete<");+ expect(html).toContain(">1 uploaded<");+ expect(html).not.toContain(+ "background-color:var(--mui-palette-critical-main)",+ );+});diff --git a/web/apps/photos/vitest.config.ts b/web/apps/photos/vitest.config.tsnew file mode 100644index 0000000000..cfa752fdf7--- /dev/null+++ b/web/apps/photos/vitest.config.ts@@ -0,0 +1,3 @@+import { defineConfig } from "vitest/config";++export default defineConfig({ oxc: { jsx: { runtime: "automatic" } } });diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex 0ea12e56da..099b1c67ba 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -72,6 +72,7 @@"upload_cancelling": "Cancelling remaining uploads","upload_done": "{{count, number}} uploaded","upload_skipped": "{{count, number}} skipped",+ "upload_failed": "{{count, number}} failed","import_library": "Import your library","need_help": "Need help?","provider_not_listed": "Not seeing your provider",diff --git a/web/packages/gallery/components/upload-progress-stats.ts b/web/packages/gallery/components/upload-progress-stats.tsindex 2c65e85c9d..c4a8054467 100644--- a/web/packages/gallery/components/upload-progress-stats.ts+++ b/web/packages/gallery/components/upload-progress-stats.ts@@ -28,7 +28,7 @@ export type UploadStatKind = "inProgress" | FinishedStatKind;export const uploadStatColors: Record<FinishedStatKind, string> = {completed: "#08c225",skipped: "#2c83ff",- failed: "#ff8a1f",+ failed: "var(--mui-palette-critical-main)",};// "failed" may be retryable; "skipped" cannot be uploaded.diff --git a/web/packages/gallery/components/upload-progress/MinimizedUploadProgress.tsx b/web/packages/gallery/components/upload-progress/MinimizedUploadProgress.tsxindex b49088f790..6f641c646c 100644--- a/web/packages/gallery/components/upload-progress/MinimizedUploadProgress.tsx+++ b/web/packages/gallery/components/upload-progress/MinimizedUploadProgress.tsx@@ -15,6 +15,7 @@ import {import type { SystemStyleObject } from "@mui/system";import { t } from "i18next";import { useRef } from "react";+import { uploadCompletionCounts } from "../upload-progress-stats";import { uploadSheetMediaQuery } from "./bottom-sheet";import type { DragPosition } from "./context";import { useUploadProgressContext } from "./context";@@ -33,6 +34,19 @@ export function MinimizedUploadProgress() {useMinimizedUploadDrag(dragSurfaceRef);const progress = normalizePercent(percentComplete);const showUploadProgress = context.uploadPhase == "uploading";+ const hasFailures =+ uploadCompletionCounts(+ context.finishedUploads,+ context.preUploadSkippedFiles,+ ).failed > 0;+ const title =+ context.uploadPhase == "done" && hasFailures+ ? t("failed_uploads")+ : showUploadProgress+ ? t("uploaded_percent", { percent: progress })+ : context.uploadPhase == "done"+ ? uploadStatusText(context.uploadPhase)+ : t("file_upload");const setDragSurface = (surface: HTMLDivElement | null) => {dragSurfaceRef.current = surface;@@ -47,7 +61,10 @@ export function MinimizedUploadProgress() {><Paperref={setDragSurface}- sx={[minimizedPaperSx, minimizedPositionSx(dragPosition)]}+ sx={[+ (theme) => minimizedPaperSx(theme, hasFailures),+ minimizedPositionSx(dragPosition),+ ]}><Stackdirection="row"@@ -56,7 +73,10 @@ export function MinimizedUploadProgress() {<Box{...dragHandleProps}aria-hidden- sx={minimizedDragIconSx}+ sx={[+ minimizedDragIconSx,+ hasFailures && failureForegroundSx,+ ]}><HugeiconsIconicon={DragDropVerticalIcon}@@ -65,15 +85,20 @@ export function MinimizedUploadProgress() {/></Box><Stack sx={{ flex: 1, minWidth: 0, gap: 0.5 }}>- <Typography sx={minimizedTitleSx}>- {showUploadProgress- ? t("uploaded_percent", { percent: progress })- : context.uploadPhase == "done"- ? uploadStatusText(context.uploadPhase)- : t("file_upload")}- </Typography>- <Typography sx={minimizedSubtitleSx}>- {showUploadProgress || context.uploadPhase == "done"+ <Typography sx={minimizedTitleSx}>{title}</Typography>+ <Typography+ sx={[+ minimizedSubtitleSx,+ hasFailures && {+ ...failureForegroundSx,+ whiteSpace: "normal",+ overflowWrap: "anywhere",+ },+ ]}+ >+ {showUploadProgress ||+ context.uploadPhase == "done" ||+ hasFailures? uploadCountsText(context): uploadStatusText(context.uploadPhase)}</Typography>@@ -81,14 +106,20 @@ export function MinimizedUploadProgress() {<IconButtonaria-label={t("expand")}onClick={handleExpand}- sx={minimizedIconButtonSx}+ sx={[+ minimizedIconButtonSx,+ hasFailures && failureForegroundSx,+ ]}><UnfoldMoreIcon sx={{ fontSize: 22 }} /></IconButton><IconButtonaria-label={t("close")}onClick={onClose}- sx={minimizedIconButtonSx}+ sx={[+ minimizedIconButtonSx,+ hasFailures && failureForegroundSx,+ ]}><CloseIcon sx={{ fontSize: 22 }} /></IconButton>@@ -115,22 +146,28 @@ const minimizedSnackbarSx = {bottom: "calc(32px + env(safe-area-inset-bottom, 0px))",},};-const minimizedPaperSx = (theme: Theme): SystemStyleObject<Theme> => ({+const minimizedPaperSx = (+ theme: Theme,+ hasFailures: boolean,+): SystemStyleObject<Theme> => ({width: "min(400px, calc(100svw - 32px))",p: "16px 16px 16px 12px",borderRadius: "20px",- backgroundColor: "#fff",+ backgroundColor: hasFailures ? "critical.main" : "#fff",backgroundImage: "none",boxShadow: "0px 4px 4px rgba(0 0 0 / 0.16)",- color: "text.base",+ color: hasFailures ? "critical.contrastText" : "text.base",overflow: "hidden",[uploadSheetMediaQuery]: {width: "calc(100svw - 32px)",animation: `${minimizedRiseAnimation} 320ms cubic-bezier(0.2, 0.8, 0.2, 1)`,"@media (prefers-reduced-motion: reduce)": { animation: "none" },},- ...theme.applyStyles("dark", { backgroundColor: "#2b2b2b" }),+ ...theme.applyStyles("dark", {+ backgroundColor: hasFailures ? "critical.main" : "#2b2b2b",+ }),});+const failureForegroundSx = { color: "inherit" };const minimizedDragIconSx = {display: "inline-flex",flexShrink: 0,diff --git a/web/packages/gallery/components/upload-progress/helpers.ts b/web/packages/gallery/components/upload-progress/helpers.tsindex ff5d729f8c..20fc912b23 100644--- a/web/packages/gallery/components/upload-progress/helpers.ts+++ b/web/packages/gallery/components/upload-progress/helpers.ts@@ -99,26 +99,29 @@ export const uploadCountsText = ({| "finishedUploads"| "preUploadSkippedFiles">) => {+ const {+ completed: count,+ skipped,+ failed,+ } = uploadCompletionCounts(finishedUploads, preUploadSkippedFiles);if (uploadPhase == "done") {- const {- completed: count,- skipped,- failed,- } = uploadCompletionCounts(finishedUploads, preUploadSkippedFiles);- const notCount = skipped + failed;const items: string[] = [];if (count) items.push(t("upload_done", { count }));- if (notCount) items.push(t("upload_skipped", { count: notCount }));+ if (skipped) items.push(t("upload_skipped", { count: skipped }));+ if (failed) items.push(t("upload_failed", { count: failed }));return items.length? formattedListJoin(items): t("upload_done", { count });}- return uploadCounter.total+ const progress = uploadCounter.total? t("upload_items_progress", {count: uploadCounter.finished,total: uploadCounter.total,}): uploadStatusText(uploadPhase);+ return failed+ ? formattedListJoin([progress, t("upload_failed", { count: failed })])+ : progress;};export const normalizePercent = (value: number) =>