From 8478fc722991d37c2e4204c612996440cb68c32a Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Sun, 29 Nov 2026 19:23:44 -0700 Subject: [PATCH] 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 --- app/src/components/Download.js | 23 +++++++++++++ app/src/components/Vars.js | 1 + app/src/components/admin/Downloads.js | 7 ++++ app/src/components/admin/Downloads.test.js | 38 ++++++++++++++++++++-- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/app/src/components/Download.js b/app/src/components/Download.js index a6bea126..887bbddd 100644 --- a/app/src/components/Download.js +++ b/app/src/components/Download.js @@ -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 +
Git Repo
+ + {orphaned + ? This download's Repo no longer exists. Delete this download to stop it. + : This download is managed by its Repo. Change it on the Repos page.} + + Delete + + +
+} + /** 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'; diff --git a/app/src/components/Vars.js b/app/src/components/Vars.js index 06ef47c4..6591cad5 100644 --- a/app/src/components/Vars.js +++ b/app/src/components/Vars.js @@ -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', diff --git a/app/src/components/admin/Downloads.js b/app/src/components/admin/Downloads.js index 98ec5ead..7b11b999 100644 --- a/app/src/components/admin/Downloads.js +++ b/app/src/components/admin/Downloads.js @@ -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 = ; } else if (downloader === Downloaders.ScrapeHtml) { editForm = { }); }); }); + +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( + + ); + + 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()); + }); +});