From 2ae6defbc487adce81ddc5d5dc5731b3f2d3135f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Mon, 16 Nov 2026 00:25:15 -0500 Subject: [PATCH] refactor(ui): point lint at useDirectDataProvider and simplify uploadImage args (#6482) --- ui/.eslintrc | 4 +- ui/src/common/ImageUploadOverlay.jsx | 2 +- .../useDirectDataProvider.test.jsx | 6 +- ui/src/dataProvider/wrapperDataProvider.js | 3 +- .../dataProvider/wrapperDataProvider.test.js | 56 +------------------ 5 files changed, 8 insertions(+), 63 deletions(-) diff --git a/ui/.eslintrc b/ui/.eslintrc index b1135e43b..c0ad40ad5 100644 --- a/ui/.eslintrc +++ b/ui/.eslintrc @@ -53,11 +53,11 @@ { "group": ["**/dataProvider"], "importNames": ["httpClient"], - "message": "Do not call httpClient directly. Add a method to wrapperDataProvider and call it through useDataProvider(), or add the Subsonic call to src/subsonic." + "message": "Do not call httpClient directly. Add a method to wrapperDataProvider and call it through useDirectDataProvider(), or add the Subsonic call to src/subsonic." }, { "group": ["**/dataProvider/httpClient"], - "message": "Do not call httpClient directly. Add a method to wrapperDataProvider and call it through useDataProvider(), or add the Subsonic call to src/subsonic." + "message": "Do not call httpClient directly. Add a method to wrapperDataProvider and call it through useDirectDataProvider(), or add the Subsonic call to src/subsonic." } ] } diff --git a/ui/src/common/ImageUploadOverlay.jsx b/ui/src/common/ImageUploadOverlay.jsx index 6cd1d1270..7b15d4d0e 100644 --- a/ui/src/common/ImageUploadOverlay.jsx +++ b/ui/src/common/ImageUploadOverlay.jsx @@ -64,7 +64,7 @@ export const ImageUploadOverlay = ({ if (!file || !entityId) return try { - await dataProvider.uploadImage(entityType, { id: entityId, file }) + await dataProvider.uploadImage(entityType, entityId, file) notify(`message.coverUploaded`, 'success') if (onImageChange) onImageChange() refresh() diff --git a/ui/src/dataProvider/useDirectDataProvider.test.jsx b/ui/src/dataProvider/useDirectDataProvider.test.jsx index 196ac34c1..201f58d37 100644 --- a/ui/src/dataProvider/useDirectDataProvider.test.jsx +++ b/ui/src/dataProvider/useDirectDataProvider.test.jsx @@ -46,8 +46,8 @@ describe('useDirectDataProvider', () => { const provider = { uploadImage: vi.fn().mockRejectedValue(error) } const { result } = renderWithOptimistic(provider, false) - await expect( - result.current.uploadImage('playlist', { id: 'pl-1' }), - ).rejects.toBe(error) + await expect(result.current.uploadImage('playlist', 'pl-1')).rejects.toBe( + error, + ) }) }) diff --git a/ui/src/dataProvider/wrapperDataProvider.js b/ui/src/dataProvider/wrapperDataProvider.js index d9dbf00a1..d0ef79a98 100644 --- a/ui/src/dataProvider/wrapperDataProvider.js +++ b/ui/src/dataProvider/wrapperDataProvider.js @@ -239,8 +239,7 @@ const wrapperDataProvider = { httpClient(`${REST_URL}/metadata/${REFRESH_KIND[resource]}/${id}/refresh`, { method: 'POST', }).then(() => ({ data: { id } })), - // useDataProvider forwards only two arguments when the first is a string, so id and file share one. - uploadImage: (resource, { id, file }) => { + uploadImage: (resource, id, file) => { const formData = new FormData() formData.append('image', file) return fetchData(`${REST_URL}/${resource}/${id}/image`, { diff --git a/ui/src/dataProvider/wrapperDataProvider.test.js b/ui/src/dataProvider/wrapperDataProvider.test.js index 2d2727e4d..eb3f7f491 100644 --- a/ui/src/dataProvider/wrapperDataProvider.test.js +++ b/ui/src/dataProvider/wrapperDataProvider.test.js @@ -140,23 +140,13 @@ describe('wrapperDataProvider', () => { it('posts the file as multipart form data under the image field', async () => { const file = new File(['img'], 'cover.png', { type: 'image/png' }) - await wrapperDataProvider.uploadImage('artist', { id: 'ar-1', file }) + await wrapperDataProvider.uploadImage('artist', 'ar-1', file) const [url, options] = mockHttpClient.mock.calls[0] expect(url).toBe('/api/artist/ar-1/image') expect(options.method).toBe('POST') expect(options.body).toBeInstanceOf(FormData) expect(options.body.get('image')).toBe(file) - // An empty Headers keeps httpClient from forcing a JSON content type over the multipart boundary - expect([...options.headers.keys()]).toEqual([]) - }) - - it('deletes the uploaded image', async () => { - await wrapperDataProvider.deleteImage('playlist', 'pl-1') - - expect(mockHttpClient).toHaveBeenCalledWith('/api/playlist/pl-1/image', { - method: 'DELETE', - }) }) }) @@ -184,32 +174,6 @@ describe('wrapperDataProvider', () => { }) describe('scrobbler links', () => { - it('reads the Last.fm link status', async () => { - mockHttpClient.mockResolvedValue({ json: { status: true, apiKey: 'k' } }) - - const result = await wrapperDataProvider.getLastfmLink() - - expect(mockHttpClient).toHaveBeenCalledWith('/api/lastfm/link') - expect(result).toEqual({ data: { status: true, apiKey: 'k' } }) - }) - - it('unlinks Last.fm', async () => { - await wrapperDataProvider.unlinkLastfm() - - expect(mockHttpClient).toHaveBeenCalledWith('/api/lastfm/link', { - method: 'DELETE', - }) - }) - - it('reads the ListenBrainz link status', async () => { - mockHttpClient.mockResolvedValue({ json: { status: false } }) - - const result = await wrapperDataProvider.getListenBrainzLink() - - expect(mockHttpClient).toHaveBeenCalledWith('/api/listenbrainz/link') - expect(result).toEqual({ data: { status: false } }) - }) - it('links ListenBrainz with the given token', async () => { mockHttpClient.mockResolvedValue({ json: { user: 'sam' } }) @@ -221,23 +185,5 @@ describe('wrapperDataProvider', () => { }) expect(result).toEqual({ data: { user: 'sam' } }) }) - - it('unlinks ListenBrainz', async () => { - await wrapperDataProvider.unlinkListenBrainz() - - expect(mockHttpClient).toHaveBeenCalledWith('/api/listenbrainz/link', { - method: 'DELETE', - }) - }) - }) - - describe('rescanPlugins', () => { - it('posts to the plugin rescan endpoint', async () => { - await wrapperDataProvider.rescanPlugins() - - expect(mockHttpClient).toHaveBeenCalledWith('/api/plugin/rescan', { - method: 'POST', - }) - }) }) })