From ee66f1b3d9a28cc5d1fa6f246ad5e4f66baff3de Mon Sep 17 00:00:00 2001 From: Sucukdeluxe Date: Tue, 25 Aug 2026 05:29:54 +0200 Subject: [PATCH] feat(downloads): inherit package selection visually --- .../views/downloads/VirtualizedDownloadsBody.tsx | 15 ++++++++++++--- tests/downloads-view.test.tsx | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/renderer/views/downloads/VirtualizedDownloadsBody.tsx b/src/renderer/views/downloads/VirtualizedDownloadsBody.tsx index 22a214e..efde5e0 100644 --- a/src/renderer/views/downloads/VirtualizedDownloadsBody.tsx +++ b/src/renderer/views/downloads/VirtualizedDownloadsBody.tsx @@ -1,5 +1,6 @@ import { useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactElement } from "react"; -import { buildDownloadLogicalRows, type DownloadLogicalRow } from "./downloads-model"; +import type { DownloadItem } from "../../../shared/types"; +import { buildDownloadLogicalRows, type DownloadDisplayMode, type DownloadLogicalRow } from "./downloads-model"; import { activateDownloadDisclosureTransition, DOWNLOAD_DISCLOSURE_DURATION_MS, @@ -78,19 +79,27 @@ function disclosureOpacity(row: DownloadLogicalRow | DownloadDisclosureRow): num return "disclosureOpacity" in row && typeof row.disclosureOpacity === "number" ? row.disclosureOpacity : 1; } +export function isDownloadItemVisuallySelected( + item: Pick, + selectedIds: ReadonlySet, + displayMode: DownloadDisplayMode +): boolean { + return selectedIds.has(item.id) || (displayMode === "packages" && selectedIds.has(item.packageId)); +} + function renderVirtualRow(row: DownloadLogicalRow | DownloadDisclosureRow, model: DownloadsViewModel, actions: DownloadsViewActions): ReactElement { if (row.type === "item-group") { return (
{row.items.map((entry) => ( - + ))}
); } if (row.type === "item") { return ( - + ); } return ( diff --git a/tests/downloads-view.test.tsx b/tests/downloads-view.test.tsx index 48274d0..081847d 100644 --- a/tests/downloads-view.test.tsx +++ b/tests/downloads-view.test.tsx @@ -63,6 +63,7 @@ import { DOWNLOAD_PACKAGE_ROW_HEIGHT, calculateDownloadVirtualWindow } from "../src/renderer/views/downloads/download-virtualizer"; +import { isDownloadItemVisuallySelected } from "../src/renderer/views/downloads/VirtualizedDownloadsBody"; import { compactDownloadServiceLabel, extractHoster, @@ -947,6 +948,15 @@ describe("downloads model", () => { expect(model.actionableSelectedIds).toEqual(["package-a"]); }); + it("visually inherits package selection without adding child ids to the action selection", () => { + const selectedIds = new Set(["package-a"]); + const child = item("active", "package-a", "downloading"); + + expect(isDownloadItemVisuallySelected(child, selectedIds, "packages")).toBe(true); + expect(isDownloadItemVisuallySelected(child, selectedIds, "files")).toBe(false); + expect([...selectedIds]).toEqual(["package-a"]); + }); + it("keeps occupied package rows logical while preserving active packages and an actionable visible selection", () => { const packageEntries = Array.from({ length: 264 }, (_, index) => pkg(`p-${index}`, `Paket ${index}`, [`i-${index}`])); const itemEntries = packageEntries.map((entry, index) => item(`i-${index}`, entry.id, index === 263 ? "downloading" : "queued"));