Video page: move Delete into the Edit dropdown

The Edit dropdown now holds Refresh, Transcode and Delete, so the action
row is Download / Edit / Add to Playlist.  Delete keeps its confirmation
(a Confirm dialog) and the tagged-files prompt, and is disabled in WROL
Mode like the other items.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-09-14 18:42:54 -06:00
parent e480a386d0
commit 712d89c424
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 72 additions and 13 deletions

View file

@ -1,7 +1,7 @@
import React, {useEffect, useRef, useState} from 'react';
import {cancelJob, fetchVideoDownloadDefaults, getJob, transcodeVideo} from '../api';
import {useWROLMode} from '../hooks/customHooks';
import {Button, Group, Icon, Menu, Modal, Progress, Select, Stack, Status, Text, toast} from './ui';
import {Button, Confirm, Group, Icon, Menu, Modal, Progress, Select, Stack, Status, Text, toast} from './ui';
import {
TRANSCODE_COPY,
transcodeAudioCodecOptions,
@ -269,15 +269,28 @@ export function TranscodeModal({open, onClose, fileGroupId, video, onComplete})
}
/**
* The "Edit" dropdown on the Video page: Refresh (re-download metadata) and Transcode.
* The "Edit" dropdown on the Video page: Refresh (re-download metadata), Transcode, and Delete.
*
* `onRefresh` is awaited; `onTranscodeComplete` is called after the file was replaced so the
* page can fetch the Video again (its path and codecs changed).
* page can fetch the Video again (its path and codecs changed). `onDelete` is awaited after the
* user confirms; the page decides what happens next (navigate away, or the tagged-files prompt).
*/
export function VideoEditMenu({videoFile, video, onRefresh, onTranscodeComplete}) {
export function VideoEditMenu({videoFile, video, onRefresh, onTranscodeComplete, onDelete}) {
const wrolModeEnabled = useWROLMode();
const [transcodeOpen, setTranscodeOpen] = useState(false);
const [refreshing, setRefreshing] = useState(false);
const [deleteOpen, setDeleteOpen] = useState(false);
const [deleting, setDeleting] = useState(false);
const handleDelete = async () => {
setDeleting(true);
try {
await onDelete();
setDeleteOpen(false);
} finally {
setDeleting(false);
}
};
const handleRefresh = async () => {
setRefreshing(true);
@ -310,8 +323,29 @@ export function VideoEditMenu({videoFile, video, onRefresh, onTranscodeComplete}
>
Transcode...
</Menu.Item>
<Menu.Divider/>
<Menu.Item
color='var(--danger)'
leftSection={<Icon name='trash'/>}
onClick={() => setDeleteOpen(true)}
disabled={!onDelete || !!wrolModeEnabled}
>
Delete...
</Menu.Item>
</Menu.Dropdown>
</Menu>
<Confirm
open={deleteOpen}
title='Delete video?'
confirmLabel='Delete'
destructive
loading={deleting}
onConfirm={handleDelete}
onCancel={() => setDeleteOpen(false)}
>
Are you sure you want to delete this video? All files related to this video will be deleted.
It will not be downloaded again!
</Confirm>
<TranscodeModal
open={transcodeOpen}
onClose={() => setTranscodeOpen(false)}

View file

@ -182,13 +182,44 @@ describe('VideoEditMenu', () => {
expect(screen.getByRole('menuitem', {name: /Transcode/})).toBeDisabled();
});
test('WROL Mode disables both items', async () => {
test('WROL Mode disables every item', async () => {
renderWithProviders(
<VideoEditMenu videoFile={videoFile} video={video} onRefresh={jest.fn()}/>,
<VideoEditMenu videoFile={videoFile} video={video} onRefresh={jest.fn()} onDelete={jest.fn()}/>,
wrolMode,
);
fireEvent.click(screen.getByRole('button', {name: /Edit/}));
expect(await screen.findByRole('menuitem', {name: /Refresh/})).toBeDisabled();
expect(screen.getByRole('menuitem', {name: /Transcode/})).toBeDisabled();
expect(screen.getByRole('menuitem', {name: /Delete/})).toBeDisabled();
});
test('Delete asks for confirmation before calling onDelete', async () => {
const onDelete = jest.fn().mockResolvedValue(undefined);
renderWithProviders(
<VideoEditMenu videoFile={videoFile} video={video} onRefresh={jest.fn()} onDelete={onDelete}/>,
);
fireEvent.click(screen.getByRole('button', {name: /Edit/}));
fireEvent.click(await screen.findByRole('menuitem', {name: /Delete/}));
expect(await screen.findByText('Delete video?')).toBeInTheDocument();
expect(onDelete).not.toHaveBeenCalled();
fireEvent.click(await screen.findByRole('button', {name: 'Delete'}));
await waitFor(() => expect(onDelete).toHaveBeenCalledTimes(1));
});
test('backing out of the Delete confirmation deletes nothing', async () => {
const onDelete = jest.fn();
renderWithProviders(
<VideoEditMenu videoFile={videoFile} video={video} onRefresh={jest.fn()} onDelete={onDelete}/>,
);
fireEvent.click(screen.getByRole('button', {name: /Edit/}));
fireEvent.click(await screen.findByRole('menuitem', {name: /Delete/}));
expect(await screen.findByText('Delete video?')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', {name: 'Cancel'}));
await waitFor(() => expect(screen.queryByText('Delete video?')).not.toBeInTheDocument());
expect(onDelete).not.toHaveBeenCalled();
});
});

View file

@ -489,18 +489,12 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
<Button component='a' href={downloadUrl} icon='download'>
Download
</Button>
<APIButton
role='danger'
confirmContent='Are you sure you want to delete this video? All files related to this video will be deleted. It will not be downloaded again!'
confirmButton='Delete'
onClick={async () => await handleDeleteVideo(videoFile.id)}
obeyWROLMode={true}
>Delete</APIButton>
<VideoEditMenu
videoFile={videoFile}
video={video}
onRefresh={handleRefresh}
onTranscodeComplete={fetchVideo}
onDelete={async () => await handleDeleteVideo(videoFile.id)}
/>
<AddToPlaylistButton fileGroupId={videoFile.id}/>
</div>