Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web] Preserve localized delete copy and guard unowned selections

Aswin Asokb15893ecb21e
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index cbbd0cd132..e7c1349586 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -484,15 +484,18 @@ export const FileList: React.FC<FileListProps> = ({
previousSelectionRef.current !== null;
let selectionCount: number;
let favoriteCount: number;
+ let hasOwnFiles: boolean;
let hasOnlyOwnFiles: boolean;
if (isTemporarySingleSelection) {
selectionCount = 1;
favoriteCount = favoriteFileIDs?.has(contextMenu.file.id) ? 1 : 0;
hasOnlyOwnFiles = contextMenu.file.ownerID === user?.id;
+ hasOwnFiles = hasOnlyOwnFiles;
} else {
selectionCount = selected.count;
favoriteCount = selectedFavoriteCount;
+ hasOwnFiles = selected.ownCount > 0;
hasOnlyOwnFiles =
selectionCount > 0 && selected.ownCount === selectionCount;
}
@@ -500,6 +503,7 @@ export const FileList: React.FC<FileListProps> = ({
barMode: mode,
isInSearchMode: modePlus === "search",
collectionSummary,
+ hasOwnFiles,
hasOnlyOwnFiles,
showAddPerson: !!showAddPersonAction,
showEditLocation: !!showEditLocationAction && hasOnlyOwnFiles,
diff --git a/web/apps/photos/src/components/SelectedFileOptions.tsx b/web/apps/photos/src/components/SelectedFileOptions.tsx
index 0c8aa38b26..633890da92 100644
--- a/web/apps/photos/src/components/SelectedFileOptions.tsx
+++ b/web/apps/photos/src/components/SelectedFileOptions.tsx
@@ -226,6 +226,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
barMode,
isInSearchMode,
collectionSummary,
+ hasOwnFiles: selectedOwnFileCount > 0,
hasOnlyOwnFiles,
showAddPerson: !!onShowAssignPersonDialog,
showEditLocation: !!onEditLocation && hasOnlyOwnFiles,
diff --git a/web/apps/photos/src/utils/file-actions.ts b/web/apps/photos/src/utils/file-actions.ts
index a971b08a8c..0941d84aad 100644
--- a/web/apps/photos/src/utils/file-actions.ts
+++ b/web/apps/photos/src/utils/file-actions.ts
@@ -27,6 +27,7 @@ interface FileActionContext {
barMode?: GalleryBarMode;
isInSearchMode: boolean;
collectionSummary: CollectionSummary | undefined;
+ hasOwnFiles: boolean;
hasOnlyOwnFiles: boolean;
showAddPerson: boolean;
showEditLocation: boolean;
@@ -39,6 +40,7 @@ export function getAvailableFileActions(
barMode,
isInSearchMode,
collectionSummary,
+ hasOwnFiles,
hasOnlyOwnFiles,
showAddPerson,
showEditLocation,
@@ -60,7 +62,9 @@ export function getAvailableFileActions(
insertAddPersonBeforeModifications(actions);
}
- return actions;
+ return hasOwnFiles
+ ? actions
+ : actions.filter((action) => action !== "trash");
}
function getBaseActions(
diff --git a/web/apps/photos/tests/file-actions.test.ts b/web/apps/photos/tests/file-actions.test.ts
index 9deb9e7157..d9b78812e1 100644
--- a/web/apps/photos/tests/file-actions.test.ts
+++ b/web/apps/photos/tests/file-actions.test.ts
@@ -9,6 +9,7 @@ describe("getAvailableFileActions", () => {
barMode: "hidden-albums",
isInSearchMode: false,
collectionSummary: undefined,
+ hasOwnFiles: true,
hasOnlyOwnFiles: true,
showAddPerson: false,
showEditLocation: false,
@@ -29,6 +30,21 @@ describe("getAvailableFileActions", () => {
barMode: "hidden-albums",
isInSearchMode: false,
collectionSummary: undefined,
+ hasOwnFiles: false,
+ hasOnlyOwnFiles: false,
+ showAddPerson: false,
+ showEditLocation: false,
+ }),
+ ).toEqual(["download", "addToAlbum", "unhide"]);
+ });
+
+ test("allows trashing owned files in a mixed hidden-album selection", () => {
+ expect(
+ getAvailableFileActions({
+ barMode: "hidden-albums",
+ isInSearchMode: false,
+ collectionSummary: undefined,
+ hasOwnFiles: true,
hasOnlyOwnFiles: false,
showAddPerson: false,
showEditLocation: false,
@@ -57,6 +73,7 @@ describe("getAvailableFileActions", () => {
getAvailableFileActions({
isInSearchMode: false,
collectionSummary,
+ hasOwnFiles: false,
hasOnlyOwnFiles: false,
showAddPerson: false,
showEditLocation: false,
diff --git a/web/apps/photos/tests/trash-files-dialog.test.ts b/web/apps/photos/tests/trash-files-dialog.test.ts
new file mode 100644
index 0000000000..040f6f9909
--- /dev/null
+++ b/web/apps/photos/tests/trash-files-dialog.test.ts
@@ -0,0 +1,64 @@
+import en from "ente-base/locales/en-US/translation.json";
+import es from "ente-base/locales/es-ES/translation.json";
+import fr from "ente-base/locales/fr-FR/translation.json";
+import { trashFilesDialogAttributes } from "ente-gallery/components/trash-files-dialog";
+import i18n from "i18next";
+import { beforeEach, expect, test } from "vitest";
+
+beforeEach(async () => {
+ await i18n.init({
+ lng: "en-US",
+ fallbackLng: "en-US",
+ resources: {
+ "en-US": { translation: en },
+ "fr-FR": {
+ translation: {
+ trash_files_title: fr.trash_files_title,
+ trash_files_message: fr.trash_files_message,
+ },
+ },
+ "es-ES": {
+ translation: {
+ trash_files_title: es.trash_files_title,
+ trash_files_message: es.trash_files_message,
+ },
+ },
+ },
+ });
+});
+
+test("keeps singular and plural English confirmations", () => {
+ expect(trashFilesDialogAttributes(1)).toMatchObject({
+ title: "Delete 1 item?",
+ message: en.trash_items_message_one,
+ });
+ expect(trashFilesDialogAttributes(2)).toMatchObject({
+ title: "Delete 2 items?",
+ message: en.trash_items_message_other,
+ });
+});
+
+test.each([
+ ["fr-FR", fr],
+ ["es-ES", es],
+] as const)("retains existing translations in %s", async (locale, strings) => {
+ await i18n.changeLanguage(locale);
+ for (const count of [1, 2]) {
+ expect(trashFilesDialogAttributes(count)).toMatchObject({
+ title: strings.trash_files_title,
+ message: strings.trash_files_message,
+ });
+ }
+});
+
+test("uses new translated copy independently for each key", async () => {
+ i18n.addResourceBundle("fr-FR", "translation", {
+ trash_items_title_one: "Supprimer {{count}} fichier ?",
+ trash_items_title_other: "Supprimer {{count}} fichiers ?",
+ });
+ await i18n.changeLanguage("fr-FR");
+ expect(trashFilesDialogAttributes(2)).toMatchObject({
+ title: "Supprimer 2 fichiers ?",
+ message: fr.trash_files_message,
+ });
+});
diff --git a/web/apps/photos/vitest.config.ts b/web/apps/photos/vitest.config.ts
new file mode 100644
index 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/gallery/components/trash-files-dialog.tsx b/web/packages/gallery/components/trash-files-dialog.tsx
index 7b2d870185..9e05048653 100644
--- a/web/packages/gallery/components/trash-files-dialog.tsx
+++ b/web/packages/gallery/components/trash-files-dialog.tsx
@@ -8,8 +8,16 @@ import warningRed from "./assets/warning-red.png";
export const trashFilesDialogAttributes = (
count: number,
): Pick<MiniDialogAttributes, "title" | "message" | "illustration"> => ({
- title: t("trash_items_title", { count }),
- message: t("trash_items_message", { count }),
+ title: t("trash_items_title", {
+ count,
+ fallbackLng: false,
+ defaultValue: t("trash_files_title"),
+ }),
+ message: t("trash_items_message", {
+ count,
+ fallbackLng: false,
+ defaultValue: t("trash_files_message"),
+ }),
illustration: (
<Box
component="img"