Skip to content

Commit 80e3592

Browse files
authored
refactor: remove thumbnail for non-edX videos & allow removing fallback URLs (#1241)
* refactor: remove thumbnail from non-edx videos * fix: when deleting a fallback URL the app crashed * refactor: simplify conditional rendering
1 parent 121ced4 commit 80e3592

File tree

3 files changed

+16
-123
lines changed

3 files changed

+16
-123
lines changed

src/editors/containers/VideoEditor/components/VideoSettingsModal/components/ThumbnailWidget/__snapshots__/index.test.jsx.snap

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`ThumbnailWidget snapshots snapshots: renders as expected where thumbnail uploads are allowed 1`] = `
4-
<injectIntl(ShimmedIntlComponent)
5-
fontSize="x-small"
6-
isError={true}
7-
subtitle="Unavailable"
8-
title="Thumbnail"
9-
>
10-
<ErrorAlert
11-
dismissError={[Function]}
12-
hideHeading={true}
13-
isError={false}
14-
>
15-
<FormattedMessage
16-
defaultMessage="The file size for thumbnails must be larger than 2 KB or less than 2 MB. Please resize your image and try again."
17-
description=" Message presented to user when file size of image is less than 2 KB or larger than 2 MB"
18-
id="authoring.videoeditor.thumbnail.error.fileSizeError"
19-
/>
20-
</ErrorAlert>
21-
<Alert
22-
variant="light"
23-
>
24-
<FormattedMessage
25-
defaultMessage="Select a video from your library to enable this feature (applies only to courses that run on the edx.org site)."
26-
description="Message for unavailable thumbnail widget"
27-
id="authoring.videoeditor.thumbnail.unavailable.message"
28-
/>
29-
</Alert>
30-
<Stack
31-
direction="horizontal"
32-
gap={3}
33-
>
34-
<Image
35-
alt="Image used as thumbnail for video"
36-
className="w-75"
37-
fluid={true}
38-
src="sOMeUrl"
39-
thumbnail={true}
40-
/>
41-
</Stack>
42-
</injectIntl(ShimmedIntlComponent)>
43-
`;
3+
exports[`ThumbnailWidget snapshots snapshots: renders as expected where thumbnail uploads are allowed 1`] = `null`;
444

