Better handling of album comments (#1013)
* Change album comment behaviour * Don't check first item * Fix previously imported album comments. * Remove song comments if album comment is present
This commit is contained in:
@@ -40,6 +40,7 @@ const AlbumShowLayout = (props) => {
|
||||
<AlbumSongs
|
||||
resource={'albumSong'}
|
||||
exporter={false}
|
||||
album={record}
|
||||
actions={
|
||||
<AlbumActions className={classes.albumActions} record={record} />
|
||||
}
|
||||
|
||||
@@ -157,7 +157,17 @@ const AlbumSongs = (props) => {
|
||||
)
|
||||
}
|
||||
|
||||
export const removeAlbumCommentsFromSongs = ({ album, data }) => {
|
||||
if (album?.comment && data) {
|
||||
Object.values(data).forEach((song) => {
|
||||
song.comment = ''
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const SanitizedAlbumSongs = (props) => {
|
||||
removeAlbumCommentsFromSongs(props)
|
||||
|
||||
const { loaded, loading, total, ...rest } = useListContext(props)
|
||||
return <>{loaded && <AlbumSongs {...rest} actions={props.actions} />}</>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { removeAlbumCommentsFromSongs } from './AlbumSongs'
|
||||
|
||||
describe('removeAlbumCommentsFromSongs', () => {
|
||||
const data = { 1: { comment: 'one' }, 2: { comment: 'two' } }
|
||||
it('does not remove song comments if album does not have comment', () => {
|
||||
const album = { comment: '' }
|
||||
removeAlbumCommentsFromSongs({ album, data })
|
||||
expect(data['1'].comment).toEqual('one')
|
||||
expect(data['2'].comment).toEqual('two')
|
||||
})
|
||||
|
||||
it('removes song comments if album has comment', () => {
|
||||
const album = { comment: 'test' }
|
||||
removeAlbumCommentsFromSongs({ album, data })
|
||||
expect(data['1'].comment).toEqual('')
|
||||
expect(data['2'].comment).toEqual('')
|
||||
})
|
||||
|
||||
it('does not crash if album and data arr not available', () => {
|
||||
expect(() => {
|
||||
removeAlbumCommentsFromSongs({})
|
||||
}).not.toThrow()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user