Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(gallery):move-files-between-hidden-albums

Aswin Asokcdb52dd26d1d
diff --git a/desktop/changes/move-between-hidden-albums.md b/desktop/changes/move-between-hidden-albums.md
new file mode 100644
index 0000000000..6d42328bd1
--- /dev/null
+++ b/desktop/changes/move-between-hidden-albums.md
@@ -0,0 +1 @@
+- Added support for moving photos between hidden albums.
diff --git a/web/apps/photos/src/components/CollectionSelector.tsx b/web/apps/photos/src/components/CollectionSelector.tsx
index c148459dbb..3a4be77a9f 100644
--- a/web/apps/photos/src/components/CollectionSelector.tsx
+++ b/web/apps/photos/src/components/CollectionSelector.tsx
@@ -111,6 +111,14 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = (
return false;
}
+ if (
+ attributes.action === "move" &&
+ attributes.showHiddenCollections &&
+ collectionSummary.type === "hiddenItems"
+ ) {
+ return true;
+ }
+
const isUserFavorites =
collectionSummary.type === "userFavorites";
if (
diff --git a/web/apps/photos/src/components/SelectedFileOptions.tsx b/web/apps/photos/src/components/SelectedFileOptions.tsx
index 27ca534106..87faa5663b 100644
--- a/web/apps/photos/src/components/SelectedFileOptions.tsx
+++ b/web/apps/photos/src/components/SelectedFileOptions.tsx
@@ -206,6 +206,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
onOpenCollectionSelector({
action: "move",
sourceCollectionSummaryID: collectionSummary?.id,
+ showHiddenCollections: barMode == "hidden-albums",
onCreateCollection: createOnCreateForCollectionOp("move"),
onSelectCollection: createOnSelectForCollectionOp("move"),
});
diff --git a/web/apps/photos/src/components/gallery/helpers.ts b/web/apps/photos/src/components/gallery/helpers.ts
index dad4b112c6..7a1f41c4c1 100644
--- a/web/apps/photos/src/components/gallery/helpers.ts
+++ b/web/apps/photos/src/components/gallery/helpers.ts
@@ -9,6 +9,7 @@ import type { EnteFile } from "ente-media/file";
import {
addOrCopyToCollection,
createUncategorizedCollection,
+ getOrCreateDefaultHiddenCollection,
moveFromCollection,
moveToCollection,
restoreToCollection,
@@ -26,14 +27,16 @@ export const validateKey = async () => {
}
};
-export const findCollectionCreatingUncategorizedIfNeeded = async (
+export const findCollectionCreatingIfNeeded = async (
collections: Collection[],
collectionSummaryID: number,
): Promise<Collection> =>
collectionSummaryID == PseudoCollectionID.uncategorizedPlaceholder
? createUncategorizedCollection()
- : // The selector only exposes summaries backed by collections.
- collections.find(({ id }) => id == collectionSummaryID)!;
+ : collectionSummaryID == PseudoCollectionID.hiddenItems
+ ? getOrCreateDefaultHiddenCollection()
+ : // The selector only exposes summaries backed by collections.
+ collections.find(({ id }) => id == collectionSummaryID)!;
// Adds may copy non-owned files or reuse an owned file with the same hash.
// Moves remain owner-only; shared contributor flows are adds.
@@ -48,11 +51,15 @@ export const performCollectionOp = async (
await addOrCopyToCollection(selectedCollection, selectedFiles);
break;
case "move":
- await moveFromCollection(
- sourceCollectionID!,
- selectedCollection,
- selectedFiles,
- );
+ if (sourceCollectionID == PseudoCollectionID.hiddenItems) {
+ await moveToCollection(selectedCollection, selectedFiles);
+ } else {
+ await moveFromCollection(
+ sourceCollectionID!,
+ selectedCollection,
+ selectedFiles,
+ );
+ }
break;
case "restore":
await restoreToCollection(selectedCollection, selectedFiles);
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index bfc8133935..02021156da 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -37,7 +37,7 @@ import {
type RemotePullOpts,
} from "@/components/gallery";
import {
- findCollectionCreatingUncategorizedIfNeeded,
+ findCollectionCreatingIfNeeded,
performCollectionOp,
validateKey,
} from "@/components/gallery/helpers";
@@ -386,6 +386,10 @@ const Page: React.FC = () => {
} = state;
const barMode = state.view?.type ?? "albums";
+ const quickLinkVisibility =
+ barMode == "hidden-albums"
+ ? ItemVisibility.hidden
+ : ItemVisibility.visible;
const activeCollectionID =
state.view?.type == "people"
? undefined
@@ -987,7 +991,7 @@ const Page: React.FC = () => {
(op: CollectionOp) => {
setPostCreateAlbumOp(op);
postCreateAlbumHidden.current =
- op == "add" && barMode == "hidden-albums";
+ (op == "add" || op == "move") && barMode == "hidden-albums";
return showAlbumNameInput;
},
[showAlbumNameInput, barMode],
@@ -1120,6 +1124,7 @@ const Page: React.FC = () => {
const quickLinkCollection =
await createQuickLinkCollection(
quickLinkNameForFiles(ownedSelectedFiles),
+ quickLinkVisibility,
);
await addToCollection(
quickLinkCollection,
@@ -1431,6 +1436,7 @@ const Page: React.FC = () => {
try {
const quickLinkCollection = await createQuickLinkCollection(
quickLinkNameForFiles([file]),
+ quickLinkVisibility,
);
await addToCollection(quickLinkCollection, [file]);
const publicURL = await createPublicURL(
@@ -1455,6 +1461,7 @@ const Page: React.FC = () => {
showLoadingBar,
hideLoadingBar,
customDomain,
+ quickLinkVisibility,
remotePull,
onGenericError,
],
@@ -1620,6 +1627,7 @@ const Page: React.FC = () => {
handleOpenCollectionSelector({
action: "move",
sourceCollectionSummaryID: activeCollectionSummary?.id,
+ showHiddenCollections: barMode == "hidden-albums",
onCreateCollection:
createOnCreateForCollectionOp("move"),
onSelectCollection:
@@ -1829,10 +1837,7 @@ const Page: React.FC = () => {
: normalCollectionSummaries
}
collectionForCollectionSummaryID={(id) =>
- findCollectionCreatingUncategorizedIfNeeded(
- state.collections,
- id,
- )
+ findCollectionCreatingIfNeeded(state.collections, id)
}
/>
<DownloadStatusNotifications
diff --git a/web/apps/photos/src/utils/file-actions.ts b/web/apps/photos/src/utils/file-actions.ts
index 74b4d552b8..ca0efc9747 100644
--- a/web/apps/photos/src/utils/file-actions.ts
+++ b/web/apps/photos/src/utils/file-actions.ts
@@ -127,7 +127,7 @@ function getBaseActions(
}
if (barMode === "hidden-albums") {
- return ["download", "addToAlbum", "unhide", "trash"];
+ return ["download", "addToAlbum", "moveToAlbum", "unhide", "trash"];
}
const isUserFavorites =
diff --git a/web/apps/photos/tests/file-actions.test.ts b/web/apps/photos/tests/file-actions.test.ts
index c334eba472..46178dd4a1 100644
--- a/web/apps/photos/tests/file-actions.test.ts
+++ b/web/apps/photos/tests/file-actions.test.ts
@@ -3,6 +3,26 @@ import { describe, expect, test } from "vitest";
import { getAvailableFileActions } from "../src/utils/file-actions";
describe("getAvailableFileActions", () => {
+ test("allows moving files between hidden albums", () => {
+ expect(
+ getAvailableFileActions({
+ barMode: "hidden-albums",
+ isInSearchMode: false,
+ collectionSummary: undefined,
+ hasOnlyOwnFiles: true,
+ showAddPerson: false,
+ showEditLocation: false,
+ }),
+ ).toEqual([
+ "sendLink",
+ "download",
+ "addToAlbum",
+ "moveToAlbum",
+ "unhide",
+ "trash",
+ ]);
+ });
+
test("uses shared actions for an incoming uncategorized collection", () => {
const collectionSummary: CollectionSummary = {
id: 1,
diff --git a/web/apps/photos/tests/gallery-helpers.test.ts b/web/apps/photos/tests/gallery-helpers.test.ts
new file mode 100644
index 0000000000..3fe94233ad
--- /dev/null
+++ b/web/apps/photos/tests/gallery-helpers.test.ts
@@ -0,0 +1,74 @@
+import type { Collection } from "ente-media/collection";
+import type { EnteFile } from "ente-media/file";
+import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
+import { beforeEach, describe, expect, test, vi } from "vitest";
+import {
+ findCollectionCreatingIfNeeded,
+ performCollectionOp,
+} from "../src/components/gallery/helpers";
+
+const collectionService = vi.hoisted(() => ({
+ addOrCopyToCollection: vi.fn(),
+ createUncategorizedCollection: vi.fn(),
+ getOrCreateDefaultHiddenCollection: vi.fn(),
+ moveFromCollection: vi.fn(),
+ moveToCollection: vi.fn(),
+ restoreToCollection: vi.fn(),
+}));
+
+vi.mock("ente-accounts/services/recovery-key", () => ({
+ getUserRecoveryKey: vi.fn(),
+}));
+vi.mock("ente-base/log", () => ({ default: { warn: vi.fn() } }));
+vi.mock("ente-new/photos/services/collection", () => collectionService);
+
+describe("performCollectionOp", () => {
+ beforeEach(() => vi.clearAllMocks());
+
+ test("moves hidden items using their real source collections", async () => {
+ const destination = { id: 2 } as Collection;
+ const files = [{ id: 1, collectionID: 1 }] as EnteFile[];
+
+ await performCollectionOp(
+ "move",
+ destination,
+ files,
+ PseudoCollectionID.hiddenItems,
+ );
+
+ expect(collectionService.moveToCollection).toHaveBeenCalledWith(
+ destination,
+ files,
+ );
+ expect(collectionService.moveFromCollection).not.toHaveBeenCalled();
+ });
+
+ test("moves album files from the active source collection", async () => {
+ const destination = { id: 2 } as Collection;
+ const files = [{ id: 1, collectionID: 1 }] as EnteFile[];
+
+ await performCollectionOp("move", destination, files, 1);
+
+ expect(collectionService.moveFromCollection).toHaveBeenCalledWith(
+ 1,
+ destination,
+ files,
+ );
+ expect(collectionService.moveToCollection).not.toHaveBeenCalled();
+ });
+});
+
+describe("findCollectionCreatingIfNeeded", () => {
+ beforeEach(() => vi.clearAllMocks());
+
+ test("resolves Hidden Items to the real default-hidden collection", async () => {
+ const defaultHiddenCollection = { id: 1 } as Collection;
+ collectionService.getOrCreateDefaultHiddenCollection.mockResolvedValue(
+ defaultHiddenCollection,
+ );
+
+ await expect(
+ findCollectionCreatingIfNeeded([], PseudoCollectionID.hiddenItems),
+ ).resolves.toBe(defaultHiddenCollection);
+ });
+});
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index e860b0455d..99cd8ab827 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -63,10 +63,13 @@ const copyRequestBatchSize = 100;
export const createAlbum = (albumName: string) =>
createCollection(albumName, "album");
-export const createQuickLinkCollection = (name: string) =>
+export const createQuickLinkCollection = (
+ name: string,
+ visibility: ItemVisibility,
+) =>
createCollection(name, "album", {
subType: CollectionSubType.quicklink,
- visibility: ItemVisibility.visible,
+ visibility,
});
export const createHiddenAlbum = (albumName: string) =>
@@ -1208,7 +1211,7 @@ const resolveFavoritesFilesForRemoval = async (
});
};
-const savedOrCreateDefaultHiddenCollection = async () =>
+export const getOrCreateDefaultHiddenCollection = async () =>
(await savedDefaultHiddenCollection()) ?? createDefaultHiddenCollection();
const savedDefaultHiddenCollection = async () =>
@@ -1269,8 +1272,7 @@ export const canRemoveFilesFromAllParticipants = (collection: Collection) => {
export const hideFiles = async (files: EnteFile[]) => {
const userID = ensureLocalUser().id;
- const defaultHiddenCollection =
- await savedOrCreateDefaultHiddenCollection();
+ const defaultHiddenCollection = await getOrCreateDefaultHiddenCollection();
const collections = await savedCollections();
const collectionsByID = new Map(collections.map((c) => [c.id, c]));