diff --git a/ui/src/common/ArtistLinkField.jsx b/ui/src/common/ArtistLinkField.jsx index d41b47b06..e9d17801d 100644 --- a/ui/src/common/ArtistLinkField.jsx +++ b/ui/src/common/ArtistLinkField.jsx @@ -12,6 +12,10 @@ const ALink = withWidth()((props) => { const artistLink = useGetHandleArtistClick(width) const dispatch = useDispatch() + const displayName = artist.creditedAs || artist.name + const showCanonicalTooltip = + artist.creditedAs && artist.creditedAs !== artist.name + return ( { e.stopPropagation() dispatch(closeExtendedInfoDialog()) }} + title={showCanonicalTooltip ? artist.name : undefined} {...rest} > - {artist.name} + {displayName} {artist.subroles?.length > 0 ? ` (${artist.subroles.join(', ')})` : ''} ) @@ -37,7 +42,8 @@ const parseAndReplaceArtists = ( let lastIndex = 0 albumArtists?.forEach((artist) => { - const index = displayAlbumArtist.indexOf(artist.name, lastIndex) + const matchName = artist.creditedAs || artist.name + const index = displayAlbumArtist.indexOf(matchName, lastIndex) if (index !== -1) { // Add text before the artist name if (index > lastIndex) { @@ -47,7 +53,7 @@ const parseAndReplaceArtists = ( result.push( , ) - lastIndex = index + artist.name.length + lastIndex = index + matchName.length } }) diff --git a/ui/src/common/ArtistLinkField.test.jsx b/ui/src/common/ArtistLinkField.test.jsx index 09fdf64a4..e49873930 100644 --- a/ui/src/common/ArtistLinkField.test.jsx +++ b/ui/src/common/ArtistLinkField.test.jsx @@ -213,6 +213,81 @@ describe('ArtistLinkField', () => { }) }) + describe('creditedAs', () => { + it('renders creditedAs as the link text when present', () => { + const record = { + artist: 'PAS', + participants: { + artist: [ + { + id: 'canon-1', + name: 'Planetary Assault Systems', + creditedAs: 'PAS', + }, + ], + }, + } + + render() + + expect(screen.getByText('PAS')).toBeInTheDocument() + expect( + screen.queryByText('Planetary Assault Systems'), + ).not.toBeInTheDocument() + }) + + it('sets a title tooltip with the canonical name when creditedAs differs', () => { + const record = { + artist: 'PAS', + participants: { + artist: [ + { + id: 'canon-1', + name: 'Planetary Assault Systems', + creditedAs: 'PAS', + }, + ], + }, + } + + render() + + const link = screen.getByRole('link') + expect(link).toHaveAttribute('title', 'Planetary Assault Systems') + }) + + it('falls back to name when creditedAs is missing', () => { + const record = { + artist: 'Some Artist', + participants: { + artist: [{ id: 'canon-2', name: 'Some Artist' }], + }, + } + + render() + + expect(screen.getByText('Some Artist')).toBeInTheDocument() + const link = screen.getByRole('link') + expect(link).not.toHaveAttribute('title') + }) + + it('does not set a tooltip when creditedAs equals name', () => { + const record = { + artist: 'Same Name', + participants: { + artist: [ + { id: 'canon-3', name: 'Same Name', creditedAs: 'Same Name' }, + ], + }, + } + + render() + + const link = screen.getByRole('link') + expect(link).not.toHaveAttribute('title') + }) + }) + describe('when limiting displayed artists', () => { it('limits the number of artists displayed', () => { const record = {