π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Centralize MiniDialog warning artwork by kind
AswinAsok18ba7dc6f9cd
diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsxindex da32e3a779..c2b1edbad5 100644--- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx+++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx@@ -1,5 +1,4 @@import type { RemotePullOpts } from "@/components/gallery";-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";import { downloadAndSaveCollectionFiles } from "@/services/save";import {CleanIcon,@@ -196,7 +195,7 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({if (hasAlbumFiles) {showMiniDialog({title: t("delete_album_title"),- illustration: <DialogWarningIllustration />,+ kind: "info",message: (<Transi18nKey={"delete_album_message"}@@ -226,7 +225,7 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({showMiniDialog({title: t("delete_album_title"),- illustration: <DialogWarningIllustration />,+ kind: "info",message: (<Transi18nKey={"delete_album_message_no_photos"}@@ -263,7 +262,7 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({const confirmEmptyTrash = () =>showMiniDialog({title: t("empty_trash_title"),- illustration: <DialogWarningIllustration color="red" />,+ kind: "warning",message: t("empty_trash_message"),continue: {text: t("empty_trash"),diff --git a/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsx b/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsxindex 05e43fbd36..8a23357295 100644--- a/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsx+++ b/web/apps/photos/src/components/Collections/EditAlbumDetailsDialog.tsx@@ -1,4 +1,3 @@-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";import CloseIcon from "@mui/icons-material/Close";import {Box,@@ -114,7 +113,7 @@ export const EditAlbumDetailsDialog: React.FC<EditAlbumDetailsDialogProps> = ({if (hasChanges) {showMiniDialog({title: t("discard_changes"),- illustration: <DialogWarningIllustration color="red" />,+ kind: "warning",message: t("discard_changes_confirm_message"),continue: {text: t("discard"),diff --git a/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.ts b/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.tsindex 787f6dfd13..1422bdfd28 100644--- a/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.ts+++ b/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.ts@@ -16,9 +16,7 @@ import {} from "ente-new/photos/services/photos-fdb";import { usePhotosAppContext } from "ente-new/photos/types/context";import { t } from "i18next";-import { createElement } from "react";import { trashFilesDialogAttributes } from "../utils/dialog-attributes";-import { DialogWarningIllustration } from "../utils/DialogWarningIllustration";export const useDeleteEmptyAlbums = (collectionSummaries: CollectionSummary[],@@ -108,7 +106,7 @@ export const useDeleteEmptyAlbums = (showMiniDialog({...attributes,title: t("delete_empty_albums_title"),- illustration: createElement(DialogWarningIllustration),+ kind: "info",message: t("delete_empty_albums_message", {count: candidateIDs.length,}),diff --git a/web/apps/photos/src/components/SelectedFileOptions.tsx b/web/apps/photos/src/components/SelectedFileOptions.tsxindex 5fccdfa458..e112a42302 100644--- a/web/apps/photos/src/components/SelectedFileOptions.tsx+++ b/web/apps/photos/src/components/SelectedFileOptions.tsx@@ -1,6 +1,5 @@import type { CollectionSelectorAttributes } from "@/components/CollectionSelector";import type { GalleryBarMode } from "@/components/gallery/reducer";-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";import {getAvailableFileActions,type FileContextAction,@@ -115,7 +114,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({const handleDeletePermanently = () =>showMiniDialog({title: t("delete_files_title"),- illustration: <DialogWarningIllustration color="red" />,+ kind: "warning",message: t("delete_files_message"),continue: {text: t("delete"),diff --git a/web/apps/photos/src/components/gallery/PeopleHeader.tsx b/web/apps/photos/src/components/gallery/PeopleHeader.tsxindex b50d3e927f..4f336c0ceb 100644--- a/web/apps/photos/src/components/gallery/PeopleHeader.tsx+++ b/web/apps/photos/src/components/gallery/PeopleHeader.tsx@@ -1,4 +1,3 @@-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";import { useWrapAsyncOperation } from "@/components/utils/use-wrap-async";import AddIcon from "@mui/icons-material/Add";import CheckIcon from "@mui/icons-material/Check";@@ -618,7 +617,7 @@ const SuggestionsDialog: React.FC<SuggestionsDialogProps> = ({if (hasUnsavedChanges) {showMiniDialog({message: t("discard_changes_confirm_message"),- illustration: <DialogWarningIllustration color="red" />,+ kind: "warning",continue: {text: t("discard_changes"),color: "critical",diff --git a/web/apps/photos/src/components/sidebar/Sidebar.tsx b/web/apps/photos/src/components/sidebar/Sidebar.tsxindex 6c77ffafa0..b0b4d6aab8 100644--- a/web/apps/photos/src/components/sidebar/Sidebar.tsx+++ b/web/apps/photos/src/components/sidebar/Sidebar.tsx@@ -1,5 +1,4 @@import { Export } from "@/components/Export";-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";import { downloadAppDialogAttributes } from "@/components/utils/download";import exportService from "@/services/export";import { performSidebarAction as performSidebarRegistryAction } from "@/services/search/sidebar-search-registry";@@ -177,7 +176,7 @@ export const Sidebar: React.FC<SidebarProps> = ({() =>showMiniDialog({message: t("logout_message"),- illustration: <DialogWarningIllustration />,+ kind: "info",continue: {text: t("logout"),color: "critical",diff --git a/web/apps/photos/src/components/sidebar/account/SessionsSettings.tsx b/web/apps/photos/src/components/sidebar/account/SessionsSettings.tsxindex 21e77c3565..0f8b29a211 100644--- a/web/apps/photos/src/components/sidebar/account/SessionsSettings.tsx+++ b/web/apps/photos/src/components/sidebar/account/SessionsSettings.tsx@@ -1,4 +1,3 @@-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";import CheckIcon from "@mui/icons-material/Check";import DevicesIcon from "@mui/icons-material/Devices";import RefreshIcon from "@mui/icons-material/Refresh";@@ -120,7 +119,7 @@ const SessionsSettingsContents: React.FC<SessionsSettingsContentsProps> = ({showMiniDialog({title: t("terminate_session"),- illustration: <DialogWarningIllustration />,+ kind: "info",message: isCurrentDevice ? (t("terminate_session_confirm_message_self")) : (@@ -152,9 +151,7 @@ const SessionsSettingsContents: React.FC<SessionsSettingsContentsProps> = ({} else {showMiniDialog({title: t("error"),- illustration: (- <DialogWarningIllustration />- ),+ kind: "error",message: t("terminate_session_failed"),});}diff --git a/web/apps/photos/src/components/utils/DialogWarningIllustration.tsx b/web/apps/photos/src/components/utils/DialogWarningIllustration.tsxdeleted file mode 100644index 174a213e56..0000000000--- a/web/apps/photos/src/components/utils/DialogWarningIllustration.tsx+++ /dev/null@@ -1,12 +0,0 @@-import { Box } from "@mui/material";--export const DialogWarningIllustration: React.FC<{- color?: "grey" | "red";-}> = ({ color = "grey" }) => (- <Box- component="img"- src={`/images/warning-${color}.png`}- alt=""- sx={{ width: 68, height: 64, objectFit: "contain", display: "block" }}- />-);diff --git a/web/apps/photos/src/components/utils/dialog-attributes.tsx b/web/apps/photos/src/components/utils/dialog-attributes.tsxindex 8f5f8d0955..9c18ce4acd 100644--- a/web/apps/photos/src/components/utils/dialog-attributes.tsx+++ b/web/apps/photos/src/components/utils/dialog-attributes.tsx@@ -1,7 +1,6 @@import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";import { t } from "i18next";-import { DialogWarningIllustration } from "./DialogWarningIllustration";export const trashFilesDialogAttributes = (count: number,@@ -20,7 +19,7 @@ export const trashFilesDialogAttributes = (count === 1 ? "trash_file_message" : "trash_files_message",),}),- illustration: <DialogWarningIllustration color="red" />,+ kind: "warning",continue: {text: t("move_to_trash"),color: "critical",diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 5450d4ca2a..36193b9560 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -1,7 +1,6 @@import { authPageConfig } from "@/auth-page-config";import { AppLockReauthenticationDialog } from "@/components/app-lock/AppLockReauthenticationDialog";import { AppLockSetupError } from "@/components/app-lock/LockScreenContents";-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";import {updateAvailableForDownloadDialogAttributes,updateReadyToInstallDialogAttributes,@@ -179,11 +178,7 @@ const App: React.FC<PhotosAppProps> = ({ Component, pageProps }) => {<CssBaseline enableColorScheme /><ThemedLoadingBar ref={loadingBarRef} />- <AttributedMiniDialog- {...miniDialogProps}- appearance="centered"- errorIllustration={<DialogWarningIllustration />}- />+ <AttributedMiniDialog {...miniDialogProps} appearance="centered" /><Notification {...notificationProps} />{isDesktop && (diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 4d197f0eff..73a4a0484a 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -1,4 +1,3 @@-import { DialogWarningIllustration } from "@/components/utils/DialogWarningIllustration";// TODO: Audit this file (the code here is mostly fine, but needs revisiting// the file it depends on have been audited and their interfaces fixed)./* eslint-disable react-hooks/exhaustive-deps */@@ -1812,7 +1811,7 @@ const Page: React.FC = () => {case "deletePermanently":showMiniDialog({title: t("delete_files_title"),- illustration: <DialogWarningIllustration color="red" />,+ kind: "warning",message: t("delete_files_message"),continue: {text: t("delete"),diff --git a/web/apps/photos/tests/delete-empty-albums.test.ts b/web/apps/photos/tests/delete-empty-albums.test.tsindex 5f209eaf01..f387a648e9 100644--- a/web/apps/photos/tests/delete-empty-albums.test.ts+++ b/web/apps/photos/tests/delete-empty-albums.test.ts@@ -69,7 +69,7 @@ describe("shared empty album deletion", () => {test("confirms the candidate count and does nothing until confirmed", () => {const dialog = start();expect(mocks.showMiniDialog).toHaveBeenCalledOnce();- expect(dialog.illustration).toBeDefined();+ expect(dialog.kind).toBe("info");expect(dialog.dismissOnRouteChange).toBe(true);expect(dialog.continue?.text).toEqual({key: "delete",diff --git a/web/apps/photos/tests/mini-dialog-artwork.test.tsx b/web/apps/photos/tests/mini-dialog-artwork.test.tsxnew file mode 100644index 0000000000..da58a3fc1c--- /dev/null+++ b/web/apps/photos/tests/mini-dialog-artwork.test.tsx@@ -0,0 +1,87 @@+import { ThemeProvider } from "@mui/material";+import {+ AttributedMiniDialog,+ type MiniDialogAttributes,+} from "ente-base/components/MiniDialog";+import { photosTheme } from "ente-base/components/utils/theme";+import type { PropsWithChildren } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, test, vi } from "vitest";++// Render portal contents on the server so artwork assertions inspect real markup.+vi.mock("@mui/material", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@mui/material")>()),+ Dialog: ({ children }: PropsWithChildren) => <div>{children}</div>,+}));++const renderDialog = (+ attributes: MiniDialogAttributes,+ appearance: "default" | "centered" = "centered",+) =>+ renderToStaticMarkup(+ <ThemeProvider theme={photosTheme}>+ <AttributedMiniDialog+ open+ appearance={appearance}+ onClose={vi.fn()}+ attributes={{ title: "Confirm", cancel: false, ...attributes }}+ />+ </ThemeProvider>,+ );++describe("mini dialog artwork", () => {+ test.each([+ ["info", "grey"],+ ["warning", "red"],+ ["error", "grey"],+ ] as const)("renders %s artwork in centered dialogs", (kind, color) => {+ const html = renderDialog({ kind });+ expect(html).toContain(`src="/images/warning-${color}.png"`);+ expect(html).toContain('alt=""');+ expect(html).toContain("width:68px;height:64px;object-fit:contain");+ });++ test("explicit artwork overrides the kind and icon", () => {+ const html = renderDialog({+ kind: "warning",+ illustration: <span>Custom artwork</span>,+ icon: <span>Fallback icon</span>,+ });+ expect(html).toContain("Custom artwork");+ expect(html).not.toContain("warning-red.png");+ expect(html).not.toContain("Fallback icon");+ });++ test("kind artwork overrides the fallback icon", () => {+ const html = renderDialog({+ kind: "info",+ icon: <span>Fallback icon</span>,+ });+ expect(html).toContain("warning-grey.png");+ expect(html).not.toContain("Fallback icon");+ });++ test("retains consumer icons when no kind or illustration is supplied", () => {+ expect(renderDialog({ icon: <span>Info icon</span> })).toContain(+ "Info icon",+ );+ });++ test("omits artwork when none is supplied", () => {+ const html = renderDialog({});+ expect(html).not.toContain("<img");+ expect(html).toContain("padding-top:64px");+ });++ test.each(["info", "warning", "error"] as const)(+ "default dialogs preserve their icon and do not load %s artwork",+ (kind) => {+ const html = renderDialog(+ { kind, icon: <span>Original icon</span> },+ "default",+ );+ expect(html).toContain("Original icon");+ expect(html).not.toContain("/images/warning-");+ },+ );+});diff --git a/web/apps/photos/tests/mini-dialog.test.ts b/web/apps/photos/tests/mini-dialog.test.tsindex 27960eba1a..de37fb3512 100644--- a/web/apps/photos/tests/mini-dialog.test.ts+++ b/web/apps/photos/tests/mini-dialog.test.ts@@ -96,7 +96,7 @@ describe("trash confirmation attributes", () => {const attributes = trashFilesDialogAttributes(count, vi.fn());expect(attributes.title).toBe(`trash_items_title:${count}`);expect(attributes.message).toBe(`trash_items_message:${count}`);- expect(attributes.illustration).toBeDefined();+ expect(attributes.kind).toBe("warning");expect(attributes.dismissOnRouteChange).toBe(true);expect(attributes.continue?.color).toBe("critical");expect(attributes.continue?.text).toBe("move_to_trash");diff --git a/web/packages/base/components/MiniDialog.tsx b/web/packages/base/components/MiniDialog.tsxindex 9257cbdf38..2f8ffb67b6 100644--- a/web/packages/base/components/MiniDialog.tsx+++ b/web/packages/base/components/MiniDialog.tsx@@ -18,7 +18,7 @@ import log from "../log";import { InlineErrorIndicator } from "./ErrorIndicator";export interface MiniDialogAttributes {- kind?: "error";+ kind?: "info" | "warning" | "error";title?: React.ReactNode;icon?: React.ReactNode;illustration?: React.ReactNode;@@ -43,7 +43,6 @@ export interface MiniDialogAttributes {type MiniDialogProps = Pick<DialogProps, "open" | "sx"> & {appearance?: "default" | "centered";- errorIllustration?: React.ReactNode;// A new request remounts the content to reset pending/error state.dialogID?: number;onClose: () => void;@@ -61,7 +60,6 @@ const MiniDialogContent: React.FC<React.PropsWithChildren<MiniDialogProps>> = ({children,sx,appearance = "default",- errorIllustration,}) => {const titleID = useId();const messageID = useId();@@ -77,7 +75,19 @@ const MiniDialogContent: React.FC<React.PropsWithChildren<MiniDialogProps>> = ({const busy = phase === "loading" || phase === "secondary-loading";const artwork =attributes.illustration ??- (attributes.kind === "error" ? errorIllustration : undefined) ??+ (centered && attributes.kind ? (+ <Box+ component="img"+ src={`/images/warning-${attributes.kind === "warning" ? "red" : "grey"}.png`}+ alt=""+ sx={{+ width: 68,+ height: 64,+ objectFit: "contain",+ display: "block",+ }}+ />+ ) : undefined) ??attributes.icon;const resetPhaseAndClose = () => {