🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
fix(ui): prevent disabled Show in Playlist menu item from triggering actions (#4356)
Deluan Quintão445880c0065a
diff --git a/ui/src/common/SongContextMenu.jsx b/ui/src/common/SongContextMenu.jsxindex 32fbeb243..5eff495b3 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 && (<MenuItemvalue={key}key={key}- onClick={handleItemClick}- disabled={key === 'showInPlaylist' && !playlists.length}+ onClick={+ showInPlaylistDisabled+ ? (e) => e.stopPropagation()+ : handleItemClick+ }+ disabled={showInPlaylistDisabled}+ style={+ showInPlaylistDisabled ? { pointerEvents: 'auto' } : undefined+ }>{options[key].label}</MenuItem>- ),- )}+ )+ )+ })}</Menu><MenuanchorEl={playlistAnchorEl}diff --git a/ui/src/common/SongContextMenu.test.jsx b/ui/src/common/SongContextMenu.test.jsxindex ee6a358d8..a30da859f 100644--- a/ui/src/common/SongContextMenu.test.jsx+++ b/ui/src/common/SongContextMenu.test.jsx@@ -10,6 +10,8 @@ vi.mock('../dataProvider', () => ({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(+ <TestContext>+ <div onClick={mockOnClick}>+ <SongContextMenu record={{ id: 'song1', size: 1 }} resource="song" />+ </div>+ </TestContext>,+ )++ 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()+ })})