455
exports[`ThumbnailWidget snapshots snapshots: renders as expected where videoId is valid 1`] = `
466
<injectIntl(ShimmedIntlComponent)
@@ -191,81 +151,6 @@ exports[`ThumbnailWidget snapshots snapshots: renders as expected with a thumbna
191151
</injectIntl(ShimmedIntlComponent)>
192152
`;
193153

194-
exports[`ThumbnailWidget snapshots snapshots: renders as expected with default props 1`] = `
195-
<injectIntl(ShimmedIntlComponent)
196-
fontSize="x-small"
197-
isError={true}
198-
subtitle="Unavailable"
199-
title="Thumbnail"
200-
>
201-
<ErrorAlert
202-
dismissError={[Function]}
203-
hideHeading={true}
204-
isError={false}
205-
>
206-
<FormattedMessage
207-
defaultMessage="The file size for thumbnails must be larger than 2 KB or less than 2 MB. Please resize your image and try again."
208-
description=" Message presented to user when file size of image is less than 2 KB or larger than 2 MB"
209-
id="authoring.videoeditor.thumbnail.error.fileSizeError"
210-
/>
211-
</ErrorAlert>
212-
<Alert
213-
variant="light"
214-
>
215-
<FormattedMessage
216-
defaultMessage="Select a video from your library to enable this feature (applies only to courses that run on the edx.org site)."
217-
description="Message for unavailable thumbnail widget"
218-
id="authoring.videoeditor.thumbnail.unavailable.message"
219-
/>
220-
</Alert>
221-
<Stack
222-
gap={4}
223-
>
224-
<div
225-
className="text-center"
226-
>
227-
<FormattedMessage
228-
defaultMessage="Upload an image for learners to see before playing the video."
229-
description="Message for adding thumbnail"
230-
id="authoring.videoeditor.thumbnail.upload.message"
231-
/>
232-
<div
233-
className="text-primary-300"
234-
>
235-
<FormattedMessage
236-
defaultMessage="Images must have an aspect ratio of 16:9 (1280x720 px recommended)"
237-
description="Message for thumbnail aspectRequirements"
238-
id="authoring.videoeditor.thumbnail.upload.aspectRequirements"
239-
/>
240-
</div>
241-
</div>
242-
<FileInput
243-
acceptedFiles=".gif,.jpg,.jpeg,.png,.bmp,.bmp2"
244-
fileInput={
245-
{
246-
"addFile": [Function],
247-
"click": [Function],
248-
"ref": {
249-
"current": undefined,
250-
},
251-
}
252-
}
253-
/>
254-
<Button
255-
className="text-primary-500 font-weight-bold justify-content-start pl-0"
256-
disabled={true}
257-
onClick={[Function]}
258-
size="sm"
259-
variant="link"
260-
>
261-
<FormattedMessage
262-
defaultMessage="Upload thumbnail"
263-
description="Label for upload button"
264-
id="authoring.videoeditor.thumbnail.upload.label"
265-
/>
266-
</Button>
267-
</Stack>
268-
</injectIntl(ShimmedIntlComponent)>
269-
`;
154+
exports[`ThumbnailWidget snapshots snapshots: renders as expected with default props 1`] = `null`;
270155

271156
exports[`ThumbnailWidget snapshots snapshots: renders as expected with isLibrary true 1`] = `null`;

src/editors/containers/VideoEditor/components/VideoSettingsModal/components/ThumbnailWidget/index.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const ThumbnailWidget = ({
6161
}
6262
return intl.formatMessage(messages.unavailableSubtitle);
6363
};
64-
return (!isLibrary ? (
64+
return (!isLibrary && edxVideo ? (
6565
<CollapsibleFormWidget
6666
fontSize="x-small"
6767
isError={Object.keys(error).length !== 0}
@@ -75,7 +75,7 @@ const ThumbnailWidget = ({
7575
>
7676
<FormattedMessage {...messages.fileSizeError} />
7777
</ErrorAlert>
78-
{(allowThumbnailUpload && edxVideo) ? null : (
78+
{!allowThumbnailUpload && (
7979
<Alert variant="light">
8080
<FormattedMessage {...messages.unavailableMessage} />
8181
</Alert>
@@ -90,15 +90,15 @@ const ThumbnailWidget = ({
9090
src={thumbnailSrc || thumbnail}
9191
alt={intl.formatMessage(messages.thumbnailAltText)}
9292
/>
93-
{(allowThumbnailUpload && edxVideo) ? (
93+
{allowThumbnailUpload && (
9494
<IconButtonWithTooltip
9595
tooltipPlacement="top"
9696
tooltipContent={intl.formatMessage(messages.deleteThumbnail)}
9797
iconAs={Icon}
9898
src={DeleteOutline}
9999
onClick={deleteThumbnail}
100100
/>
101-
) : null }
101+
)}
102102
</Stack>
103103
) : (
104104
<Stack gap={4}>
@@ -115,7 +115,7 @@ const ThumbnailWidget = ({
115115
iconBefore={FileUpload}
116116
onClick={fileInput.click}
117117
variant="link"
118-
disabled={!(allowThumbnailUpload && edxVideo)}
118+
disabled={!allowThumbnailUpload}
119119
>
120120
<FormattedMessage {...messages.uploadButtonLabel} />
121121
</Button>

src/editors/containers/VideoEditor/components/VideoSettingsModal/components/VideoSourceWidget/hooks.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ export const sourceHooks = ({ dispatch, previousVideoId, setAlert }) => ({
3939

4040
export const fallbackHooks = ({ fallbackVideos, dispatch }) => ({
4141
addFallbackVideo: () => dispatch(actions.video.updateField({ fallbackVideos: [...fallbackVideos, ''] })),
42+
/**
43+
* Deletes the first occurrence of the given videoUrl from the fallbackVideos list
44+
* @param {string} videoUrl - the video URL to delete
45+
*/
4246
deleteFallbackVideo: (videoUrl) => {
43-
const updatedFallbackVideos = fallbackVideos.splice(fallbackVideos.indexOf(videoUrl), 1);
47+
const index = fallbackVideos.findIndex(video => video === videoUrl);
48+
const updatedFallbackVideos = [
49+
...fallbackVideos.slice(0, index),
50+
...fallbackVideos.slice(index + 1),
51+
];
4452
dispatch(actions.video.updateField({ fallbackVideos: updatedFallbackVideos }));
4553
},
4654
});

0 commit comments

Comments
 (0)