mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Downloads: an edit form for Git downloads, so an orphaned one can be deleted (#1035)
A Git download's edit modal was empty, so a Git download left behind by a deleted Repo could not be deleted. The form shows the URL, says whether the Repo still owns it, and has Delete and Cancel. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d34b2a7088
commit
8478fc7229
4 changed files with 67 additions and 2 deletions
|
|
@ -1767,6 +1767,29 @@ export function EditScrapeFilesDownloadForm({download, onDelete, onCancel, onSuc
|
|||
/>
|
||||
}
|
||||
|
||||
/** A Git Download is created and changed by its Repo, so it can only be deleted here (e.g. after its Repo was
|
||||
* deleted but the Download was not). */
|
||||
export function EditGitDownloadForm({download, onDelete, onCancel}) {
|
||||
const orphaned = !download.collection_id;
|
||||
return <Stack gap='md'>
|
||||
<Header as='h3'>Git Repo</Header>
|
||||
<TextInput label='URL' value={download.url} readOnly/>
|
||||
{orphaned
|
||||
? <Message>This download's Repo no longer exists. Delete this download to stop it.</Message>
|
||||
: <Message>This download is managed by its Repo. Change it on the <Link to='/repos'>Repos</Link> page.</Message>}
|
||||
<Group justify='space-between' mt='sm'>
|
||||
<APIButton
|
||||
role='danger'
|
||||
confirmButton='Delete'
|
||||
confirmContent='Delete this Download?'
|
||||
confirmHeader='Delete'
|
||||
onClick={onDelete}
|
||||
>Delete</APIButton>
|
||||
<Button role='cancel' onClick={onCancel}>Cancel</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
}
|
||||
|
||||
/** URL field for a single URL. */
|
||||
function UrlField({form, required = true, name = 'url', path = 'url', disabled = false}) {
|
||||
const validator = (i) => validURL(i) ? null : 'Invalid URL';
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@ export function audioContainerForCodec(codec) {
|
|||
export const Downloaders = {
|
||||
Archive: 'archive',
|
||||
File: 'file',
|
||||
Git: 'git',
|
||||
Torrent: 'torrent',
|
||||
KiwixCatalog: 'kiwix_catalog',
|
||||
KiwixZim: 'kiwix_zim',
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import {useDownloads} from "../../hooks/customHooks";
|
|||
import {
|
||||
EditArchiveDownloadForm,
|
||||
EditChannelDownloadForm,
|
||||
EditGitDownloadForm,
|
||||
EditRSSDownloadForm,
|
||||
EditScrapeFilesDownloadForm,
|
||||
EditVideosDownloadForm,
|
||||
|
|
@ -310,6 +311,12 @@ function RecurringDownloadRow({download, fetchDownloads, onDelete}) {
|
|||
onCancel={handleEditClose}
|
||||
onSuccess={onSuccess}
|
||||
/>;
|
||||
} else if (downloader === Downloaders.Git) {
|
||||
editForm = <EditGitDownloadForm
|
||||
download={download}
|
||||
onDelete={localOnDelete}
|
||||
onCancel={handleEditClose}
|
||||
/>;
|
||||
} else if (downloader === Downloaders.ScrapeHtml) {
|
||||
editForm = <EditScrapeFilesDownloadForm
|
||||
download={download}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import {fireEvent, screen, waitFor} from '@testing-library/react';
|
||||
import {OnceDownloadsTable} from './Downloads';
|
||||
import {act, fireEvent, screen, waitFor} from '@testing-library/react';
|
||||
import {OnceDownloadsTable, RecurringDownloadsTable} from './Downloads';
|
||||
import {renderWithProviders} from '../../test-utils';
|
||||
|
||||
// Mock the API functions
|
||||
|
|
@ -21,6 +21,7 @@ import {
|
|||
batchDeleteDownloads,
|
||||
batchRetryDownloads,
|
||||
clearCompletedDownloads,
|
||||
deleteDownload,
|
||||
deleteOnceDownloads,
|
||||
retryOnceDownloads,
|
||||
} from '../../api';
|
||||
|
|
@ -167,3 +168,36 @@ describe('OnceDownloadsTable', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('RecurringDownloadsTable', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('a Git download whose Repo was deleted can be deleted from its edit form', async () => {
|
||||
const fetchDownloads = jest.fn();
|
||||
const onDelete = jest.fn();
|
||||
const downloads = [{
|
||||
id: 16, url: 'https://example.com/repo', downloader: 'git', frequency: 604800, status: 'deferred',
|
||||
collection_id: null,
|
||||
}];
|
||||
renderWithProviders(
|
||||
<RecurringDownloadsTable downloads={downloads} fetchDownloads={fetchDownloads} onDelete={onDelete}/>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByLabelText('Edit download'));
|
||||
expect(await screen.findByText(/Repo no longer exists/))
|
||||
.toBeInTheDocument();
|
||||
expect(screen.getByDisplayValue('https://example.com/repo')).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', {name: 'Delete'}));
|
||||
// Confirm the deletion.
|
||||
await screen.findByText('Delete this Download?');
|
||||
const deleteButtons = screen.getAllByRole('button', {name: 'Delete'});
|
||||
expect(deleteButtons.length).toBeGreaterThan(1);
|
||||
await act(async () => fireEvent.click(deleteButtons[deleteButtons.length - 1]));
|
||||
|
||||
await waitFor(() => expect(deleteDownload).toHaveBeenCalledWith(16));
|
||||
await waitFor(() => expect(onDelete).toHaveBeenCalled());
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue