Skip to content

Commit

Permalink
Use YouTube video title and channel as assignment description (#5500)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Jun 21, 2023
1 parent 0970cc8 commit 22114e1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ export default function ContentSelector({
onSelectContent({ type: 'url', url });
};

const selectYouTubeURL = (url: string, title?: string) => {
cancelDialog();

const name = title && `YouTube: ${title}`;
onSelectContent({ type: 'url', url, name });
};

const selectCanvasFile = (file: File) => {
cancelDialog();
onSelectContent({ type: 'file', file });
Expand Down Expand Up @@ -259,7 +266,7 @@ export default function ContentSelector({
<YouTubePicker
defaultURL={getDefaultValueIfYouTubeURL()}
onCancel={cancelDialog}
onSelectURL={selectURL}
onSelectURL={selectYouTubeURL}
/>
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export default function FilePickerApp({ onSubmit }: FilePickerAppProps) {

<div data-testid="content-selector-container">
{content && currentStep !== 'content-selection' ? (
<div className="flex gap-x-2 items-center">
<div className="flex gap-x-2 items-start">
<span
className="break-words italic"
data-testid="content-summary"
Expand Down
13 changes: 10 additions & 3 deletions lms/static/scripts/frontend_apps/components/YouTubePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type YouTubePickerProps = {

onCancel: () => void;
/** Callback invoked with the entered URL when the user accepts the dialog */
onSelectURL: (url: string) => void;
onSelectURL: (url: string, videoName?: string) => void;
};

function formatRestrictionError(
Expand Down Expand Up @@ -44,6 +44,10 @@ function formatRestrictionError(
);
}

function formatVideoName(videoInfo: YouTubeVideoInfo): string {
return `${videoInfo.title} (${videoInfo.channel})`;
}

export default function YouTubePicker({
onCancel,
defaultURL,
Expand Down Expand Up @@ -87,7 +91,10 @@ export default function YouTubePicker({
const resetCurrentURL = () => setCurrentURL(undefined);
const confirmSelection = () => {
if (currentURL) {
onSelectURL(currentURL);
const videoName = videoInfo.data
? formatVideoName(videoInfo.data)
: undefined;
onSelectURL(currentURL, videoName);
}
};

Expand Down Expand Up @@ -131,7 +138,7 @@ export default function YouTubePicker({
{!error && videoInfo.data?.title && videoInfo.data.channel && (
<UIMessage data-testid="selected-video" status="success">
<span className="font-bold italic">
{videoInfo.data.title} ({videoInfo.data.channel})
{formatVideoName(videoInfo.data)}
</span>
</UIMessage>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,18 @@ describe('ContentSelector', () => {

const picker = getYouTubePicker(wrapper);
interact(wrapper, () => {
picker.props().onSelectURL('https://youtu.be/EU6TDnV5osM');
picker
.props()
.onSelectURL(
'https://youtu.be/EU6TDnV5osM',
'The video title (channel)'
);
});

assert.calledWith(onSelectContent, {
type: 'url',
url: 'https://youtu.be/EU6TDnV5osM',
name: 'YouTube: The video title (channel)',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,26 @@ describe('YouTubePicker', () => {
const wrapper = renderComponent();

wrapper.find('button[data-testid="select-button"]').props().onClick();
assert.calledWith(fakeOnSelectURL, 'https://youtu.be/videoId');
assert.calledWith(fakeOnSelectURL, 'https://youtu.be/videoId', undefined);
});

it('invokes `onSelectURL` with video data, when available', () => {
fakeUseAPIFetch.returns({
data: {
title: 'The video title',
channel: 'Hypothesis',
restrictions: [],
},
});

const wrapper = renderComponent();

wrapper.find('button[data-testid="select-button"]').props().onClick();
assert.calledWith(
fakeOnSelectURL,
'https://youtu.be/videoId',
'The video title (Hypothesis)'
);
});

[undefined, 'not-a-youtube-url'].forEach(defaultURL => {
Expand Down

0 comments on commit 22114e1

Please sign in to comment.