diff --git a/ui/src/common/SongContextMenu.jsx b/ui/src/common/SongContextMenu.jsx index 32fbeb24..5eff495b 100644 --- a/ui/src/common/SongContextMenu.jsx +++ b/ui/src/common/SongContextMenu.jsx @@ -31,6 +31,9 @@ const useStyles = makeStyles({ noWrap: { whiteSpace: 'nowrap', }, + disabledMenuItem: { + pointerEvents: 'auto', + }, }) const MoreButton = ({ record, onClick, info }) => { @@ -233,19 +236,29 @@ export const SongContextMenu = ({ open={open} onClose={handleMainMenuClose} > - {Object.keys(options).map( - (key) => + {Object.keys(options).map((key) => { + const showInPlaylistDisabled = + key === 'showInPlaylist' && !playlists.length + return ( options[key].enabled && ( e.stopPropagation() + : handleItemClick + } + disabled={showInPlaylistDisabled} + style={ + showInPlaylistDisabled ? { pointerEvents: 'auto' } : undefined + } > {options[key].label} - ), - )} + ) + ) + })} ({ vi.mock('react-redux', () => ({ useDispatch: () => vi.fn() })) +const getPlaylistsMock = vi.fn() + vi.mock('react-admin', async (importOriginal) => { const actual = await importOriginal() return { @@ -18,9 +20,7 @@ vi.mock('react-admin', async (importOriginal) => { window.location.hash = `#${url}` }, useDataProvider: () => ({ - getPlaylists: vi.fn().mockResolvedValue({ - data: [{ id: 'pl1', name: 'Pl 1' }], - }), + getPlaylists: getPlaylistsMock, inspect: vi.fn().mockResolvedValue({ data: { rawTags: {} }, }), @@ -32,6 +32,9 @@ describe('SongContextMenu', () => { beforeEach(() => { vi.clearAllMocks() window.location.hash = '' + getPlaylistsMock.mockResolvedValue({ + data: [{ id: 'pl1', name: 'Pl 1' }], + }) }) it('navigates to playlist when selected', async () => { @@ -79,4 +82,26 @@ describe('SongContextMenu', () => { expect(mockOnClick).not.toHaveBeenCalled() }) + + it('does nothing when "Show in Playlist" is disabled', async () => { + getPlaylistsMock.mockResolvedValue({ data: [] }) + const mockOnClick = vi.fn() + render( + +
+ +
+
, + ) + + fireEvent.click(screen.getAllByRole('button')[1]) + await waitFor(() => + screen.getByText(/resources\.song\.actions\.showInPlaylist/), + ) + + fireEvent.click( + screen.getByText(/resources\.song\.actions\.showInPlaylist/), + ) + expect(mockOnClick).not.toHaveBeenCalled() + }) })