Skip to content

A high-performance Android storage analyzer that bypasses MTP using a native C++ daemon, a Rust TCP bridge, and a React Treemap UI.

Rust

Select files on the current search results page (#229)

Vishnu Srivatsavaac6a6ccfb3c6
diff --git a/docs/search.md b/docs/search.md
index 48dde9a..81becb9 100644
--- a/docs/search.md
+++ b/docs/search.md
@@ -51,8 +51,9 @@ directory itself; file results open the parent.
## Selecting files
Use the checkboxes beside counted files to select them. Press Space to toggle
-a focused checkbox. The selection count includes all pages of the current
-search. Choose **Clear selection** to start over. A different query, folder
+a focused checkbox. **Select this page** and **Deselect this page** apply to
+the files on the visible page. The selection count includes all pages of the
+current search. Choose **Clear selection** to start over. A different query, folder
scope, or scan clears the selection. Deleting a file also clears it by
advancing the current scan revision.
diff --git a/src/SearchFiles.tsx b/src/SearchFiles.tsx
index 1e25133..c383663 100644
--- a/src/SearchFiles.tsx
+++ b/src/SearchFiles.tsx
@@ -3,9 +3,11 @@ import { getSearchResults } from "./scanIpc";
import { FILE_TYPE_LABELS } from "./fileTypeSummary";
import type { FileType } from "./fileTypeSummary";
import type { SearchFolder, SearchResponse } from "./searchResults";
-import type { ScanResponse } from "./scanView";
+import type { ScanNode, ScanResponse } from "./scanView";
import { formatBytes } from "./formatBytes";
+const isSelectableFile = (node: ScanNode) => node.type === "file" && node.counted;
+
export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {
scope: ScanResponse;
folder: SearchFolder | null;
@@ -54,15 +56,19 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {
setPagination({ scope: pageScope, offsets: [0] });
};
const results = data?.results ?? [];
+ const pageFileIds = category ? [] : results.filter(({ node }) => isSelectableFile(node)).map(({ node }) => node.id);
+ const pageSelected = pageFileIds.every(id => selected?.has(id));
const changeScope = () => {
setSelection(null);
setEntireScan(value => !value);
setPagination({ scope: "", offsets: [0] });
};
- const setFileSelected = (id: number, checked: boolean) => {
+ const setFilesSelected = (fileIds: number[], checked: boolean) => {
setSelection(current => {
const ids = new Set(current?.scope === selectionScope ? current.ids : undefined);
- if (checked) ids.add(id); else ids.delete(id);
+ for (const id of fileIds) {
+ if (checked) ids.add(id); else ids.delete(id);
+ }
return { scope: selectionScope, ids };
});
};
@@ -100,6 +106,9 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {
{!category && <span id="search-selection-count" role="status" className={selectedCount ? "text-accent-300" : "sr-only"}>
{selectedCount === 1 ? "1 file selected" : selectedCount > 1 ? `${selectedCount.toLocaleString("en-US")} files selected` : ""}
</span>}
+ {pageFileIds.length > 0 && <button type="button" disabled={busy}
+ onClick={() => setFilesSelected(pageFileIds, !pageSelected)}
+ className="text-accent-400 hover:underline">{pageSelected ? "Deselect this page" : "Select this page"}</button>}
{selectedCount > 0 && <button type="button" disabled={busy} onClick={clearSelection}
className="text-accent-400 hover:underline">Clear selection</button>}
</div>
@@ -117,9 +126,9 @@ export function SearchFiles({ scope, folder, category, busy, onZoom, onNuke }: {
<ol className="divide-y divide-zinc-800/80">
{results.map(({ node, path }) => <li key={node.id} className="search-result-row flex items-center gap-3 py-3">
{!category && <div className="w-4 shrink-0">
- {node.type === "file" && node.counted && <input type="checkbox" disabled={busy}
+ {isSelectableFile(node) && <input type="checkbox" disabled={busy}
aria-label={`Select ${node.name}`} checked={selected?.has(node.id) ?? false}
- onChange={event => setFileSelected(node.id, event.currentTarget.checked)}
+ onChange={event => setFilesSelected([node.id], event.currentTarget.checked)}
className="block size-4 accent-accent-500 cursor-pointer" />}
</div>}
<div className="flex-1 min-w-0">
diff --git a/tests/scan_ui_fixture.js b/tests/scan_ui_fixture.js
index 4239bf9..f28d419 100644
--- a/tests/scan_ui_fixture.js
+++ b/tests/scan_ui_fixture.js
@@ -305,7 +305,7 @@
const report = (passed, error) => {
const output = document.createElement("pre");
output.id = "scan-test-report";
- output.textContent = JSON.stringify({ fixture: "scan-ui", passed, error, ipc_calls: calls.length, wide_paging: widePaging, expanded_tree: expandedTree, checks: passed ? ["offline fonts under CSP", "bounded collapsed discovery diagnostics", "discovery retry recovery", "setup alignment", "result fonts", "file label semantics", "usable file workspace", "keyboard storage map visibility", "collapsible diagnostics", "complete paging", "directory paging focus and retries", "expanded-tree row growth and keyboard focus", "first-scan comparison", "unchanged comparison after rescan", "deletion delta comparison", "cross-device comparison isolation", "bounded package-folder paging and coverage", "package query retries and stale replies", "bounded file-type totals", "file-type retry and malformed response", "file-type generation and deletion revision", "file-type coverage and empty scan", "file-type drilldown paging, keyboard and revision", "bounded largest files", "late largest response", "largest query retry", "malformed largest response recovery", "largest ID-only deletion", "largest read-only guards", "largest folder navigation without rescanning", "bounded search results", "scoped search selection", "late search response", "search retry and malformed response", "search ID-only deletion", "read-only search deletion disabled", "late zoom", "Other tile", "stale confirmation", "exact confirmation whitespace", "reachable long-path confirmation", "native modal keyboard focus and cancellation", "ID-only deletion", "revision refresh", "partial failure", "read-only", "acknowledged shutdown", "unconfirmed shutdown", "reconnect", "stop action ordering", "duplicate rescan guard", "rescan failure recovery", "rescan cancellation recovery", "toast dismissal integration", "bounded diagnostic integration"] : undefined });
+ output.textContent = JSON.stringify({ fixture: "scan-ui", passed, error, ipc_calls: calls.length, wide_paging: widePaging, expanded_tree: expandedTree, checks: passed ? ["offline fonts under CSP", "bounded collapsed discovery diagnostics", "discovery retry recovery", "setup alignment", "result fonts", "file label semantics", "usable file workspace", "keyboard storage map visibility", "collapsible diagnostics", "complete paging", "directory paging focus and retries", "expanded-tree row growth and keyboard focus", "first-scan comparison", "unchanged comparison after rescan", "deletion delta comparison", "cross-device comparison isolation", "bounded package-folder paging and coverage", "package query retries and stale replies", "bounded file-type totals", "file-type retry and malformed response", "file-type generation and deletion revision", "file-type coverage and empty scan", "file-type drilldown paging, keyboard and revision", "bounded largest files", "late largest response", "largest query retry", "malformed largest response recovery", "largest ID-only deletion", "largest read-only guards", "largest folder navigation without rescanning", "bounded search results", "scoped search selection", "search page selection", "late search response", "search retry and malformed response", "search ID-only deletion", "read-only search deletion disabled", "late zoom", "Other tile", "stale confirmation", "exact confirmation whitespace", "reachable long-path confirmation", "native modal keyboard focus and cancellation", "ID-only deletion", "revision refresh", "partial failure", "read-only", "acknowledged shutdown", "unconfirmed shutdown", "reconnect", "stop action ordering", "duplicate rescan guard", "rescan failure recovery", "rescan cancellation recovery", "toast dismissal integration", "bounded diagnostic integration"] : undefined });
document.body.append(output);
void fetch("/report", { method: "POST", body: output.textContent }).then(() => {
if (passed) location.replace("/tests/toast_lifecycle_fixture.html");
@@ -713,6 +713,15 @@
await waitFor(() => rows().length === 129, "Root entries did not settle after folder search");
button("Search").click();
await waitFor(() => document.querySelector("#search-input"), "Search controls missing");
+ searchFor("large-folder");
+ await waitFor(() => searchRows().length === 1, "Folder-only search result missing");
+ check(!searchCheckbox() && !button("Select this page"), "Folder-only results offered file selection");
+ searchFor("l");
+ await waitFor(() => searchRows().length === 100 && searchRows()[0]?.textContent.includes("large-folder"), "Mixed search page missing");
+ button("Select this page").click();
+ await waitFor(() => button("Deselect this page"), "Select this page did not finish updating the mixed page");
+ check(!searchCheckbox() && searchRows().slice(1).every(row => searchCheckbox(row)?.checked)
+ && selectionCount() === "99 files selected", "Page selection included a folder or missed a file");
// The first response is held; an empty superseding query must win and
// the held response must never replace it.
holdSearch = true;
@@ -738,6 +747,18 @@
check(calls.filter(call => call.command === "get_search_results").at(-1).args.skip === 37, "Short-page continuation used a fixed offset");
check(!searchCheckbox().checked && selectionCount() === "1 file selected", "Paging lost or applied selection to the wrong row");
searchCheckbox().click();
+ const selectPage = button("Select this page");
+ selectPage.focus();
+ await pressKey("Enter");
+ await waitFor(() => button("Deselect this page") === selectPage, "Keyboard page selection did not finish updating");
+ check(document.activeElement === selectPage
+ && searchRows().every(row => searchCheckbox(row)?.checked) && selectionCount() === "38 files selected",
+ "Keyboard page selection did not handle the short page or preserve the earlier selection");
+ await pressKey("Enter");
+ await waitFor(() => button("Select this page") === selectPage, "Keyboard page deselection did not finish updating");
+ check(document.activeElement === selectPage && searchRows().every(row => !searchCheckbox(row)?.checked)
+ && selectionCount() === "1 file selected", "Deselecting the page changed the selection on another page");
+ searchCheckbox().click();
check(selectionCount() === "2 files selected", "Selection count did not include both pages");
button("Previous").click();
await waitFor(() => searchRows()[0]?.textContent.includes("nested-0"), "Short-page Previous failed");