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

fix: retain imported-data confirmation and failure state during deletion

[._.]/ Adam Eivyc66fb6c60f2c
diff --git a/client/src/components/timeline/ManageImportedDataPanel.jsx b/client/src/components/timeline/ManageImportedDataPanel.jsx
index 026729a7ee..9984e0a182 100644
--- a/client/src/components/timeline/ManageImportedDataPanel.jsx
+++ b/client/src/components/timeline/ManageImportedDataPanel.jsx
@@ -1,7 +1,8 @@
-import { useEffect, useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
import { Trash2, Loader2 } from 'lucide-react';
import * as api from '../../services/api';
import toast from '../ui/Toast';
+import CollapsibleListItem from '../ui/CollapsibleListItem';
import { formatCount, formatDateNumeric } from '../../utils/formatters';
// Per-source counts with a typed-confirmation erase (#12987). Deleting is
@@ -12,34 +13,55 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {
const [target, setTarget] = useState(null);
const [typed, setTyped] = useState('');
const [busy, setBusy] = useState(false);
+ const [error, setError] = useState(null);
+ const [removing, setRemoving] = useState(null);
+ const pending = useRef(false);
+ const generation = useRef(0);
useEffect(() => {
let active = true;
- api.getTimelineSources({ silent: true }).then((r) => { if (active) setSources(r?.sources || []); }).catch(() => {});
+ const current = ++generation.current;
+ api.getTimelineSources({ silent: true }).then((r) => {
+ if (active && generation.current === current) { setSources(r?.sources || []); setError(null); }
+ }).catch((err) => { if (active && generation.current === current) setError(err.message || 'Could not load imported data.'); });
return () => { active = false; };
}, [reloadKey]);
const cancel = () => { setTarget(null); setTyped(''); };
const erase = async () => {
+ const source = target;
+ if (pending.current || !source || typed !== source) return;
+ pending.current = true;
+ generation.current++;
setBusy(true);
- const result = await api.eraseTimelineSource(target).catch(() => null);
+ setError(null);
+ const result = await api.eraseTimelineSource(source, { silent: true })
+ .catch((err) => { setError(err.message || 'Could not delete imported data.'); return null; });
+ pending.current = false;
setBusy(false);
if (!result) return;
- toast.success(`Deleted ${formatCount(result.deleted)} ${target} event(s)`);
- setSources((list) => list.filter((s) => s.source !== target));
+ toast.success(`Deleted ${formatCount(result.deleted)} ${source} event(s)`);
+ setRemoving(source);
cancel();
+ };
+
+ const finishRemoval = (source) => {
+ setSources((list) => list.filter((row) => row.source !== source));
+ setRemoving(null);
onChanged?.();
};
- if (sources.length === 0) return null;
+ if (sources.length === 0 && !error) return null;
return (
<div className="rounded border border-port-border bg-port-card p-3 text-xs">
<div className="mb-2 font-medium text-gray-300">Manage imported data</div>
- <ul className="space-y-2">
+ {error && <p role="alert" className="mb-2 text-port-error">{error}</p>}
+ <div role="list" tabIndex={-1}>
{sources.map((s) => (
- <li key={s.source}>
+ <CollapsibleListItem key={s.source} removing={removing === s.source} onExited={() => finishRemoval(s.source)}>
+ <div role="listitem">
<div className="flex flex-wrap items-center gap-2">
<span className="font-mono text-gray-200">{s.source}</span>
<span className="text-gray-400">
@@ -48,7 +70,8 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {
</span>
<button
type="button"
- onClick={() => { setTarget(s.source); setTyped(''); }}
+ disabled={busy || !!removing}
+ onClick={() => { setTarget(s.source); setTyped(''); setError(null); }}
className="ml-auto inline-flex items-center gap-1 rounded border border-port-border px-2 py-1 text-port-error hover:border-port-error"
>
<Trash2 size={12} /> Delete
@@ -61,6 +84,7 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {
</label>
<input
id={`erase-${s.source}`}
+ disabled={busy}
value={typed}
onChange={(e) => setTyped(e.target.value)}
className="rounded border border-port-border bg-port-bg px-2 py-1 text-gray-200"
@@ -73,12 +97,13 @@ export default function ManageImportedDataPanel({ reloadKey, onChanged }) {
>
{busy && <Loader2 size={12} className="animate-spin" />} Confirm delete
</button>
- <button type="button" onClick={cancel} className="px-2 py-1 text-gray-400 hover:text-gray-200">Cancel</button>
+ <button type="button" disabled={busy} onClick={cancel} className="px-2 py-1 text-gray-400 hover:text-gray-200">Cancel</button>
</div>
)}
- </li>
+ </div>
+ </CollapsibleListItem>
))}
- </ul>
+ </div>
</div>
);
}
diff --git a/client/src/components/timeline/ManageImportedDataPanel.test.jsx b/client/src/components/timeline/ManageImportedDataPanel.test.jsx
new file mode 100644
index 0000000000..a9cc2703c3
--- /dev/null
+++ b/client/src/components/timeline/ManageImportedDataPanel.test.jsx
@@ -0,0 +1,54 @@
+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { beforeEach, expect, it, vi } from 'vitest';
+import ManageImportedDataPanel from './ManageImportedDataPanel';
+
+const api = vi.hoisted(() => ({ getTimelineSources: vi.fn(), eraseTimelineSource: vi.fn() }));
+vi.mock('../../services/api', () => api);
+vi.mock('../ui/Toast', () => ({ default: { success: vi.fn() } }));
+vi.mock('../../hooks/usePrefersReducedMotion', () => ({ default: () => true }));
+const sources = [{ source: 'browser', eventCount: 3 }, { source: 'discord', eventCount: 2 }];
+beforeEach(() => { vi.clearAllMocks(); api.getTimelineSources.mockResolvedValue({ sources }); });
+
+it('keeps the confirmed source fixed during deletion and ignores a pre-delete count response', async () => {
+ let finishDelete;
+ let finishCounts;
+ api.eraseTimelineSource.mockImplementation(() => new Promise(resolve => { finishDelete = resolve; }));
+ const onChanged = vi.fn();
+ const view = render(<ManageImportedDataPanel reloadKey={0} onChanged={onChanged} />);
+ await screen.findByText('browser');
+ api.getTimelineSources.mockImplementationOnce(() => new Promise(resolve => { finishCounts = resolve; }));
+ view.rerender(<ManageImportedDataPanel reloadKey={1} onChanged={onChanged} />);
+ fireEvent.click(screen.getAllByRole('button', { name: 'Delete' })[0]);
+ fireEvent.change(screen.getByRole('textbox'), { target: { value: 'browser' } });
+ fireEvent.click(screen.getByRole('button', { name: 'Confirm delete' }));
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeDisabled();
+ expect(screen.getAllByRole('button', { name: 'Delete' }).every(button => button.disabled)).toBe(true);
+ await act(async () => { finishCounts({ sources: [] }); });
+ expect(screen.getByRole('textbox')).toHaveValue('browser');
+ expect(api.eraseTimelineSource).toHaveBeenCalledTimes(1);
+ expect(api.eraseTimelineSource.mock.calls[0][0]).toBe('browser');
+ await act(async () => { finishDelete({ deleted: 3 }); });
+ await waitFor(() => expect(screen.queryByText('browser')).not.toBeInTheDocument());
+ expect(screen.getByText('discord')).toBeInTheDocument();
+ expect(onChanged).toHaveBeenCalledTimes(1);
+});
+
+it('retains the row and confirmation and shows a refused deletion', async () => {
+ api.eraseTimelineSource.mockRejectedValueOnce(new Error('Deletion unavailable'));
+ const onChanged = vi.fn();
+ render(<ManageImportedDataPanel onChanged={onChanged} />);
+ await screen.findByText('browser');
+ fireEvent.click(screen.getAllByRole('button', { name: 'Delete' })[0]);
+ fireEvent.change(screen.getByRole('textbox'), { target: { value: 'browser' } });
+ fireEvent.click(screen.getByRole('button', { name: 'Confirm delete' }));
+ expect(await screen.findByRole('alert')).toHaveTextContent('Deletion unavailable');
+ expect(screen.getByRole('textbox')).toHaveValue('browser');
+ expect(screen.getByRole('button', { name: 'Confirm delete' })).toBeEnabled();
+ expect(onChanged).not.toHaveBeenCalled();
+});
+
+it('shows a failed source-count read instead of hiding the management panel', async () => {
+ api.getTimelineSources.mockRejectedValueOnce(new Error('Sources unavailable'));
+ render(<ManageImportedDataPanel />);
+ expect(await screen.findByRole('alert')).toHaveTextContent('Sources unavailable');
+});
diff --git a/client/src/services/apiTimeline.js b/client/src/services/apiTimeline.js
index 8285a4f8c8..0af69b716c 100644
--- a/client/src/services/apiTimeline.js
+++ b/client/src/services/apiTimeline.js
@@ -81,10 +81,10 @@ export const importGmailMbox = ({ path, preview = false, yourEmail, ...options }
export const getTimelineSources = (options = {}) =>
request('/timeline/sources', { silent: options.silent });
-export const eraseTimelineSource = (source, { from, to, kind } = {}) => {
+export const eraseTimelineSource = (source, { from, to, kind, silent } = {}) => {
const params = new URLSearchParams({ source });
if (from) params.set('from', from);
if (to) params.set('to', to);
if (kind) params.set('kind', kind);
- return request(`/timeline/events?${params}`, { method: 'DELETE' });
+ return request(`/timeline/events?${params}`, { method: 'DELETE', silent });
};