Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Clear completed media uploads from the import queue (#12180)

[._.]/b68d4bfb67b5
diff --git a/client/src/components/media/MediaBatchImport.jsx b/client/src/components/media/MediaBatchImport.jsx
index 41f1cb061b..29331642b2 100644
--- a/client/src/components/media/MediaBatchImport.jsx
+++ b/client/src/components/media/MediaBatchImport.jsx
@@ -26,7 +26,7 @@ export default function MediaBatchImport({ collectionId, onImported }) {
setStopping(false);
const publish = () => { if (mounted.current) setRows(batch.map(row => ({ ...row }))); };
for (const row of batch) {
- if (row.status === 'done') continue;
+ if (row.status !== 'queued') continue;
if (cancelled.current) { row.status = 'cancelled'; continue; }
row.error = null;
row.status = row.saved ? 'assigning' : 'uploading';
@@ -60,12 +60,20 @@ export default function MediaBatchImport({ collectionId, onImported }) {
};
const completed = rows.filter(row => row.status === 'done').length;
- const retryable = rows.some(row => ['failed', 'cancelled'].includes(row.status));
+ // Keep results for retry/accounting, but completed files leave the visible queue.
+ const pending = rows.filter(row => ['queued', 'uploading', 'assigning'].includes(row.status));
+ const retryable = rows.filter(row => ['failed', 'cancelled'].includes(row.status));
+ const warnings = rows.filter(row => row.status === 'done' && row.saved.data.importWarnings?.length);
+ const retry = () => run(rows.map(row => ['failed', 'cancelled'].includes(row.status)
+ ? { ...row, status: 'queued', error: null } : row));
return (
<section aria-label="Import media" className="min-w-0 space-y-2">
<div className="flex flex-wrap items-center gap-2">
<FilePickerButton multiple accept={ACCEPT} disabled={busy}
- onChange={event => run(Array.from(event.target.files || []).map(file => ({ file, status: 'queued' })))}
+ onChange={event => {
+ const files = Array.from(event.target.files || []);
+ if (files.length) run([...rows, ...files.map(file => ({ file, status: 'queued' }))]);
+ }}
className="inline-flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-sm text-port-accent hover:bg-port-border/50">
<Upload className="h-4 w-4" aria-hidden="true" /> Upload / import
</FilePickerButton>
@@ -74,18 +82,27 @@ export default function MediaBatchImport({ collectionId, onImported }) {
onClick={() => { cancelled.current = true; setStopping(true); }}>
{stopping ? 'Finishing current file…' : 'Cancel remaining'}
</button>}
- {!busy && retryable && <button type="button" onClick={() => run(rows)} className="min-h-[44px] px-3 text-sm text-port-accent">Retry failed / cancelled</button>}
</div>
- {rows.length > 0 && <>
- <p role="status" className="text-xs text-gray-400">{formatCount(completed)} of {formatCount(rows.length)} imported{busy ? ' — working…' : ''}</p>
- <ul className="max-h-56 overflow-y-auto space-y-1 text-xs" aria-label="Import results">
- {rows.map((row, index) => <li key={index} className="break-words rounded border border-port-border px-2 py-1">
- <span className="font-medium">{row.file.name}</span>: {row.status === 'done' ? 'Imported' : row.status}
- {row.status === 'done' && <span> — {row.saved.data.importWarnings?.length ? row.saved.data.importWarnings.join(' ') : row.saved.data.prompt ? 'Embedded prompt imported' : 'No supported embedded prompt found'}</span>}
- {row.error && <p role="alert" className="text-port-error">{row.error}</p>}
+ <p role="status" aria-atomic="true" className={busy ? 'text-xs text-gray-400' : 'sr-only'}>
+ {rows.length > 0 && `${formatCount(completed)} of ${formatCount(rows.length)} imported${busy ? ' — working…' : ''}`}
+ </p>
+ {pending.length > 0 && <ul className="max-h-56 overflow-y-auto space-y-1 text-xs" aria-label="Import queue">
+ {pending.map((row, index) => <li key={index} className="break-words rounded border border-port-border px-2 py-1">
+ <span className="font-medium">{row.file.name}</span>: {row.status}
+ </li>)}
+ </ul>}
+ {retryable.length > 0 && <section aria-label="Imports needing attention" className="rounded border border-port-border p-2 text-xs">
+ <p className="font-medium">Some files still need attention</p>
+ <ul className="max-h-56 overflow-y-auto space-y-1">
+ {retryable.map((row, index) => <li key={index} role={row.error ? 'alert' : undefined} className="break-words text-port-error">
+ <span className="font-medium">{row.file.name}</span>: {row.error || 'Cancelled. Retry to resume.'}
</li>)}
</ul>
- </>}
+ <button type="button" disabled={busy} onClick={retry} className="min-h-[44px] px-3 text-sm text-port-accent disabled:opacity-50">Retry failed / cancelled</button>
+ </section>}
+ {warnings.length > 0 && <section aria-label="Import warnings" className="text-xs text-port-warning">
+ {warnings.map((row, index) => <p key={index} role="status" className="break-words">{row.file.name}: {row.saved.data.importWarnings.join(' ')}</p>)}
+ </section>}
</section>
);
}
diff --git a/client/src/components/media/MediaBatchImport.test.jsx b/client/src/components/media/MediaBatchImport.test.jsx
index 5f86df755b..1de0eb6692 100644
--- a/client/src/components/media/MediaBatchImport.test.jsx
+++ b/client/src/components/media/MediaBatchImport.test.jsx
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
const { request } = vi.hoisted(() => ({ request: vi.fn() }));
vi.mock('../../services/apiCore.js', async importOriginal => ({ ...await importOriginal(), request }));
import MediaBatchImport from './MediaBatchImport';
@@ -26,7 +26,8 @@ describe('shared gallery batch import', () => {
pick([image, video, new File(['x'], 'unsafe.svg'), image]);
await waitFor(() => expect(imported).toHaveBeenCalledTimes(2));
expect(screen.getByText('2 of 4 imported')).toBeInTheDocument();
- expect(screen.getByText(/Unsupported type/)).toBeInTheDocument();
+ expect(screen.queryByRole('list', { name: 'Import queue' })).not.toBeInTheDocument();
+ expect(within(screen.getByRole('region', { name: 'Imports needing attention' })).getByText(/Unsupported type/)).toBeInTheDocument();
expect(screen.getByText(/Image decoder rejected the bytes/)).toBeInTheDocument();
expect(request.mock.calls.map(([path]) => path)).toEqual(['/image-gen/upload', '/video-gen/upload', '/image-gen/upload']);
for (const [, options] of request.mock.calls) {
@@ -50,6 +51,8 @@ describe('shared gallery batch import', () => {
failAssignment = false;
fireEvent.click(screen.getByRole('button', { name: 'Retry failed / cancelled' }));
await screen.findByText('1 of 1 imported');
+ expect(screen.queryByRole('region', { name: 'Imports needing attention' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('list', { name: 'Import queue' })).not.toBeInTheDocument();
expect(request.mock.calls.filter(([path]) => path === '/image-gen/upload')).toHaveLength(1);
const assignments = request.mock.calls.filter(([path]) => path === '/media/collections/collection-a/items/bulk');
expect(assignments).toHaveLength(2);
@@ -65,7 +68,10 @@ describe('shared gallery batch import', () => {
fireEvent.click(screen.getByRole('button', { name: 'Cancel remaining' }));
await act(async () => finish(savedImage));
expect(request).toHaveBeenCalledTimes(1);
- expect(screen.getByText('1 of 2 imported')).toBeInTheDocument();
+ expect(screen.getByText('1 of 2 imported')).toHaveClass('sr-only');
+ expect(screen.queryByRole('list', { name: 'Import queue' })).not.toBeInTheDocument();
+ expect(screen.queryByText('portrait.png')).not.toBeInTheDocument();
+ expect(within(screen.getByRole('region', { name: 'Imports needing attention' })).getByText('clip.mp4')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'Retry failed / cancelled' }));
await screen.findByText('2 of 2 imported');
expect(request).toHaveBeenCalledTimes(2);
@@ -96,3 +102,59 @@ it('uses the current view callback when filters change during upload', async ()
expect(oldView).not.toHaveBeenCalled();
expect(newView).toHaveBeenCalledTimes(1);
});
+
+it.each([undefined, 'collection-a'])('clears completed rows while later files remain queued or in progress (collection: %s)', async collectionId => {
+ let finishImage;
+ let finishVideo;
+ let finishAssignment;
+ request.mockImplementation(path => {
+ if (path === '/image-gen/upload') return new Promise(resolve => { finishImage = resolve; });
+ if (path === '/video-gen/upload') return new Promise(resolve => { finishVideo = resolve; });
+ if (!finishAssignment) return new Promise(resolve => { finishAssignment = resolve; });
+ return Promise.resolve({ collection: { id: collectionId, items: [] } });
+ });
+ render(<MediaBatchImport collectionId={collectionId} />);
+ pick([image, video]);
+ expect(within(screen.getByRole('list', { name: 'Import queue' })).getAllByRole('listitem')).toHaveLength(2);
+ expect(screen.getByText(/: queued/)).toBeInTheDocument();
+ await act(async () => finishImage(savedImage));
+ if (collectionId) {
+ expect(screen.getByText(/: assigning/)).toBeInTheDocument();
+ expect(screen.getByText('portrait.png')).toBeInTheDocument();
+ await act(async () => finishAssignment({ collection: { id: collectionId, items: [] } }));
+ }
+ expect(screen.queryByText('portrait.png')).not.toBeInTheDocument();
+ expect(within(screen.getByRole('list', { name: 'Import queue' })).getAllByRole('listitem')).toHaveLength(1);
+ expect(screen.getByRole('status')).toHaveTextContent('1 of 2 imported');
+ await act(async () => finishVideo(savedVideo));
+ expect(screen.queryByRole('list', { name: 'Import queue' })).not.toBeInTheDocument();
+ expect(screen.queryByText('clip.mp4')).not.toBeInTheDocument();
+ expect(screen.getByRole('status')).toHaveClass('sr-only');
+ expect(screen.getByRole('status')).toHaveTextContent('2 of 2 imported');
+});
+
+it('keeps failed imports retryable when another batch is selected without retrying them implicitly', async () => {
+ request.mockRejectedValueOnce(new Error('Image decoder rejected the bytes'));
+ render(<MediaBatchImport />);
+ pick([image]);
+ await screen.findByText(/Image decoder rejected the bytes/);
+ pick([video]);
+ await screen.findByText('1 of 2 imported');
+ expect(request).toHaveBeenCalledTimes(2);
+ expect(screen.getByRole('region', { name: 'Imports needing attention' })).toHaveTextContent('portrait.png');
+ expect(screen.queryByText('clip.mp4')).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Retry failed / cancelled' }));
+ await screen.findByText('2 of 2 imported');
+ expect(request.mock.calls.map(([path]) => path)).toEqual(['/image-gen/upload', '/video-gen/upload', '/image-gen/upload']);
+ expect(screen.queryByRole('region', { name: 'Imports needing attention' })).not.toBeInTheDocument();
+});
+
+it('keeps inspection warnings separate from the completed upload queue', async () => {
+ request.mockResolvedValueOnce({ ...savedVideo, importWarnings: ['Embedded metadata could not be inspected.'] });
+ render(<MediaBatchImport />);
+ pick([video]);
+ await screen.findByText('1 of 1 imported');
+ expect(screen.queryByRole('list', { name: 'Import queue' })).not.toBeInTheDocument();
+ expect(screen.getByRole('region', { name: 'Import warnings' })).toHaveTextContent('clip.mp4: Embedded metadata could not be inspected.');
+ expect(screen.queryByRole('button', { name: /Retry/ })).not.toBeInTheDocument();
+});
diff --git a/client/src/pages/MediaCollectionDetail.test.jsx b/client/src/pages/MediaCollectionDetail.test.jsx
index ba24f4cd6f..d76b570d0a 100644
--- a/client/src/pages/MediaCollectionDetail.test.jsx
+++ b/client/src/pages/MediaCollectionDetail.test.jsx
@@ -518,7 +518,8 @@ it('uploads image and video files into the selected collection without replacing
const input = await screen.findByLabelText('Upload / import');
expect(input.multiple).toBe(true);
fireEvent.change(input, { target: { files: [new File(['png'], 'new.png'), new File(['mp4'], 'new.mp4')] } });
- await screen.findByText('2 of 2 imported');
+ expect(await screen.findByText('2 of 2 imported')).toHaveClass('sr-only');
+ expect(screen.queryByRole('list', { name: 'Import queue' })).not.toBeInTheDocument();
expect(batchApi.assignImportedMedia.mock.calls.map(call => call[0])).toEqual(['col-real', 'col-real']);
expect(collection.items).toEqual([REAL_COLLECTION.items[0], { kind: 'image', ref: 'new.png' }, { kind: 'video', ref: 'new-video' }]);
});
diff --git a/client/src/pages/MediaHistory.test.jsx b/client/src/pages/MediaHistory.test.jsx
index 90ac1986b5..e60c21c273 100644
--- a/client/src/pages/MediaHistory.test.jsx
+++ b/client/src/pages/MediaHistory.test.jsx
@@ -137,7 +137,8 @@ it('imports a mixed batch from History and inserts both returned records', async
const input = screen.getByLabelText('Upload / import');
expect(input.multiple).toBe(true);
fireEvent.change(input, { target: { files: [new File(['png'], 'new.png'), new File(['mp4'], 'new.mp4')] } });
- await screen.findByText('2 of 2 imported');
+ expect(await screen.findByText('2 of 2 imported')).toHaveClass('sr-only');
+ expect(screen.queryByRole('list', { name: 'Import queue' })).not.toBeInTheDocument();
expect(await screen.findByText('Imported image prompt')).toBeInTheDocument();
expect(await screen.findByText('Imported video prompt')).toBeInTheDocument();
expect(batchApi.assignImportedMedia).not.toHaveBeenCalled();