-
Notifications
You must be signed in to change notification settings - Fork 272
WS-TRANSCRIPT: Adds transcript component #13716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: latest
Are you sure you want to change the base?
Changes from all commits
476e3d9
98d5742
df1812f
822b0bc
20bc8a7
b805ad3
eca7454
bb46140
0065a3b
2aa6979
295ea40
4fbe6ac
b6a31d9
4734a33
d37e755
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { aresMediaBlockWithTranscript } from '../../fixture'; | ||
| import getTitleForLiteSiteTranscriptBlock from '.'; | ||
| import { MediaBlock } from '../../types'; | ||
|
|
||
| describe('getTitleForLiteSiteTranscriptBlock', () => { | ||
| it('should return the title from aresMediaMetadata block', () => { | ||
| const result = getTitleForLiteSiteTranscriptBlock( | ||
| aresMediaBlockWithTranscript as MediaBlock[], | ||
| ); | ||
| expect(result).toBe('Five things ants can teach us about management'); | ||
| }); | ||
|
|
||
| it('should return empty string if aresMedia block is missing', () => { | ||
| const result = getTitleForLiteSiteTranscriptBlock([]); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should return empty string if aresMediaMetadata block is missing', () => { | ||
| const blockMissingAresMediaMetadata = [ | ||
| { | ||
| ...aresMediaBlockWithTranscript, | ||
| model: { | ||
| blocks: [ | ||
| { | ||
| type: 'aresMedia', | ||
| model: { blocks: [] }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| const result = getTitleForLiteSiteTranscriptBlock( | ||
| // @ts-expect-error - partial data | ||
| blockMissingAresMediaMetadata, | ||
| ); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should return empty string if title is missing', () => { | ||
| const blockMissingTitle = [ | ||
| { | ||
| ...aresMediaBlockWithTranscript, | ||
| model: { | ||
| blocks: [ | ||
| { | ||
| type: 'aresMedia', | ||
| model: { | ||
| blocks: [ | ||
| { | ||
| type: 'aresMediaMetadata', | ||
| model: {}, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| // @ts-expect-error - partial data | ||
| const result = getTitleForLiteSiteTranscriptBlock(blockMissingTitle); | ||
| expect(result).toBe(''); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import filterForBlockType from '#app/lib/utilities/blockHandlers'; | ||
| import { | ||
| AresMediaBlock, | ||
| AresMediaMetadataBlock, | ||
| MediaBlock, | ||
| } from '../../types'; | ||
|
|
||
| export default (blocks: MediaBlock[]) => { | ||
| const { model: aresMedia }: AresMediaBlock = | ||
| filterForBlockType(blocks, 'aresMedia') ?? {}; | ||
|
|
||
| const { model: aresMediaMetadata }: AresMediaMetadataBlock = | ||
| filterForBlockType(aresMedia?.blocks, 'aresMediaMetadata') ?? {}; | ||
|
|
||
| const title = aresMediaMetadata?.title ?? ''; | ||
|
|
||
| return title; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { aresMediaBlockWithTranscript, aresMediaBlocks } from '../../fixture'; | ||
| import { MediaBlock } from '../../types'; | ||
| import getTranscriptBlock from '.'; | ||
| import TranscriptBlock from '../../../Transcript/fixture.json'; | ||
|
|
||
| describe('getTranscriptBlock', () => { | ||
| it('Should return a valid transcript block for an AresMedia block for an article page.', () => { | ||
| const result = getTranscriptBlock( | ||
| aresMediaBlockWithTranscript as MediaBlock[], | ||
| ); | ||
|
|
||
| expect(result).toStrictEqual(TranscriptBlock); | ||
| }); | ||
|
|
||
| it('Should return null if no transcript block is present.', () => { | ||
| const result = getTranscriptBlock(aresMediaBlocks as MediaBlock[]); | ||
|
|
||
| expect(result).toStrictEqual(null); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import filterForBlockType from '#app/lib/utilities/blockHandlers'; | ||
| import { MediaBlock } from '../../types'; | ||
| import { TranscriptBlock } from '../../../Transcript/types'; | ||
|
|
||
| export default function getTranscriptBlock( | ||
| blocks: MediaBlock[], | ||
| ): TranscriptBlock | null { | ||
| const transcriptBlock: TranscriptBlock = filterForBlockType( | ||
| blocks, | ||
| 'transcript', | ||
| ); | ||
|
|
||
| if (!transcriptBlock) return null; | ||
|
|
||
| return transcriptBlock; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||
| ## Description | ||||||
|
|
||||||
| The `Transcript` component renders video transcripts. | ||||||
|
|
||||||
| ## Props | ||||||
|
|
||||||
| | Name | type | Description | | ||||||
| | ---------- | ------ | --------------------------- | | ||||||
| | transcript | object | contains transcript content | | ||||||
| | title | string | title of video | | ||||||
|
|
||||||
| ## Example | ||||||
|
|
||||||
| ```tsx | ||||||
| <Transcript transcript={transcriptBlock} title={mediaTitle} hideDisclaimer /> | ||||||
|
||||||
| <Transcript transcript={transcriptBlock} title={mediaTitle} hideDisclaimer /> | |
| <Transcript transcript={transcriptBlock} title={mediaTitle} /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { css, Theme } from '@emotion/react'; | ||
|
|
||
| const styles = { | ||
| time: ({ mq }: Theme) => | ||
| css({ | ||
| float: 'inline-start', | ||
| width: '100%', | ||
| [mq.GROUP_1_MIN_WIDTH]: { | ||
| width: 'auto', | ||
| }, | ||
| }), | ||
| }; | ||
|
|
||
| export default styles; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import styles from './index.styles'; | ||
|
|
||
| // using span not time element to prevent text splitting bug on Talkback | ||
| export default ({ timestamp }: { timestamp: string }) => { | ||
| return <span css={styles.time}>{timestamp}</span>; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TranscriptBlockis being added toAresMediaBlock['model']['blocks'], but in the Ares/Optimo data shape thetranscriptblock is a sibling of thearesMediablock (not nested inside it). To keep types accurate, addTranscriptBlockto theMediaBlockunion instead (and keepAresMediaBlock.model.blockslimited to its actual child block types).