Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(intermediates): preserve selection across pages and refreshes
Josh Corbettbc877368e81d
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 6502d4f7bb..7c577f3d89 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -4300,6 +4300,9 @@"measuringNote": "Sizes are still being measured; figures grow as measurement finishes."},"selection": {+ "checking": "Checking selection…",+ "estimateFailed": "Could not estimate selection. Refresh to retry.",+ "tooManyRows": "More than {{count}} matching projects. Narrow your search to review this selection.","estimate": "{{count, number}} selected · {{images}}, {{videos}}, about {{size}}","available": "{{images}}, {{videos}} unused · about {{size}} reclaimable"}diff --git a/invokeai/frontend/webv2/src/features/intermediates/core/selection.test.ts b/invokeai/frontend/webv2/src/features/intermediates/core/selection.test.tsindex 09d5bf1c3a..6b376b4335 100644--- a/invokeai/frontend/webv2/src/features/intermediates/core/selection.test.ts+++ b/invokeai/frontend/webv2/src/features/intermediates/core/selection.test.ts@@ -4,7 +4,6 @@ import type { IntermediatesRow } from './types';import {EMPTY_SELECTION,- getPageSelectionState,isRowSelected,resolveScope,selectAllMatching,@@ -32,22 +31,18 @@ const page = [row('a'), row('b'), row(null)];const totals = { reclaimableBytes: 5_000, rows: 12, safeImages: 40, safeVideos: 4, unknownSizeCount: 2 };describe('row selection', () => {- it('toggles rows and reports the page state', () => {- let selection = toggleRowSelection(EMPTY_SELECTION, page[0]!, page);+ it('toggles rows', () => {+ let selection = toggleRowSelection(EMPTY_SELECTION, page[0]!);expect(isRowSelected(selection, page[0]!)).toBe(true);- expect(getPageSelectionState(selection, page)).toBe('some');for (const candidate of page.slice(1)) {- selection = toggleRowSelection(selection, candidate, page);+ selection = toggleRowSelection(selection, candidate);}expect(page.every((candidate) => isRowSelected(selection, candidate))).toBe(true);- expect(getPageSelectionState(selection, page)).toBe('all');- expect(getPageSelectionState(selectAllMatching(), page)).toBe('all');- expect(getPageSelectionState(EMPTY_SELECTION, page)).toBe('none');});it('keeps the unassigned row distinct from a project row of the same owner', () => {- const selection = toggleRowSelection(EMPTY_SELECTION, page[2]!, page);+ const selection = toggleRowSelection(EMPTY_SELECTION, page[2]!);expect(isRowSelected(selection, page[2]!)).toBe(true);expect(isRowSelected(selection, page[0]!)).toBe(false);@@ -56,10 +51,10 @@ describe('row selection', () => {it('keeps picks from an earlier page when the page changes', () => {const firstPage = [row('a'), row('b')];const secondPage = [row('c'), row('d')];- let selection = toggleRowSelection(EMPTY_SELECTION, firstPage[0]!, firstPage);- selection = toggleRowSelection(selection, secondPage[1]!, secondPage);+ let selection = toggleRowSelection(EMPTY_SELECTION, firstPage[0]!);+ selection = toggleRowSelection(selection, secondPage[1]!);- expect(summarizeSelection(selection, totals).rows).toBe(2);+ expect(summarizeSelection(selection, totals)?.rows).toBe(2);expect(resolveScope({ hasSubsetFilter: false, loadedRows: secondPage, ownerId: 'alice', selection })).toEqual({kind: 'selection',targets: [@@ -67,19 +62,37 @@ describe('row selection', () => {{ projectId: 'd', userId: 'alice' },],});- expect(getPageSelectionState(selection, firstPage)).toBe('some');});it('adds a row without disturbing an existing pick or an all-matching selection', () => {const picked = withRowSelected(withRowSelected(EMPTY_SELECTION, page[0]!), page[0]!);- expect(summarizeSelection(picked, totals).rows).toBe(1);+ expect(summarizeSelection(picked, totals)?.rows).toBe(1);expect(withRowSelected(selectAllMatching(), page[1]!)).toEqual(selectAllMatching());});- it('leaving all-matching by toggling a row keeps the rest of the visible page', () => {- const selection = toggleRowSelection(selectAllMatching(), page[1]!, page);-- expect(selection.mode).toBe('rows');+ it('excludes a row without losing matching rows on other pages', () => {+ const selection = toggleRowSelection(selectAllMatching(), page[1]!);++ expect(selection.mode).toBe('all-matching');+ expect(isRowSelected(selection, row('off-page'))).toBe(true);+ expect(summarizeSelection(selection, totals)).toBeNull();+ expect(summarizeSelection(selection, totals, [...page, row('off-page')])).toMatchObject({+ rows: 3,+ safeImages: 9,+ safeVideos: 6,+ reclaimableBytes: 300,+ });+ expect(toggleRowSelection(selection, page[1]!)).toEqual(selectAllMatching());+ expect(+ resolveScope({ hasSubsetFilter: false, loadedRows: [...page, row('off-page')], ownerId: 'alice', selection })+ ).toEqual({+ kind: 'selection',+ targets: [+ { userId: 'alice', projectId: 'a' },+ { userId: 'alice', projectId: null },+ { userId: 'alice', projectId: 'off-page' },+ ],+ });expect(isRowSelected(selection, page[0]!)).toBe(true);expect(isRowSelected(selection, page[1]!)).toBe(false);expect(isRowSelected(selection, page[2]!)).toBe(true);@@ -88,7 +101,7 @@ describe('row selection', () => {describe('selection summary', () => {it('sums explicit picks from their snapshots', () => {- const selection = toggleRowSelection(toggleRowSelection(EMPTY_SELECTION, page[0]!, page), page[2]!, page);+ const selection = toggleRowSelection(toggleRowSelection(EMPTY_SELECTION, page[0]!), page[2]!);expect(summarizeSelection(selection, totals)).toEqual({referencedBytes: 20,@@ -126,7 +139,7 @@ describe('scope resolution', () => {});it('turns picks, and all-matching under a search, into explicit targets', () => {- const picks = toggleRowSelection(EMPTY_SELECTION, page[2]!, page);+ const picks = toggleRowSelection(EMPTY_SELECTION, page[2]!);expect(resolveScope({ hasSubsetFilter: false, loadedRows: page, ownerId: 'alice', selection: picks })).toEqual({kind: 'selection',diff --git a/invokeai/frontend/webv2/src/features/intermediates/core/selection.ts b/invokeai/frontend/webv2/src/features/intermediates/core/selection.tsindex fdb4375e4d..7f8841bbc1 100644--- a/invokeai/frontend/webv2/src/features/intermediates/core/selection.ts+++ b/invokeai/frontend/webv2/src/features/intermediates/core/selection.ts@@ -5,78 +5,48 @@ import { getIntermediatesRowKey } from './types';/*** Row selection for the manager. `rows` keeps a snapshot of every picked row, so picks survive paging and can be* summarized and targeted without the page that showed them; `all-matching` stands for every row the current- * filters match, including rows never loaded, and resolves against the server when a preview is requested.+ * filters match, including rows never loaded, minus explicit exclusions. It resolves against the server when a+ * preview is requested.*/export type IntermediatesSelection =| { mode: 'rows'; rows: ReadonlyMap<string, IntermediatesRow> }- | { mode: 'all-matching' };+ | { mode: 'all-matching'; excluded: ReadonlySet<string> };export const EMPTY_SELECTION: IntermediatesSelection = { mode: 'rows', rows: new Map() };export const isRowSelected = (selection: IntermediatesSelection, row: IntermediatesRow): boolean =>- selection.mode === 'all-matching' || selection.rows.has(getIntermediatesRowKey(row));--export const isSelectionEmpty = (selection: IntermediatesSelection): boolean =>- selection.mode === 'rows' && selection.rows.size === 0;--const materialize = (- selection: IntermediatesSelection,- visibleRows: readonly IntermediatesRow[]-): Map<string, IntermediatesRow> =>- new Map(- selection.mode === 'all-matching'- ? visibleRows.map((row) => [getIntermediatesRowKey(row), row] as const)- : selection.rows- );+ selection.mode === 'all-matching'+ ? !selection.excluded.has(getIntermediatesRowKey(row))+ : selection.rows.has(getIntermediatesRowKey(row));export const withRowSelected = (selection: IntermediatesSelection, row: IntermediatesRow): IntermediatesSelection => {- if (selection.mode === 'all-matching' || selection.rows.has(getIntermediatesRowKey(row))) {- return selection;- }- const rows = new Map(selection.rows);-- rows.set(getIntermediatesRowKey(row), row);-- return { mode: 'rows', rows };+ return isRowSelected(selection, row) ? selection : toggleRowSelection(selection, row);};export const toggleRowSelection = (selection: IntermediatesSelection,- row: IntermediatesRow,- visibleRows: readonly IntermediatesRow[]+ row: IntermediatesRow): IntermediatesSelection => {const key = getIntermediatesRowKey(row);- // Leaving "all matching" materializes the visible page minus the toggled row; rows beyond the page cannot be kept.- const rows = materialize(selection, visibleRows);-+ if (selection.mode === 'all-matching') {+ const excluded = new Set(selection.excluded);+ if (excluded.has(key)) {+ excluded.delete(key);+ } else {+ excluded.add(key);+ }+ return { mode: 'all-matching', excluded };+ }+ const rows = new Map(selection.rows);if (rows.has(key)) {rows.delete(key);} else {rows.set(key, row);}-return { mode: 'rows', rows };};-export const selectAllMatching = (): IntermediatesSelection => ({ mode: 'all-matching' });--export type PageSelectionState = 'none' | 'some' | 'all';--export const getPageSelectionState = (- selection: IntermediatesSelection,- visibleRows: readonly IntermediatesRow[]-): PageSelectionState => {- if (visibleRows.length === 0) {- return 'none';- }- if (selection.mode === 'all-matching') {- return 'all';- }-- const selected = visibleRows.filter((row) => selection.rows.has(getIntermediatesRowKey(row))).length;-- return selected === 0 ? 'none' : selected === visibleRows.length ? 'all' : 'some';-};+export const selectAllMatching = (): IntermediatesSelection => ({ mode: 'all-matching', excluded: new Set() });export interface SelectionSummary {rows: number;@@ -91,13 +61,30 @@ export interface SelectionSummary {/*** Sums the selection. Explicit picks are summed from their snapshots, whichever page showed them; "all matching"- * uses the server's totals, which cover every matching row.+ * uses the server's totals. With exclusions, a complete current matching snapshot is required: old excluded-row+ * snapshots cannot tell us whether those rows still exist or how their counts changed.*/export const summarizeSelection = (selection: IntermediatesSelection,- totals: { rows: number; safeImages: number; safeVideos: number; reclaimableBytes: number; unknownSizeCount: number }-): SelectionSummary => {+ totals: { rows: number; safeImages: number; safeVideos: number; reclaimableBytes: number; unknownSizeCount: number },+ matchingRows?: readonly IntermediatesRow[]+): SelectionSummary | null => {if (selection.mode === 'all-matching') {+ if (selection.excluded.size > 0) {+ return matchingRows+ ? summarizeSelection(+ {+ mode: 'rows',+ rows: new Map(+ matchingRows+ .filter((row) => isRowSelected(selection, row))+ .map((row) => [getIntermediatesRowKey(row), row])+ ),+ },+ totals+ )+ : null;+ }return {referencedBytes: 0,referencedImages: 0,@@ -139,7 +126,11 @@ export const selectionToTargets = (selection: IntermediatesSelection,loadedRows: readonly IntermediatesRow[]): IntermediatesScopeTarget[] =>- [...(selection.mode === 'all-matching' ? loadedRows : selection.rows.values())].map(({ projectId, userId }) => ({+ [+ ...(selection.mode === 'all-matching'+ ? loadedRows.filter((row) => isRowSelected(selection, row))+ : selection.rows.values()),+ ].map(({ projectId, userId }) => ({projectId,userId,}));@@ -156,7 +147,7 @@ export const resolveScope = (options: {}): IntermediatesScope => {const { hasSubsetFilter, loadedRows, ownerId, selection } = options;- if (selection.mode === 'all-matching' && !hasSubsetFilter) {+ if (selection.mode === 'all-matching' && selection.excluded.size === 0 && !hasSubsetFilter) {return ownerId === null ? { kind: 'everyone' } : { kind: 'owner', userId: ownerId };}diff --git a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsx b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsxindex ae20c0b5c6..a4abd9509f 100644--- a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsx@@ -574,4 +574,132 @@ describe('IntermediatesManager', () => {));});+ it('keeps all 119 other projects selected across pages and safe/force previews', async () => {+ const manyRows = Array.from({ length: 120 }, (_, index) => row(`p${index}`, `Project ${index}`, 1));+ const totals = summaryOf(manyRows).totals;+ dependencies.getIntermediatesSummary+ .mockReset()+ .mockImplementation((params: { offset?: number; limit?: number }) => {+ const offset = params.offset ?? 0;+ return Promise.resolve({+ ...summaryOf(manyRows.slice(offset, offset + (params.limit ?? 50))),+ offset,+ total: 120,+ totals,+ });+ });+ await renderManager();+ await vi.waitFor(() => expect(host.textContent).toContain('Project 0'));+ await act(() => checkbox('intermediates.list.selectAll').click());+ await act(() => checkbox('intermediates.list.selectRow(name=Project 1)').click());+ await vi.waitFor(() => expect(host.textContent).toContain('count=119'));+ await act(() => buttonWithText('common.nextPage', host).click());+ await vi.waitFor(() => expect(host.textContent).toContain('Project 55'));+ expect(checkbox('intermediates.list.selectRow(name=Project 55)').checked).toBe(true);+ expect(checkbox('intermediates.list.selectAll').checked).toBe(false);+ await act(() => buttonWithText('common.nextPage', host).click());+ await vi.waitFor(() => expect(host.textContent).toContain('Project 119'));+ expect(checkbox('intermediates.list.selectRow(name=Project 119)').checked).toBe(true);+ await act(() => buttonWithText('intermediates.list.delete', host).click());+ const targets = manyRows+ .filter(({ projectId }) => projectId !== 'p1')+ .map(({ projectId, userId }) => ({ projectId, userId }));+ await vi.waitFor(() =>+ expect(dependencies.createIntermediatesPreview).toHaveBeenLastCalledWith(+ { mode: 'safe', scope: { kind: 'selection', targets } },+ expect.anything()+ )+ );+ await act(() => document.querySelector<HTMLLabelElement>('[role="alertdialog"] label')!.click());+ await vi.waitFor(() =>+ expect(dependencies.createIntermediatesPreview).toHaveBeenLastCalledWith(+ { mode: 'force', scope: { kind: 'selection', targets } },+ expect.anything()+ )+ );+ });++ it('reconciles excluded rows after refresh across pages without forgetting their identities', async () => {+ let currentRows = Array.from({ length: 120 }, (_, index) => row(`p${index}`, `Project ${index}`, 1));+ dependencies.getIntermediatesSummary+ .mockReset()+ .mockImplementation((params: { offset?: number; limit?: number }) => {+ const offset = params.offset ?? 0;+ return Promise.resolve({+ ...summaryOf(currentRows),+ items: currentRows.slice(offset, offset + (params.limit ?? 50)),+ offset,+ });+ });+ await renderManager();+ await vi.waitFor(() => expect(host.textContent).toContain('Project 0'));+ await act(() => checkbox('intermediates.list.selectAll').click());+ await act(() => checkbox('intermediates.list.selectRow(name=Project 1)').click());+ await vi.waitFor(() => expect(host.textContent).toContain('count=119'));+ const snapshots = () =>+ dependencies.getIntermediatesSummary.mock.calls.filter(([params]) => params.limit === 1000).length;+ const initialSnapshots = snapshots();+ await act(() => buttonWithText('common.nextPage', host).click());+ await vi.waitFor(() => expect(host.textContent).toContain('Project 55'));+ expect(snapshots()).toBe(initialSnapshots);++ currentRows = [row('p55', 'Project 55', 1)];+ await act(() => host.querySelector<HTMLButtonElement>('[aria-label="intermediates.refresh"]')!.click());+ await vi.waitFor(() => expect(host.textContent).toContain('intermediates.selection.estimate(count=1,'));+ expect(checkbox('intermediates.list.selectRow(name=Project 55)').checked).toBe(true);+ expect(buttonWithText('intermediates.list.delete', host).disabled).toBe(false);++ currentRows = [row('p1', 'Project 1', 1), row('p55', 'Project 55', 1)];+ await act(() => host.querySelector<HTMLButtonElement>('[aria-label="intermediates.refresh"]')!.click());+ await vi.waitFor(() => expect(host.textContent).toContain('Project 1'));+ expect(checkbox('intermediates.list.selectRow(name=Project 1)').checked).toBe(false);+ await vi.waitFor(() =>+ expect(host.textContent).toContain(+ 'intermediates.selection.estimate(count=1,images=intermediates.counts.images(count=1)'+ )+ );++ // Same global totals, but all reclaimable bytes have moved to the still-selected row.+ currentRows = [row('p1', 'Project 1', 0), row('p55', 'Project 55', 2)];+ await act(() => host.querySelector<HTMLButtonElement>('[aria-label="intermediates.refresh"]')!.click());+ await vi.waitFor(() =>+ expect(host.textContent).toContain(+ 'intermediates.selection.estimate(count=1,images=intermediates.counts.images(count=2)'+ )+ );+ expect(checkbox('intermediates.list.selectRow(name=Project 1)').checked).toBe(false);+ await act(() => buttonWithText('intermediates.list.delete', host).click());+ await vi.waitFor(() =>+ expect(dependencies.createIntermediatesPreview).toHaveBeenLastCalledWith(+ { mode: 'safe', scope: { kind: 'selection', targets: [{ projectId: 'p55', userId: 'alice' }] } },+ expect.anything()+ )+ );+ });++ it('bounds exclusion snapshots and reports the preview limit instead of guessing a selection estimate', async () => {+ const manyRows = Array.from({ length: 1001 }, (_, index) => row(`p${index}`, `Project ${index}`, 1));+ dependencies.getIntermediatesSummary+ .mockReset()+ .mockImplementation((params: { offset?: number; limit?: number }) => {+ const offset = params.offset ?? 0;+ return Promise.resolve({+ ...summaryOf(manyRows),+ items: manyRows.slice(offset, offset + (params.limit ?? 50)),+ offset,+ });+ });+ await renderManager();+ await vi.waitFor(() => expect(host.textContent).toContain('Project 0'));+ await act(() => checkbox('intermediates.list.selectAll').click());+ await act(() => checkbox('intermediates.list.selectRow(name=Project 1)').click());+ await vi.waitFor(() => expect(host.textContent).toContain('intermediates.selection.tooManyRows'));+ expect(dependencies.getIntermediatesSummary.mock.calls.filter(([params]) => params.limit === 1000)).toHaveLength(1);+ expect(buttonWithText('intermediates.list.delete', host).disabled).toBe(false);+ await act(() => buttonWithText('intermediates.list.delete', host).click());+ await vi.waitFor(() =>+ expect(document.querySelector('[role="alertdialog"]')?.textContent).toContain('intermediates.dialog.tooManyRows')+ );+ expect(dependencies.createIntermediatesPreview).not.toHaveBeenCalled();+ });});diff --git a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsx b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsxindex 58957d51e2..1c0f02e18f 100644--- a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsx+++ b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsx@@ -23,9 +23,7 @@ import {} from '@chakra-ui/react';import {EMPTY_SELECTION,- getPageSelectionState,isRowSelected,- isSelectionEmpty,resolveScope,selectAllMatching,summarizeSelection,@@ -204,6 +202,15 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI}const focusedRow = pendingProjectId ? rows.find((row) => row.projectId === pendingProjectId) : undefined;const effectiveSelection = focusedRow ? withRowSelected(selection, focusedRow) : selection;+ const hasExclusions = effectiveSelection.mode === 'all-matching' && effectiveSelection.excluded.size > 0;+ // One bounded read, shared across UI pages and refreshed by the same summary invalidations.+ const matchingSnapshotQuery = useQuery({+ ...intermediatesSummaryQueryOptions({ ...params, limit: INTERMEDIATES_MAX_ROWS, offset: 0 }),+ enabled: hasExclusions && query.data !== undefined,+ });+ const matchingSnapshot = matchingSnapshotQuery.data;+ const selectionOverLimit =+ hasExclusions && matchingSnapshot !== undefined && matchingSnapshot.total > matchingSnapshot.items.length;const operationQuery = useQuery({...intermediatesOperationQueryOptions(activeOperationId ?? ''),enabled: activeOperationId !== null,@@ -241,20 +248,27 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserIconst handleToggleRow = useCallback((row: IntermediatesRow) => {setPendingProjectId(null);- setSelection(toggleRowSelection(effectiveSelection, row, rows));+ setSelection(toggleRowSelection(effectiveSelection, row));},- [effectiveSelection, rows]+ [effectiveSelection]+ );+ const selectionSummary = useMemo(+ () =>+ summarizeSelection(+ effectiveSelection,+ totals ?? EMPTY_TOTALS,+ matchingSnapshot && !matchingSnapshotQuery.isError && !selectionOverLimit ? matchingSnapshot.items : undefined+ ),+ [effectiveSelection, matchingSnapshot, matchingSnapshotQuery.isError, selectionOverLimit, totals]);+ const matchingRowCount = hasExclusions ? matchingSnapshot?.total : totals?.rows;// Select all selects every matching row, including pages not loaded; only a complete selection clears.const handleToggleAll = useCallback(() => {setPendingProjectId(null);- setSelection(getPageSelectionState(effectiveSelection, rows) === 'all' ? EMPTY_SELECTION : selectAllMatching());- }, [effectiveSelection, rows]);-- const selectionSummary = useMemo(- () => summarizeSelection(effectiveSelection, totals ?? EMPTY_TOTALS),- [effectiveSelection, totals]- );+ setSelection(+ selectionSummary !== null && selectionSummary.rows === matchingRowCount ? EMPTY_SELECTION : selectAllMatching()+ );+ }, [selectionSummary, matchingRowCount]);const loadPreview = useCallback(async (mode: IntermediatesCleanupMode, scope: IntermediatesScope) => {@@ -270,8 +284,8 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI}));try {let resolvedScope = scope;- // Row filters cannot be expressed by the cleanup scope; resolve them to explicit rows.- if (effectiveSelection.mode === 'all-matching' && hasSubsetFilter && scope.kind === 'selection') {+ // Filters and exclusions cannot be expressed by the cleanup scope; resolve them to explicit rows.+ if (effectiveSelection.mode === 'all-matching' && scope.kind === 'selection') {const everything = await getIntermediatesSummary({ ...params, limit: INTERMEDIATES_MAX_ROWS, offset: 0 },owner.signal@@ -282,7 +296,9 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI}resolvedScope = {kind: 'selection',- targets: everything.items.map(({ projectId, userId }) => ({ projectId, userId })),+ targets: everything.items+ .filter((row) => isRowSelected(effectiveSelection, row))+ .map(({ projectId, userId }) => ({ projectId, userId })),};}const preview = await createIntermediatesPreview({ mode, scope: resolvedScope }, owner.signal);@@ -302,7 +318,7 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI}}},- [effectiveSelection.mode, hasSubsetFilter, params, t]+ [effectiveSelection, params, t]);const openDialog = useCallback((scope: IntermediatesScope, trigger: HTMLElement | null) => {@@ -421,8 +437,12 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI}, [queryClient]);const selectedScope = resolveScope({ hasSubsetFilter, loadedRows: rows, ownerId, selection: effectiveSelection });- const hasSelection = !isSelectionEmpty(effectiveSelection);- const pageSelection = getPageSelectionState(effectiveSelection, rows);+ const hasSelection = selectionSummary ? selectionSummary.rows > 0 : hasExclusions && (totals?.rows ?? 0) > 0;+ const selectionState = hasSelection+ ? selectionSummary !== null && selectionSummary.rows === matchingRowCount+ ? 'all'+ : 'some'+ : 'none';const filteredOwnerRow = ownerFilter ? rows[0] : undefined;const hasPreviousPage = offset > 0;const hasNextPage = query.data !== undefined && offset + rows.length < query.data.total;@@ -527,7 +547,7 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI<HStack borderBottomWidth="1px" borderColor="border.subtle" flexShrink={0} gap="2" minH="8" py="1.5"><Checkbox.Rootaria-label={t('intermediates.list.selectAll')}- checked={pageSelection === 'all' ? true : pageSelection === 'some' ? 'indeterminate' : false}+ checked={selectionState === 'all' ? true : selectionState === 'some' ? 'indeterminate' : false}colorPalette="accent"disabled={rows.length === 0}size="xs"@@ -541,20 +561,29 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI</Checkbox.Label></Checkbox.Root><Text color="fg.muted" flex="1" fontSize="2xs" minW="0" textAlign="end" truncate>- {hasSelection- ? t('intermediates.selection.estimate', {- count: selectionSummary.rows,- images: t('intermediates.counts.images', { count: selectionSummary.safeImages }),- size: formatBytes(selectionSummary.reclaimableBytes),- videos: t('intermediates.counts.videos', { count: selectionSummary.safeVideos }),- })- : totals- ? t('intermediates.selection.available', {- images: t('intermediates.counts.images', { count: totals.safeImages }),- size: formatBytes(totals.reclaimableBytes),- videos: t('intermediates.counts.videos', { count: totals.safeVideos }),+ {hasExclusions && selectionSummary === null+ ? t(+ selectionOverLimit+ ? 'intermediates.selection.tooManyRows'+ : matchingSnapshotQuery.isError+ ? 'intermediates.selection.estimateFailed'+ : 'intermediates.selection.checking',+ { count: INTERMEDIATES_MAX_ROWS }+ )+ : hasSelection && selectionSummary+ ? t('intermediates.selection.estimate', {+ count: selectionSummary.rows,+ images: t('intermediates.counts.images', { count: selectionSummary.safeImages }),+ size: formatBytes(selectionSummary.reclaimableBytes),+ videos: t('intermediates.counts.videos', { count: selectionSummary.safeVideos }),})- : ''}+ : totals+ ? t('intermediates.selection.available', {+ images: t('intermediates.counts.images', { count: totals.safeImages }),+ size: formatBytes(totals.reclaimableBytes),+ videos: t('intermediates.counts.videos', { count: totals.safeVideos }),+ })+ : ''}</Text>{query.data?.measuring ? (<Tooltip content={t('intermediates.stats.measuringNote')}>