Commit 9e1c731b authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Update content-info banner to link to item

Update for changed `contentInfo` structure, including the separation of
`title` and `subtitle` into separate fields. Show subtitle for item
title but not container title.
parent b7ecd177
...@@ -2,6 +2,7 @@ import classnames from 'classnames'; ...@@ -2,6 +2,7 @@ import classnames from 'classnames';
import { import {
Link, Link,
LinkUnstyled,
CaretLeftIcon, CaretLeftIcon,
CaretRightIcon, CaretRightIcon,
} from '@hypothesis/frontend-shared/lib/next'; } from '@hypothesis/frontend-shared/lib/next';
...@@ -23,6 +24,10 @@ import { ...@@ -23,6 +24,10 @@ import {
* @param {ContentInfoConfig} props.info * @param {ContentInfoConfig} props.info
*/ */
export default function ContentInfoBanner({ info }) { export default function ContentInfoBanner({ info }) {
// Format item title to show subtitle
const itemTitle = `${info.item.title}${info.item.subtitle && ': '}${
info.item.subtitle
}`;
return ( return (
<div <div
className={classnames( className={classnames(
...@@ -52,9 +57,9 @@ export default function ContentInfoBanner({ info }) { ...@@ -52,9 +57,9 @@ export default function ContentInfoBanner({ info }) {
'font-semibold' 'font-semibold'
)} )}
data-testid="content-container-info" data-testid="content-container-info"
title={info.item.containerTitle} title={info.container.title}
> >
{info.item.containerTitle} {info.container.title}
</div> </div>
<div <div
className={classnames( className={classnames(
...@@ -97,9 +102,13 @@ export default function ContentInfoBanner({ info }) { ...@@ -97,9 +102,13 @@ export default function ContentInfoBanner({ info }) {
'min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium' 'min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium'
)} )}
> >
<span title={info.item.title} data-testid="content-item-title"> <LinkUnstyled
{info.item.title} title={itemTitle}
</span> href={info.links.currentItem}
data-testid="content-item-link"
>
{itemTitle}
</LinkUnstyled>
</div> </div>
{info.links.nextItem && ( {info.links.nextItem && (
......
...@@ -17,8 +17,13 @@ describe('ContentInfoBanner', () => { ...@@ -17,8 +17,13 @@ describe('ContentInfoBanner', () => {
}, },
item: { item: {
title: 'Chapter 2: Some book chapter', title: 'Chapter 2',
containerTitle: 'Expansive Book', subtitle: 'Some book chapter',
},
container: {
title: 'Expansive Book',
subtitle: 'The revenge',
}, },
links: { links: {
...@@ -41,9 +46,7 @@ describe('ContentInfoBanner', () => { ...@@ -41,9 +46,7 @@ describe('ContentInfoBanner', () => {
it('shows item title', () => { it('shows item title', () => {
const wrapper = createComponent(); const wrapper = createComponent();
// TODO: This should be a link once the item link is available in const title = wrapper.find('LinkUnstyled[data-testid="content-item-link"]');
// content-info metadata
const title = wrapper.find('span[data-testid="content-item-title"]');
assert.equal(title.text(), 'Chapter 2: Some book chapter'); assert.equal(title.text(), 'Chapter 2: Some book chapter');
}); });
...@@ -57,7 +60,9 @@ describe('ContentInfoBanner', () => { ...@@ -57,7 +60,9 @@ describe('ContentInfoBanner', () => {
'Expansive Book' 'Expansive Book'
); );
assert.equal( assert.equal(
wrapper.find('span[data-testid="content-item-title"]').prop('title'), wrapper
.find('LinkUnstyled[data-testid="content-item-link"]')
.prop('title'),
'Chapter 2: Some book chapter' 'Chapter 2: Some book chapter'
); );
}); });
......
...@@ -228,7 +228,9 @@ describe('annotator/integrations/pdf', () => { ...@@ -228,7 +228,9 @@ describe('annotator/integrations/pdf', () => {
}, },
item: { item: {
title: 'Chapter 2: A chapter', title: 'Chapter 2: A chapter',
containerTitle: 'Book Title Here', },
container: {
title: 'Book Title Here',
}, },
links: { links: {
previousItem: 'https://jstor.org/stable/book123.1', previousItem: 'https://jstor.org/stable/book123.1',
......
...@@ -201,8 +201,7 @@ ...@@ -201,8 +201,7 @@
* *
* @typedef ContentInfoItem * @typedef ContentInfoItem
* @prop {string} title - Title of the current article, chapter etc. * @prop {string} title - Title of the current article, chapter etc.
* @prop {string} containerTitle - Title of the journal issue, book etc. which * @prop {string} [subtitle]
* contains the current work
*/ */
/** /**
...@@ -211,6 +210,7 @@ ...@@ -211,6 +210,7 @@
* @typedef ContentInfoLinks * @typedef ContentInfoLinks
* @prop {string} [previousItem] - Previous item in the book, journal etc. * @prop {string} [previousItem] - Previous item in the book, journal etc.
* @prop {string} [nextItem] - Next item in the book, journal etc. * @prop {string} [nextItem] - Next item in the book, journal etc.
* @prop {string} currentItem - This item in the content provider's context
*/ */
/** /**
...@@ -222,7 +222,9 @@ ...@@ -222,7 +222,9 @@
* *
* @typedef {object} ContentInfoConfig * @typedef {object} ContentInfoConfig
* @prop {ContentInfoLogo} logo - Logo of the content provider * @prop {ContentInfoLogo} logo - Logo of the content provider
* @prop {ContentInfoItem} item * @prop {ContentInfoItem} item - Metadata about the current content item
* @prop {ContentInfoItem} container - Metadata about the container (journal or
* book, e.g.) the current `item` is part of
* @prop {ContentInfoLinks} links * @prop {ContentInfoLinks} links
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment