mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 11:56:18 -05:00
Models like Archive/Video/Doc can be deleted, even if they are tagged. User is shown a warning and must confirm deletion of tagged files.
This commit is contained in:
parent
513ae52a6e
commit
09a967535b
23 changed files with 689 additions and 109 deletions
|
|
@ -60,6 +60,7 @@ import {
|
|||
updateArchiveDownloaderConfig,
|
||||
} from "../api";
|
||||
import {InputForm, useForm} from "../hooks/useForm";
|
||||
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
||||
import {CollectionTagModal} from "./collections/CollectionTagModal";
|
||||
import {CollectionReorganizeModal} from "./collections/CollectionReorganizeModal";
|
||||
import {BatchReorganizeModal} from "./collections/BatchReorganizeModal";
|
||||
|
|
@ -96,6 +97,7 @@ function ArchivePage() {
|
|||
const {fileGroupId} = useParams();
|
||||
const {archiveFile, history, fetchArchive} = useArchive(fileGroupId);
|
||||
const {theme} = useContext(ThemeContext);
|
||||
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
||||
|
||||
let title = archiveFile ? archiveFile.title ? archiveFile.title : archiveFile.name : null;
|
||||
useTitle(title);
|
||||
|
|
@ -132,8 +134,12 @@ function ArchivePage() {
|
|||
<Image src={screenshotUrl} size='large' style={{marginTop: '1em', marginBottom: '1em'}}/> :
|
||||
null;
|
||||
|
||||
const localDeleteArchive = async () => {
|
||||
await deleteArchives([archiveFile.id]);
|
||||
const localDeleteArchive = async (force = false) => {
|
||||
const result = await deleteArchives([archiveFile.id], force);
|
||||
if (result && result.tagged) {
|
||||
setTaggedFileGroups(result.file_groups);
|
||||
return;
|
||||
}
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Archive Deleted',
|
||||
|
|
@ -180,7 +186,7 @@ function ArchivePage() {
|
|||
color='red'
|
||||
confirmContent='Are you sure you want to delete this archive? All files will be deleted'
|
||||
confirmButton='Delete'
|
||||
onClick={localDeleteArchive}
|
||||
onClick={() => localDeleteArchive(false)}
|
||||
obeyWROLMode={true}
|
||||
>
|
||||
Delete
|
||||
|
|
@ -356,6 +362,16 @@ function ArchivePage() {
|
|||
/>
|
||||
{historyList}
|
||||
</Segment>
|
||||
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={async () => {
|
||||
setTaggedFileGroups(null);
|
||||
await localDeleteArchive(true);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
@ -1082,6 +1098,7 @@ function ArchiveSettingsPage() {
|
|||
function ArchivesPage() {
|
||||
const [selectedArchives, setSelectedArchives] = useState([]);
|
||||
const [bulkTagOpen, setBulkTagOpen] = useState(false);
|
||||
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
||||
const searchInputRef = React.useRef();
|
||||
|
||||
useHotkeys('f', (e) => {
|
||||
|
|
@ -1132,10 +1149,17 @@ function ArchivesPage() {
|
|||
}
|
||||
}
|
||||
|
||||
const onDelete = async () => {
|
||||
const archiveIds = archives.filter(i => selectedArchives.indexOf(i['primary_path']) >= 0)
|
||||
.map(i => i['id']);
|
||||
await deleteArchives(archiveIds);
|
||||
const archiveIdsForSelection = () => archives
|
||||
.filter(i => selectedArchives.indexOf(i['primary_path']) >= 0)
|
||||
.map(i => i['id']);
|
||||
|
||||
const onDelete = async (force = false) => {
|
||||
const archiveIds = archiveIdsForSelection();
|
||||
const result = await deleteArchives(archiveIds, force);
|
||||
if (result && result.tagged) {
|
||||
setTaggedFileGroups(result.file_groups);
|
||||
return;
|
||||
}
|
||||
await fetchArchives();
|
||||
setSelectedArchives([]);
|
||||
}
|
||||
|
|
@ -1166,7 +1190,7 @@ function ArchivesPage() {
|
|||
disabled={_.isEmpty(selectedArchives)}
|
||||
confirmButton='Delete'
|
||||
confirmContent='Are you sure you want to delete these archives files? This cannot be undone.'
|
||||
onClick={onDelete}
|
||||
onClick={() => onDelete(false)}
|
||||
>Delete</APIButton>
|
||||
<Button
|
||||
color='grey'
|
||||
|
|
@ -1263,6 +1287,15 @@ function ArchivesPage() {
|
|||
</Media>
|
||||
{body}
|
||||
{paginator}
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={async () => {
|
||||
setTaggedFileGroups(null);
|
||||
await onDelete(true);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import {
|
|||
} from "./Common";
|
||||
import {Button, darkTheme, Header, Icon, Segment, Statistic, Tab} from "./Theme";
|
||||
import {BulkTagModal} from "./BulkTagModal";
|
||||
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
||||
import {DocSearchFilterButton, FilesView} from "./Files";
|
||||
import {useAuthors, useDoc, useOneQuery, useSearchDocs, useSubjects} from "../hooks/customHooks";
|
||||
import {TagsSelector} from "../Tags";
|
||||
|
|
@ -47,6 +48,7 @@ function DocsPage() {
|
|||
|
||||
const [selectedDocs, setSelectedDocs] = useState([]);
|
||||
const [bulkTagOpen, setBulkTagOpen] = useState(false);
|
||||
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
||||
|
||||
const onSelect = (path, checked) => {
|
||||
if (checked && path) {
|
||||
|
|
@ -56,9 +58,13 @@ function DocsPage() {
|
|||
}
|
||||
}
|
||||
|
||||
const onDelete = async () => {
|
||||
const onDelete = async (force = false) => {
|
||||
const docIds = docs.filter(i => selectedDocs.indexOf(i['primary_path']) >= 0).map(i => i['id']);
|
||||
await deleteDocs(docIds);
|
||||
const result = await deleteDocs(docIds, force);
|
||||
if (result && result.tagged) {
|
||||
setTaggedFileGroups(result.file_groups);
|
||||
return;
|
||||
}
|
||||
await fetchDocs();
|
||||
setSelectedDocs([]);
|
||||
}
|
||||
|
|
@ -86,7 +92,7 @@ function DocsPage() {
|
|||
disabled={_.isEmpty(selectedDocs)}
|
||||
confirmButton='Delete'
|
||||
confirmContent='Are you sure you want to delete these documents? This cannot be undone.'
|
||||
onClick={onDelete}
|
||||
onClick={() => onDelete(false)}
|
||||
obeyWROLMode={true}
|
||||
>Delete</APIButton>
|
||||
<Button color='grey' onClick={invertSelection} disabled={_.isEmpty(docs)}>Invert</Button>
|
||||
|
|
@ -162,6 +168,15 @@ function DocsPage() {
|
|||
</Media>
|
||||
{body}
|
||||
{paginator}
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={async () => {
|
||||
setTaggedFileGroups(null);
|
||||
await onDelete(true);
|
||||
}}
|
||||
/>
|
||||
</>;
|
||||
}
|
||||
|
||||
|
|
@ -171,6 +186,7 @@ function DocPage() {
|
|||
const {docFile, doc, fetchDoc} = useDoc(parseInt(fileGroupId));
|
||||
const {theme} = useContext(ThemeContext);
|
||||
const [searchParams] = useSearchParams();
|
||||
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
||||
// Deep-link params: `loc` = EPUB spine index, `page` = PDF page, `q` = search term.
|
||||
const locParam = searchParams.get('loc');
|
||||
const pageParam = searchParams.get('page');
|
||||
|
|
@ -244,9 +260,13 @@ function DocPage() {
|
|||
: null;
|
||||
const embedUrl = isEpub ? viewerUrl : pdfSrc;
|
||||
|
||||
const handleDelete = async () => {
|
||||
const handleDelete = async (force = false) => {
|
||||
if (doc && doc.id) {
|
||||
await deleteDocs([docFile.id]);
|
||||
const result = await deleteDocs([docFile.id], force);
|
||||
if (result && result.tagged) {
|
||||
setTaggedFileGroups(result.file_groups);
|
||||
return;
|
||||
}
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Document Deleted',
|
||||
|
|
@ -415,7 +435,7 @@ function DocPage() {
|
|||
color='red'
|
||||
confirmContent='Are you sure you want to delete this document? All files will be deleted.'
|
||||
confirmButton='Delete'
|
||||
onClick={handleDelete}
|
||||
onClick={() => handleDelete(false)}
|
||||
obeyWROLMode={true}
|
||||
>Delete</APIButton>
|
||||
</>;
|
||||
|
|
@ -442,6 +462,16 @@ function DocPage() {
|
|||
</Segment>
|
||||
|
||||
<Tab menu={tabMenu} panes={tabPanes}/>
|
||||
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={async () => {
|
||||
setTaggedFileGroups(null);
|
||||
await handleDelete(true);
|
||||
}}
|
||||
/>
|
||||
</>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import {FilePreviewContext} from "./FilePreview";
|
|||
import {DragSelectionContext, DragSelectionProvider, SettingsContext, ThemeContext} from "../contexts/contexts";
|
||||
import {BulkTagModal} from "./BulkTagModal";
|
||||
import {InlineErrorBoundary} from "./ErrorBoundary";
|
||||
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
||||
|
||||
function depthIndentation(path) {
|
||||
// Repeated spaces for every folder a path is in.
|
||||
|
|
@ -431,38 +432,12 @@ export function FileBrowser() {
|
|||
paths={selectedPaths}
|
||||
onComplete={reset}
|
||||
/>
|
||||
<Modal
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
onClose={() => setTaggedFileGroups(null)}
|
||||
closeIcon
|
||||
>
|
||||
<Modal.Header><Icon name='warning sign'/> Tagged Files Will Be Deleted</Modal.Header>
|
||||
<Modal.Content>
|
||||
<p>The following tagged files will be deleted:</p>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHeaderCell>File</TableHeaderCell>
|
||||
<TableHeaderCell>Tags</TableHeaderCell>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{taggedFileGroups && taggedFileGroups.map((fg, idx) => (
|
||||
<TableRow key={idx}>
|
||||
<TableCell>{fg.primary_path || fg.name}</TableCell>
|
||||
<TableCell>{(fg.tags || []).join(', ')}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={() => setTaggedFileGroups(null)}>Cancel</Button>
|
||||
<Button color='red' onClick={onForceDelete}>
|
||||
<Icon name='trash'/> Delete
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={onForceDelete}
|
||||
/>
|
||||
</div>;
|
||||
|
||||
const onFolderClick = async (folder) => {
|
||||
|
|
|
|||
34
app/src/components/TaggedDeleteConfirmModal.js
Normal file
34
app/src/components/TaggedDeleteConfirmModal.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import React from "react";
|
||||
import {Button, Icon, Modal, Table} from "./Theme";
|
||||
import {TableBody, TableCell, TableHeader, TableHeaderCell, TableRow} from "semantic-ui-react";
|
||||
|
||||
export function TaggedDeleteConfirmModal({open, taggedFileGroups, onConfirm, onCancel}) {
|
||||
return <Modal open={open} onClose={onCancel} closeIcon>
|
||||
<Modal.Header><Icon name='warning sign'/> Tagged Files Will Be Deleted</Modal.Header>
|
||||
<Modal.Content>
|
||||
<p>The following tagged files will be deleted:</p>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHeaderCell>File</TableHeaderCell>
|
||||
<TableHeaderCell>Tags</TableHeaderCell>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{(taggedFileGroups || []).map((fg, idx) => (
|
||||
<TableRow key={fg.id ?? idx}>
|
||||
<TableCell>{fg.primary_path || fg.name}</TableCell>
|
||||
<TableCell>{(fg.tags || []).join(', ')}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={onCancel}>Cancel</Button>
|
||||
<Button color='red' onClick={onConfirm}>
|
||||
<Icon name='trash'/> Delete
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>;
|
||||
}
|
||||
93
app/src/components/TaggedDeleteConfirmModal.test.js
Normal file
93
app/src/components/TaggedDeleteConfirmModal.test.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import React from 'react';
|
||||
import {screen, fireEvent} from '@testing-library/react';
|
||||
import {renderWithProviders} from '../test-utils';
|
||||
import {TaggedDeleteConfirmModal} from './TaggedDeleteConfirmModal';
|
||||
|
||||
describe('TaggedDeleteConfirmModal', () => {
|
||||
const sampleGroups = [
|
||||
{id: 1, primary_path: 'videos/foo.mp4', tags: ['favorite', 'review']},
|
||||
{id: 2, primary_path: 'archives/bar.html', tags: ['important']},
|
||||
];
|
||||
|
||||
it('renders nothing when closed', () => {
|
||||
renderWithProviders(
|
||||
<TaggedDeleteConfirmModal
|
||||
open={false}
|
||||
taggedFileGroups={sampleGroups}
|
||||
onConfirm={jest.fn()}
|
||||
onCancel={jest.fn()}
|
||||
/>
|
||||
);
|
||||
expect(screen.queryByText(/Tagged Files Will Be Deleted/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders rows for each tagged file group', () => {
|
||||
renderWithProviders(
|
||||
<TaggedDeleteConfirmModal
|
||||
open={true}
|
||||
taggedFileGroups={sampleGroups}
|
||||
onConfirm={jest.fn()}
|
||||
onCancel={jest.fn()}
|
||||
/>
|
||||
);
|
||||
expect(screen.getAllByText(/Tagged Files Will Be Deleted/i).length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('videos/foo.mp4')).toBeInTheDocument();
|
||||
expect(screen.getByText('archives/bar.html')).toBeInTheDocument();
|
||||
expect(screen.getByText('favorite, review')).toBeInTheDocument();
|
||||
expect(screen.getByText('important')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onCancel when Cancel button clicked', () => {
|
||||
const onCancel = jest.fn();
|
||||
renderWithProviders(
|
||||
<TaggedDeleteConfirmModal
|
||||
open={true}
|
||||
taggedFileGroups={sampleGroups}
|
||||
onConfirm={jest.fn()}
|
||||
onCancel={onCancel}
|
||||
/>
|
||||
);
|
||||
fireEvent.click(screen.getByRole('button', {name: /Cancel/i}));
|
||||
expect(onCancel).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls onConfirm when Delete button clicked', () => {
|
||||
const onConfirm = jest.fn();
|
||||
renderWithProviders(
|
||||
<TaggedDeleteConfirmModal
|
||||
open={true}
|
||||
taggedFileGroups={sampleGroups}
|
||||
onConfirm={onConfirm}
|
||||
onCancel={jest.fn()}
|
||||
/>
|
||||
);
|
||||
const deleteButton = screen.getAllByRole('button', {name: /Delete/i})
|
||||
.find(b => b.textContent.includes('Delete'));
|
||||
fireEvent.click(deleteButton);
|
||||
expect(onConfirm).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles empty/null taggedFileGroups gracefully', () => {
|
||||
renderWithProviders(
|
||||
<TaggedDeleteConfirmModal
|
||||
open={true}
|
||||
taggedFileGroups={null}
|
||||
onConfirm={jest.fn()}
|
||||
onCancel={jest.fn()}
|
||||
/>
|
||||
);
|
||||
expect(screen.getAllByText(/Tagged Files Will Be Deleted/i).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('falls back to name when primary_path is missing', () => {
|
||||
renderWithProviders(
|
||||
<TaggedDeleteConfirmModal
|
||||
open={true}
|
||||
taggedFileGroups={[{id: 5, name: 'fallback-name', tags: ['t']}]}
|
||||
onConfirm={jest.fn()}
|
||||
onCancel={jest.fn()}
|
||||
/>
|
||||
);
|
||||
expect(screen.getByText('fallback-name')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -26,6 +26,7 @@ import {Button, darkTheme, Header, Icon, Loader, Segment, Tab} from "./Theme";
|
|||
import {VideoCard} from "./Videos";
|
||||
import {TagsSelector} from "../Tags";
|
||||
import {Comment, CommentGroup, Input, Label, Transition} from "semantic-ui-react";
|
||||
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
||||
|
||||
const MEDIA_PATH = '/media';
|
||||
|
||||
|
|
@ -171,6 +172,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
|
||||
const navigate = useNavigate();
|
||||
const videoRef = React.useRef();
|
||||
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
||||
|
||||
useTitle(videoFile ? videoFile.title ? videoFile.title : videoFile.name : null);
|
||||
let video;
|
||||
|
|
@ -276,8 +278,12 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
return <PageContainer><Header as='h4'>Could not find video</Header></PageContainer>;
|
||||
}
|
||||
|
||||
const handleDeleteVideo = async (video_id) => {
|
||||
await deleteVideos([video_id])
|
||||
const handleDeleteVideo = async (video_id, force = false) => {
|
||||
const result = await deleteVideos([video_id], force);
|
||||
if (result && result.tagged) {
|
||||
setTaggedFileGroups(result.file_groups);
|
||||
return;
|
||||
}
|
||||
navigate(-1);
|
||||
}
|
||||
|
||||
|
|
@ -575,6 +581,15 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
|
||||
{prevNextVideosSegment}
|
||||
</Container>
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={async () => {
|
||||
setTaggedFileGroups(null);
|
||||
await handleDeleteVideo(videoFile.id, true);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
|||
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
||||
import {Button, Card, Header, Loader, Modal, Placeholder, Popup, Segment, Statistic} from "./Theme";
|
||||
import {BulkTagModal} from "./BulkTagModal";
|
||||
import {TaggedDeleteConfirmModal} from "./TaggedDeleteConfirmModal";
|
||||
import {
|
||||
deleteVideos,
|
||||
deleteCookies,
|
||||
|
|
@ -88,6 +89,7 @@ export function VideosPage() {
|
|||
const {searchParams} = React.useContext(QueryContext);
|
||||
const [selectedVideos, setSelectedVideos] = useState([]);
|
||||
const [bulkTagOpen, setBulkTagOpen] = useState(false);
|
||||
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
||||
const searchInputRef = React.useRef();
|
||||
|
||||
useHotkeys('f', (e) => {
|
||||
|
|
@ -156,9 +158,13 @@ export function VideosPage() {
|
|||
setSelectedVideos(newSelectedVideos);
|
||||
}
|
||||
|
||||
const onDelete = async () => {
|
||||
const onDelete = async (force = false) => {
|
||||
const fileGroupIds = videos.filter(i => selectedVideos.indexOf(i['primary_path']) >= 0).map(i => i['id']);
|
||||
await deleteVideos(fileGroupIds);
|
||||
const result = await deleteVideos(fileGroupIds, force);
|
||||
if (result && result.tagged) {
|
||||
setTaggedFileGroups(result.file_groups);
|
||||
return;
|
||||
}
|
||||
await fetchVideos();
|
||||
setSelectedVideos([]);
|
||||
}
|
||||
|
|
@ -189,7 +195,7 @@ export function VideosPage() {
|
|||
disabled={_.isEmpty(selectedVideos)}
|
||||
confirmButton='Delete'
|
||||
confirmContent='Are you sure you want to delete these video files? This cannot be undone.'
|
||||
onClick={onDelete}
|
||||
onClick={() => onDelete(false)}
|
||||
>Delete</APIButton>
|
||||
<Button
|
||||
color='grey'
|
||||
|
|
@ -265,6 +271,15 @@ export function VideosPage() {
|
|||
</Media>
|
||||
{body}
|
||||
{paginator}
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={async () => {
|
||||
setTaggedFileGroups(null);
|
||||
await onDelete(true);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import Message from 'semantic-ui-react/dist/commonjs/collections/Message';
|
|||
import {Button, Modal} from '../Theme';
|
||||
import {deleteArchives, deleteVideos} from '../../api';
|
||||
import {humanFileSize, isoDatetimeToString} from '../Common';
|
||||
import {TaggedDeleteConfirmModal} from '../TaggedDeleteConfirmModal';
|
||||
|
||||
/**
|
||||
* Card component for a single conflicting file.
|
||||
|
|
@ -28,16 +29,26 @@ import {humanFileSize, isoDatetimeToString} from '../Common';
|
|||
function ConflictFileCard({file, onDelete, isRecommended}) {
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const [localError, setLocalError] = useState(null);
|
||||
const [taggedFileGroups, setTaggedFileGroups] = useState(null);
|
||||
|
||||
const handleDelete = async () => {
|
||||
const performDelete = async (force) => {
|
||||
if (file.model_type === 'video' && file.file_group_id) {
|
||||
return await deleteVideos([file.file_group_id], force);
|
||||
} else if (file.model_type === 'archive' && file.archive_id) {
|
||||
return await deleteArchives([file.archive_id], force);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const handleDelete = async (force = false) => {
|
||||
setIsDeleting(true);
|
||||
setLocalError(null);
|
||||
|
||||
try {
|
||||
if (file.model_type === 'video' && file.file_group_id) {
|
||||
await deleteVideos([file.file_group_id]);
|
||||
} else if (file.model_type === 'archive' && file.archive_id) {
|
||||
await deleteArchives([file.archive_id]);
|
||||
const result = await performDelete(force);
|
||||
if (result && result.tagged) {
|
||||
setTaggedFileGroups(result.file_groups);
|
||||
return;
|
||||
}
|
||||
onDelete(file);
|
||||
} catch (err) {
|
||||
|
|
@ -125,7 +136,7 @@ function ConflictFileCard({file, onDelete, isRecommended}) {
|
|||
icon
|
||||
loading={isDeleting}
|
||||
disabled={isDeleting}
|
||||
onClick={handleDelete}
|
||||
onClick={() => handleDelete(false)}
|
||||
title='Delete this file'
|
||||
>
|
||||
<Icon name='trash'/>
|
||||
|
|
@ -134,6 +145,15 @@ function ConflictFileCard({file, onDelete, isRecommended}) {
|
|||
</Grid.Row>
|
||||
</Grid>
|
||||
</Card.Content>
|
||||
<TaggedDeleteConfirmModal
|
||||
open={taggedFileGroups !== null}
|
||||
taggedFileGroups={taggedFileGroups}
|
||||
onCancel={() => setTaggedFileGroups(null)}
|
||||
onConfirm={async () => {
|
||||
setTaggedFileGroups(null);
|
||||
await handleDelete(true);
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ describe('ConflictResolutionModal', () => {
|
|||
fireEvent.click(deleteButtons[0]);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(api.deleteVideos).toHaveBeenCalledWith([1]);
|
||||
expect(api.deleteVideos).toHaveBeenCalledWith([1], false);
|
||||
});
|
||||
|
||||
// File should be removed from UI (conflict resolved since only 1 file remains)
|
||||
|
|
@ -157,7 +157,7 @@ describe('ConflictResolutionModal', () => {
|
|||
fireEvent.click(deleteButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(api.deleteArchives).toHaveBeenCalledWith([201]);
|
||||
expect(api.deleteArchives).toHaveBeenCalledWith([201], false);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -318,6 +318,39 @@ describe('ConflictResolutionModal', () => {
|
|||
expect(screen.getByText(/Recommended to Keep/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows tagged-delete confirmation modal when API returns FILE_GROUP_IS_TAGGED', async () => {
|
||||
api.deleteVideos.mockResolvedValue({
|
||||
tagged: true,
|
||||
file_groups: [
|
||||
{id: 1, primary_path: 'unique-tagged-path-12345.mp4', tags: ['unique-tag-zxcv']},
|
||||
],
|
||||
});
|
||||
|
||||
renderWithProviders(<ConflictResolutionModal {...defaultProps} />);
|
||||
|
||||
const deleteButtons = screen.getAllByTitle('Delete this file');
|
||||
fireEvent.click(deleteButtons[0]);
|
||||
|
||||
// Wait for the secondary confirmation modal to appear (use unique path/tag to avoid
|
||||
// matching the parent ConflictResolutionModal's "Tagged" label).
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('unique-tagged-path-12345.mp4')).toBeInTheDocument();
|
||||
});
|
||||
expect(screen.getByText('unique-tag-zxcv')).toBeInTheDocument();
|
||||
|
||||
// Confirming should re-call deleteVideos with force=true.
|
||||
api.deleteVideos.mockResolvedValueOnce({});
|
||||
// The TaggedDeleteConfirmModal's Delete button has the trash icon.
|
||||
const confirmButton = screen.getAllByRole('button')
|
||||
.find(b => b.classList.contains('red') && b.textContent.includes('Delete')
|
||||
&& b.querySelector('.trash.icon'));
|
||||
fireEvent.click(confirmButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(api.deleteVideos).toHaveBeenLastCalledWith([1], true);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not show rank display for archives', () => {
|
||||
const archiveConflicts = [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue