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: confirm catalog media detachment (#5207) (#5277)

[._.]/ Adam Eivyd840b54b2804
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsx
index 20cc86046a..f03b0d2ae6 100644
--- a/client/src/pages/CatalogIngredient.jsx
+++ b/client/src/pages/CatalogIngredient.jsx
@@ -1169,6 +1169,7 @@ function MediaPanel({ media, missingMedia, onAttach, onSetPortrait, onDetach, on
const [dragOver, setDragOver] = useState(false);
const [busy, setBusy] = useState(false); // upload or transcription in flight
const [recording, setRecording] = useState(false);
+ const [armedDetach, setArmedDetach] = useState(null);
const recorderRef = useRef(null);
const list = Array.isArray(media) ? media : [];
const portrait = list.find((m) => m.kind === 'portrait');
@@ -1271,7 +1272,8 @@ function MediaPanel({ media, missingMedia, onAttach, onSetPortrait, onDetach, on
<div className="mb-3">
<div className="text-[10px] uppercase tracking-wider text-gray-500 mb-1">Portrait</div>
<MediaTile m={portrait} missing={missingMedia.has(portrait.mediaKey)} isPortrait
- onSetPortrait={onSetPortrait} onDetach={onDetach} />
+ onSetPortrait={onSetPortrait} onDetach={onDetach} armedDetach={armedDetach}
+ onArmDetach={setArmedDetach} />
</div>
)}
@@ -1279,7 +1281,8 @@ function MediaPanel({ media, missingMedia, onAttach, onSetPortrait, onDetach, on
<div className="grid grid-cols-2 sm:grid-cols-3 gap-2">
{others.map((m) => (
<MediaTile key={`${m.mediaKey}:${m.kind}`} m={m} missing={missingMedia.has(m.mediaKey)}
- onSetPortrait={onSetPortrait} onDetach={onDetach} />
+ onSetPortrait={onSetPortrait} onDetach={onDetach} armedDetach={armedDetach}
+ onArmDetach={setArmedDetach} />
))}
</div>
)}
@@ -1307,7 +1310,7 @@ function MediaPanel({ media, missingMedia, onAttach, onSetPortrait, onDetach, on
// `missing` integrity flag warns about). Audio/video render inline players
// (their bytes are served from /data/audio and /data/videos); a voice memo's
// transcript rides in `caption`. Other kinds render a labeled chip.
-function MediaTile({ m, missing, isPortrait = false, onSetPortrait, onDetach }) {
+function MediaTile({ m, missing, isPortrait = false, onSetPortrait, onDetach, armedDetach, onArmDetach }) {
const isImage = m.kind === 'portrait' || m.kind === 'reference';
const isAudio = m.kind === 'audio';
const isVideo = m.kind === 'video';
@@ -1347,10 +1350,18 @@ function MediaTile({ m, missing, isPortrait = false, onSetPortrait, onDetach })
<Star size={12} aria-hidden="true" />
</button>
)}
- <button type="button" onClick={() => onDetach(m.mediaKey, m.kind)} title="Detach" aria-label="Detach"
- className="p-2 sm:p-1 rounded bg-black/60 text-gray-200 hover:text-port-error">
- <X size={12} aria-hidden="true" />
- </button>
+ {armedDetach === `${m.mediaKey}:${m.kind}` ? (
+ <ConfirmButtonPair prompt="Detach?" confirmText="Detach" cancelText="Cancel"
+ ariaLabel="Confirm media detach" onConfirm={() => {
+ onArmDetach(null);
+ onDetach(m.mediaKey, m.kind);
+ }} onCancel={() => onArmDetach(null)} largeTouchTargets />
+ ) : (
+ <button type="button" onClick={() => onArmDetach(`${m.mediaKey}:${m.kind}`)} title="Detach" aria-label="Detach"
+ className="p-2 sm:p-1 rounded bg-black/60 text-gray-200 hover:text-port-error">
+ <X size={12} aria-hidden="true" />
+ </button>
+ )}
</div>
</div>
);
diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsx
index 234c0ec2e5..a7921e5f92 100644
--- a/client/src/pages/CatalogIngredient.test.jsx
+++ b/client/src/pages/CatalogIngredient.test.jsx
@@ -112,7 +112,7 @@ vi.mock('../components/TagPicker', () => ({
vi.mock('../components/ui/Toast', () => ({ default: { success: vi.fn(), error: vi.fn(), info: vi.fn() } }));
import CatalogIngredient, { buildGenerationPromptSeed } from './CatalogIngredient';
-import { getCatalogIngredientDetails, unlinkCatalogIngredientRelation, updateCatalogIngredient } from '../services/apiCatalog';
+import { getCatalogIngredientDetails, unlinkCatalogIngredientRelation, updateCatalogIngredient, detachCatalogIngredientMedia } from '../services/apiCatalog';
const renderPage = (path = '/catalog/character/cat-chr-1') => {
const router = createMemoryRouter([
@@ -126,9 +126,28 @@ beforeEach(() => {
getCatalogIngredientDetails.mockImplementation(async () => detailsOf(CHAR_FIXTURE));
updateCatalogIngredient.mockReset();
unlinkCatalogIngredientRelation.mockReset();
+ detachCatalogIngredientMedia.mockReset();
});
describe('CatalogIngredient — character sheet', () => {
+ it('requires confirmation before detaching media', async () => {
+ detachCatalogIngredientMedia.mockResolvedValue({});
+ getCatalogIngredientDetails.mockImplementation(async () => ({
+ ...detailsOf(CHAR_FIXTURE),
+ media: [{ mediaKey: 'portrait.png', kind: 'portrait' }],
+ }));
+ renderPage();
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Detach' })).toBeTruthy());
+
+ fireEvent.click(screen.getByRole('button', { name: 'Detach' }));
+ expect(detachCatalogIngredientMedia).not.toHaveBeenCalled();
+ expect(screen.getByRole('button', { name: 'Detach', exact: true })).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Detach', exact: true }));
+ await waitFor(() => expect(detachCatalogIngredientMedia).toHaveBeenCalledWith(
+ 'cat-chr-1', { mediaKey: 'portrait.png', kind: 'portrait' }, { silent: true },
+ ));
+ });
+
it('requires confirmation before removing an outbound relation', async () => {
unlinkCatalogIngredientRelation.mockResolvedValue({});
getCatalogIngredientDetails.mockImplementation(async () => ({