Skip to content

Commit

Permalink
refactor: delete getTranscriptDownloadUrlV2 and add it to getTranscri…
Browse files Browse the repository at this point in the history
…ptDownloadUrl
  • Loading branch information
ChrisChV committed Jan 29, 2025
1 parent 4961e73 commit 91b4a9d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@ const TranscriptActionMenu = ({
launchDeleteConfirmation,
// redux
getTranscriptDownloadUrl,
getTranscriptDownloadUrlV2,
buildTranscriptUrl,
isLibrary,
}) => {
const input = fileInput({ onAddFile: module.hooks.replaceFileCallback({ language, dispatch: useDispatch() }) });
let downloadLink;
if (isLibrary) {
downloadLink = getTranscriptDownloadUrlV2({ language });
} else {
downloadLink = transcriptUrl ? buildTranscriptUrl({ transcriptUrl }) : getTranscriptDownloadUrl({ language });
}
const downloadLink = transcriptUrl ? buildTranscriptUrl({ transcriptUrl }) : getTranscriptDownloadUrl({ language });
return (
<Dropdown>
<Dropdown.Toggle
Expand Down Expand Up @@ -84,16 +77,12 @@ TranscriptActionMenu.propTypes = {
launchDeleteConfirmation: PropTypes.func.isRequired,
// redux
getTranscriptDownloadUrl: PropTypes.func.isRequired,
getTranscriptDownloadUrlV2: PropTypes.func.isRequired,
buildTranscriptUrl: PropTypes.func.isRequired,
isLibrary: PropTypes.bool.isRequired,
};

export const mapStateToProps = (state) => ({
getTranscriptDownloadUrl: selectors.video.getTranscriptDownloadUrl(state),
getTranscriptDownloadUrlV2: selectors.video.getTranscriptDownloadUrlV2(state),
buildTranscriptUrl: selectors.video.buildTranscriptUrl(state),
isLibrary: selectors.app.isLibrary(state),
});

export const mapDispatchToProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jest.mock('../../../../../../data/redux', () => ({
},
video: {
getTranscriptDownloadUrl: jest.fn(args => ({ getTranscriptDownloadUrl: args })).mockName('selectors.video.getTranscriptDownloadUrl'),
getTranscriptDownloadUrlV2: jest.fn(args => ({ getTranscriptDownloadUrlV2: args })).mockName('selectors.video.getTranscriptDownloadUrlV2'),
buildTranscriptUrl: jest.fn(args => ({ buildTranscriptUrl: args })).mockName('selectors.video.buildTranscriptUrl'),
},
},
Expand Down Expand Up @@ -70,9 +69,7 @@ describe('TranscriptActionMenu', () => {
launchDeleteConfirmation: jest.fn().mockName('launchDeleteConfirmation'),
// redux
getTranscriptDownloadUrl: jest.fn().mockName('selectors.video.getTranscriptDownloadUrl'),
getTranscriptDownloadUrlV2: jest.fn().mockName('selectors.video.getTranscriptDownloadUrlV2'),
buildTranscriptUrl: jest.fn().mockName('selectors.video.buildTranscriptUrl'),
isLibrary: false,
};
afterAll(() => {
jest.clearAllMocks();
Expand All @@ -89,12 +86,6 @@ describe('TranscriptActionMenu', () => {
shallow(<TranscriptActionMenu {...props} transcriptUrl="url" />).snapshot,
).toMatchSnapshot();
});
test('snapshots: renders as expected with isLibrary props: dont show confirm delete', () => {
jest.spyOn(module.hooks, 'replaceFileCallback').mockImplementationOnce(() => jest.fn().mockName('module.hooks.replaceFileCallback'));
expect(
shallow(<TranscriptActionMenu {...props} isLibrary />).snapshot,
).toMatchSnapshot();
});
});
describe('mapStateToProps', () => {
const testState = { A: 'pple', B: 'anana', C: 'ucumber' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,60 +54,6 @@ exports[`TranscriptActionMenu Snapshots snapshots: renders as expected with defa
</Dropdown>
`;

exports[`TranscriptActionMenu Snapshots snapshots: renders as expected with isLibrary props: dont show confirm delete 1`] = `
<Dropdown>
<Dropdown.Toggle
alt="Actions dropdown"
as="IconButton"
iconAs="Icon"
id="dropdown-toggle-with-iconbutton-video-transcript-widget"
variant="primary"
/>
<Dropdown.Menu
className="video_transcript Action Menu"
>
<Dropdown.Item
key="transcript-actions-sOmenUmBer-replace"
onClick={[MockFunction click input]}
>
<FormattedMessage
defaultMessage="Replace"
description="Message Presented To user for action to replace transcript"
id="authoring.videoeditor.transcript.replaceTranscript"
/>
</Dropdown.Item>
<Dropdown.Item
key="transcript-actions-sOmenUmBer-download"
>
<FormattedMessage
defaultMessage="Download"
description="Message Presented To user for action to download transcript"
id="authoring.videoeditor.transcript.downloadTranscript"
/>
</Dropdown.Item>
<Dropdown.Item
key="transcript-actions-sOmenUmBer-delete"
onClick={[MockFunction launchDeleteConfirmation]}
>
<FormattedMessage
defaultMessage="Delete"
description="Message Presented To user for action to delete transcript"
id="authoring.videoeditor.transcript.deleteTranscript"
/>
</Dropdown.Item>
</Dropdown.Menu>
<FileInput
acceptedFiles=".srt"
fileInput={
{
"click": [MockFunction click input],
"onAddFile": [MockFunction module.hooks.replaceFileCallback],
}
}
/>
</Dropdown>
`;

exports[`TranscriptActionMenu Snapshots snapshots: renders as expected with transcriptUrl props: dont show confirm delete 1`] = `
<Dropdown>
<Dropdown.Toggle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,124 @@ exports[`TranscriptWidget component snapshots snapshot: renders ErrorAlert with
</CollapsibleFormWidget>
`;

exports[`TranscriptWidget component snapshots snapshot: renders when isLibrary is true 1`] = `undefined`;
exports[`TranscriptWidget component snapshots snapshot: renders when isLibrary is true 1`] = `
<CollapsibleFormWidget
fontSize="x-small"
isError={true}
subtitle="English"
title="Transcripts"
>
<ErrorAlert
dismissError={null}
hideHeading={true}
isError={false}
>
<FormattedMessage
defaultMessage="Failed to upload transcript. Please try again."
description="Message presented to user when transcript fails to upload"
id="authoring.videoeditor.transcript.error.uploadTranscriptError"
/>
</ErrorAlert>
<ErrorAlert
dismissError={null}
hideHeading={true}
isError={true}
>
<FormattedMessage
defaultMessage="Failed to delete transcript. Please try again."
description="Message presented to user when transcript fails to delete"
id="authoring.videoeditor.transcript.error.deleteTranscriptError"
/>
</ErrorAlert>
<Stack
gap={3}
>
<Form.Group
className="border-primary-100 border-bottom"
>
<Transcript
index={0}
language="en"
/>
<ActionRow
className="mt-3.5"
>
<Form.Checkbox
checked={false}
className="decorative-control-label"
onChange={[Function]}
>
<div
className="small text-gray-700"
>
<FormattedMessage
defaultMessage="Allow transcript downloads"
description="Label for allow transcript downloads checkbox"
id="authoring.videoeditor.transcripts.allowDownloadCheckboxLabel"
/>
</div>
</Form.Checkbox>
<OverlayTrigger
key="top"
overlay={
<Tooltip
id="tooltip-top"
>
<FormattedMessage
defaultMessage="Learners will see a link to download the transcript below the video."
description="Message for show by default checkbox"
id="authoring.videoeditor.transcripts.upload.allowDownloadTooltipMessage"
/>
</Tooltip>
}
placement="top"
>
<Icon
style={
{
"height": "16px",
"width": "16px",
}
}
/>
</OverlayTrigger>
<ActionRow.Spacer />
</ActionRow>
<Form.Checkbox
checked={false}
className="mt-3 decorative-control-label"
onChange={[Function]}
>
<div
className="small text-gray-700"
>
<FormattedMessage
defaultMessage="Show transcript in the video player by default"
description="Label for show by default checkbox"
id="authoring.videoeditor.transcripts.upload.showByDefaultCheckboxLabel"
/>
</div>
</Form.Checkbox>
</Form.Group>
<div
className="mt-2"
>
<Button
className="text-primary-500 font-weight-bold justify-content-start pl-0"
onClick={[Function]}
size="sm"
variant="link"
>
<FormattedMessage
defaultMessage="Add a transcript"
description="Label for upload button"
id="authoring.videoeditor.transcripts.upload.label"
/>
</Button>
</div>
</Stack>
</CollapsibleFormWidget>
`;

exports[`TranscriptWidget component snapshots snapshots: renders as expected with allowTranscriptDownloads true 1`] = `
<CollapsibleFormWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jest.mock('../../../../../../data/redux', () => ({
thunkActions: {
video: {
deleteTranscript: jest.fn().mockName('thunkActions.video.deleteTranscript'),
updateTranscriptHandlerUrl: jest.fn().mockName('thunkActions.video.updateTranscriptHandlerUrl'),
},
},

Expand Down
34 changes: 19 additions & 15 deletions src/editors/data/redux/video/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,25 @@ export const openLanguages = createSelector(
);

export const getTranscriptDownloadUrl = createSelector(
[AppSelectors.simpleSelectors.studioEndpointUrl, AppSelectors.simpleSelectors.blockId],
(studioEndpointUrl, blockId) => ({ language }) => downloadVideoTranscriptURL({
studioEndpointUrl,
blockId,
language,
}),
);

export const getTranscriptDownloadUrlV2 = createSelector(
[simpleSelectors.transcriptHandlerUrl],
(transcriptHandlerUrl) => ({ language }) => downloadVideoTranscriptURLV2({
transcriptHandlerUrl,
language,
}),
[
AppSelectors.simpleSelectors.studioEndpointUrl,
AppSelectors.simpleSelectors.blockId,
AppSelectors.isLibrary,
simpleSelectors.transcriptHandlerUrl,
],
(studioEndpointUrl, blockId, isLibrary, transcriptHandlerUrl) => ({ language }) => {

Check warning on line 69 in src/editors/data/redux/video/selectors.js

View check run for this annotation

Codecov / codecov/patch

src/editors/data/redux/video/selectors.js#L69

Added line #L69 was not covered by tests
if (isLibrary) {
return downloadVideoTranscriptURLV2({

Check warning on line 71 in src/editors/data/redux/video/selectors.js

View check run for this annotation

Codecov / codecov/patch

src/editors/data/redux/video/selectors.js#L71

Added line #L71 was not covered by tests
transcriptHandlerUrl,
language,
});
}
return downloadVideoTranscriptURL({

Check warning on line 76 in src/editors/data/redux/video/selectors.js

View check run for this annotation

Codecov / codecov/patch

src/editors/data/redux/video/selectors.js#L76

Added line #L76 was not covered by tests
studioEndpointUrl,
blockId,
language,
});
},
);

export const buildTranscriptUrl = createSelector(
Expand Down Expand Up @@ -148,7 +153,6 @@ export default {
...simpleSelectors,
openLanguages,
getTranscriptDownloadUrl,
getTranscriptDownloadUrlV2,
buildTranscriptUrl,
getHandoutDownloadUrl,
videoSettings,
Expand Down

0 comments on commit 91b4a9d

Please sign in to comment.