From 0111d1c2f52dc7ab7098d7c83678d53b691f0cd8 Mon Sep 17 00:00:00 2001 From: jansenk Date: Thu, 8 Jun 2023 12:15:52 -0400 Subject: [PATCH 1/4] fix: remove param from end of video features url --- src/editors/data/redux/thunkActions/requests.js | 1 - src/editors/data/redux/thunkActions/requests.test.js | 1 - src/editors/data/services/cms/api.js | 3 +-- src/editors/data/services/cms/api.test.js | 2 +- src/editors/data/services/cms/mockApi.js | 2 +- src/editors/data/services/cms/urls.js | 4 ++-- src/editors/data/services/cms/urls.test.js | 4 ++-- 7 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/editors/data/redux/thunkActions/requests.js b/src/editors/data/redux/thunkActions/requests.js index ed9c40ad3..b0cb34eb2 100644 --- a/src/editors/data/redux/thunkActions/requests.js +++ b/src/editors/data/redux/thunkActions/requests.js @@ -290,7 +290,6 @@ export const fetchVideoFeatures = ({ ...rest }) => (dispatch, getState) => { requestKey: RequestKeys.fetchVideoFeatures, promise: api.fetchVideoFeatures({ studioEndpointUrl: selectors.app.studioEndpointUrl(getState()), - learningContextId: selectors.app.learningContextId(getState()), }), ...rest, })); diff --git a/src/editors/data/redux/thunkActions/requests.test.js b/src/editors/data/redux/thunkActions/requests.test.js index bf1d0c411..fac633a1b 100644 --- a/src/editors/data/redux/thunkActions/requests.test.js +++ b/src/editors/data/redux/thunkActions/requests.test.js @@ -486,7 +486,6 @@ describe('requests thunkActions module', () => { requestKey: RequestKeys.fetchVideoFeatures, promise: api.fetchVideoFeatures({ studioEndpointUrl: selectors.app.studioEndpointUrl(testState), - learningContextId: selectors.app.learningContextId(testState), }), }, }); diff --git a/src/editors/data/services/cms/api.js b/src/editors/data/services/cms/api.js index f43ff9fdf..1b1a416ec 100644 --- a/src/editors/data/services/cms/api.js +++ b/src/editors/data/services/cms/api.js @@ -204,9 +204,8 @@ export const apiMethods = { ), fetchVideoFeatures: ({ studioEndpointUrl, - learningContextId, }) => get( - urls.videoFeatures({ studioEndpointUrl, learningContextId }), + urls.videoFeatures({ studioEndpointUrl }), ), uploadVideo: ({ data, diff --git a/src/editors/data/services/cms/api.test.js b/src/editors/data/services/cms/api.test.js index fa17b0128..b3414c88c 100644 --- a/src/editors/data/services/cms/api.test.js +++ b/src/editors/data/services/cms/api.test.js @@ -575,7 +575,7 @@ describe('cms api', () => { }); describe('fetchVideoFeatures', () => { it('should call get with url.videoFeatures', () => { - const args = { studioEndpointUrl, learningContextId }; + const args = { studioEndpointUrl }; apiMethods.fetchVideoFeatures({ ...args }); expect(get).toHaveBeenCalledWith(urls.videoFeatures({ ...args })); }); diff --git a/src/editors/data/services/cms/mockApi.js b/src/editors/data/services/cms/mockApi.js index 9b3de20aa..6e15c0c56 100644 --- a/src/editors/data/services/cms/mockApi.js +++ b/src/editors/data/services/cms/mockApi.js @@ -139,7 +139,7 @@ export const fetchAdvanceSettings = ({ studioEndpointUrl, learningContextId }) = data: { allow_unsupported_xblocks: { value: true } }, }); // eslint-disable-next-line -export const fetchVideoFeatures = ({ studioEndpointUrl, learningContextId }) => mockPromise({ +export const fetchVideoFeatures = ({ studioEndpointUrl }) => mockPromise({ data: { allowThumbnailUpload: true, videoSharingEnabledForCourse: true, diff --git a/src/editors/data/services/cms/urls.js b/src/editors/data/services/cms/urls.js index 0a7de51fb..fd1b11af6 100644 --- a/src/editors/data/services/cms/urls.js +++ b/src/editors/data/services/cms/urls.js @@ -63,8 +63,8 @@ export const courseAdvanceSettings = ({ studioEndpointUrl, learningContextId }) `${studioEndpointUrl}/api/contentstore/v0/advanced_settings/${learningContextId}` ); -export const videoFeatures = ({ studioEndpointUrl, learningContextId }) => ( - `${studioEndpointUrl}/video_features/${learningContextId}` +export const videoFeatures = ({ studioEndpointUrl }) => ( + `${studioEndpointUrl}/video_features/` ); export const courseVideos = ({ studioEndpointUrl, learningContextId }) => ( diff --git a/src/editors/data/services/cms/urls.test.js b/src/editors/data/services/cms/urls.test.js index 47dbd5cff..3e1ddb1d4 100644 --- a/src/editors/data/services/cms/urls.test.js +++ b/src/editors/data/services/cms/urls.test.js @@ -135,8 +135,8 @@ describe('cms url methods', () => { }); describe('videoFeatures', () => { it('returns url with studioEndpointUrl and learningContextId', () => { - expect(videoFeatures({ studioEndpointUrl, learningContextId })) - .toEqual(`${studioEndpointUrl}/video_features/${learningContextId}`); + expect(videoFeatures({ studioEndpointUrl })) + .toEqual(`${studioEndpointUrl}/video_features/`); }); }); describe('courseVideos', () => { From e2535b24673fef8e9dcf3f5052648b439d29f952 Mon Sep 17 00:00:00 2001 From: jansenk Date: Tue, 6 Jun 2023 11:25:29 -0400 Subject: [PATCH 2/4] feat: send event on checkbox change --- .../components/SocialShareWidget/constants.js | 5 +++ .../components/SocialShareWidget/hooks.jsx | 24 ++++++++++ .../SocialShareWidget/hooks.test.jsx | 44 +++++++++++++++++++ .../components/SocialShareWidget/index.jsx | 10 ++--- 4 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js create mode 100644 src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx create mode 100644 src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js new file mode 100644 index 000000000..08a42dfff --- /dev/null +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js @@ -0,0 +1,5 @@ +export const analyticsEvents = { + socialSharingSettingChanged: 'edx.social.video_sharing_setting.changed' +} + +export default analyticsEvents \ No newline at end of file diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx new file mode 100644 index 000000000..1b6dee43d --- /dev/null +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx @@ -0,0 +1,24 @@ +import { useSelector } from 'react-redux'; +import analyticsEvents from './constants'; +import { sendTrackEvent } from '@edx/frontend-platform/analytics'; +import { selectors } from '../../../../../../data/redux'; + +export const handleSocialSharingCheckboxChange = ({ updateField }) => { + const analytics = useSelector(selectors.app.analytics); + const allowVideoSharing = useSelector(selectors.video.allowVideoSharing); + return (event) => { + sendTrackEvent( + analyticsEvents.socialSharingSettingChanged, + { + ...analytics, + value: event.target.checked, + } + ); + updateField({ + allowVideoSharing: { + ...allowVideoSharing, + value: event.target.checked, + }, + }); + }; +}; diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx new file mode 100644 index 000000000..3e20a74b1 --- /dev/null +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx @@ -0,0 +1,44 @@ +import { actions } from '../../../../../../data/redux/app'; +import { sendTrackEvent } from '@edx/frontend-platform/analytics'; +import analyticsEvents from './constants'; +import * as hooks from './hooks'; + +jest.mock('../../../../../../data/redux', () => ({ + selectors: { + app: { + analytics: jest.fn((state) => ({ analytics: state })), + }, + video: { + allowVideoSharing: jest.fn((state) => ({ allowVideoSharing: state })), + }, + }, +})); + +jest.mock('@edx/frontend-platform/analytics', () => ({ + sendTrackEvent: jest.fn(), +})); + + +describe('SocialShareWidget hooks', () => { + describe('handleSocialSharingCheckboxChange when', () => { + var onClick, updateField; + describe.each([true, false])('box is toggled', (checked) => { + beforeAll(() => { + jest.resetAllMocks() + updateField = jest.fn() + onClick = hooks.handleSocialSharingCheckboxChange({ updateField }); + expect(typeof onClick).toBe('function'); + onClick({ target: { checked } }); + }); + it("field is updated", () => { + expect(updateField).toBeCalledWith({"allowVideoSharing": {"value": checked}}); + }); + it("event tracking is called", () => { + expect(sendTrackEvent).toBeCalledWith( + analyticsEvents.socialSharingSettingChanged, + {"value": checked} + ); + }); + }); + }); +}); diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx index f9c9a2026..09e3de14b 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx @@ -14,6 +14,7 @@ import { import { selectors, actions } from '../../../../../../data/redux'; import CollapsibleFormWidget from '../CollapsibleFormWidget'; import messages from './messages'; +import * as hooks from './hooks' /** * Collapsible Form widget controlling video thumbnail @@ -32,6 +33,8 @@ export const SocialShareWidget = ({ const isSetByCourse = allowVideoSharing.level === 'course'; const videoSharingEnabled = isLibrary ? videoSharingEnabledForAll : videoSharingEnabledForCourse; const learnMoreLink = videoSharingLearnMoreLink || 'http://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/latest/developing_course/social_sharing.html'; + const onSocialSharingCheckboxChange = hooks.handleSocialSharingCheckboxChange({ updateField }); + const getSubtitle = () => { if (allowVideoSharing.value) { return intl.formatMessage(messages.enabledSubtitle); @@ -52,12 +55,7 @@ export const SocialShareWidget = ({ className="mt-3" checked={allowVideoSharing.value} disabled={isSetByCourse} - onChange={(e) => updateField({ - allowVideoSharing: { - ...allowVideoSharing, - value: e.target.checked, - }, - })} + onChange={onSocialSharingCheckboxChange} >
{intl.formatMessage(messages.socialSharingCheckboxLabel)} From 491d870cd2c06c44ee25592d2b110b31b8407275 Mon Sep 17 00:00:00 2001 From: jansenk Date: Mon, 12 Jun 2023 10:25:04 -0400 Subject: [PATCH 3/4] style: quality --- .../components/SocialShareWidget/constants.js | 6 +++--- .../components/SocialShareWidget/hooks.jsx | 6 ++++-- .../components/SocialShareWidget/hooks.test.jsx | 17 ++++++++--------- .../components/SocialShareWidget/index.jsx | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js index 08a42dfff..3b104e33b 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/constants.js @@ -1,5 +1,5 @@ export const analyticsEvents = { - socialSharingSettingChanged: 'edx.social.video_sharing_setting.changed' -} + socialSharingSettingChanged: 'edx.social.video_sharing_setting.changed', +}; -export default analyticsEvents \ No newline at end of file +export default analyticsEvents; diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx index 1b6dee43d..01ae560ae 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx @@ -1,7 +1,7 @@ import { useSelector } from 'react-redux'; -import analyticsEvents from './constants'; import { sendTrackEvent } from '@edx/frontend-platform/analytics'; import { selectors } from '../../../../../../data/redux'; +import analyticsEvents from './constants'; export const handleSocialSharingCheckboxChange = ({ updateField }) => { const analytics = useSelector(selectors.app.analytics); @@ -12,7 +12,7 @@ export const handleSocialSharingCheckboxChange = ({ updateField }) => { { ...analytics, value: event.target.checked, - } + }, ); updateField({ allowVideoSharing: { @@ -22,3 +22,5 @@ export const handleSocialSharingCheckboxChange = ({ updateField }) => { }); }; }; + +export default handleSocialSharingCheckboxChange; diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx index 3e20a74b1..0bd60ab6a 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx @@ -1,4 +1,3 @@ -import { actions } from '../../../../../../data/redux/app'; import { sendTrackEvent } from '@edx/frontend-platform/analytics'; import analyticsEvents from './constants'; import * as hooks from './hooks'; @@ -18,25 +17,25 @@ jest.mock('@edx/frontend-platform/analytics', () => ({ sendTrackEvent: jest.fn(), })); - describe('SocialShareWidget hooks', () => { describe('handleSocialSharingCheckboxChange when', () => { - var onClick, updateField; + let onClick; + let updateField; describe.each([true, false])('box is toggled', (checked) => { beforeAll(() => { - jest.resetAllMocks() - updateField = jest.fn() + jest.resetAllMocks(); + updateField = jest.fn(); onClick = hooks.handleSocialSharingCheckboxChange({ updateField }); expect(typeof onClick).toBe('function'); onClick({ target: { checked } }); }); - it("field is updated", () => { - expect(updateField).toBeCalledWith({"allowVideoSharing": {"value": checked}}); + it('field is updated', () => { + expect(updateField).toBeCalledWith({ allowVideoSharing: { value: checked } }); }); - it("event tracking is called", () => { + it('event tracking is called', () => { expect(sendTrackEvent).toBeCalledWith( analyticsEvents.socialSharingSettingChanged, - {"value": checked} + { value: checked }, ); }); }); diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx index 09e3de14b..66909af2a 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx @@ -14,7 +14,7 @@ import { import { selectors, actions } from '../../../../../../data/redux'; import CollapsibleFormWidget from '../CollapsibleFormWidget'; import messages from './messages'; -import * as hooks from './hooks' +import * as hooks from './hooks'; /** * Collapsible Form widget controlling video thumbnail From 1a0cc2db2a932243aab55cfffc3fa5eab44b1c42 Mon Sep 17 00:00:00 2001 From: jansenk Date: Thu, 22 Jun 2023 09:26:11 -0400 Subject: [PATCH 4/4] style: rename function --- .../VideoSettingsModal/components/SocialShareWidget/hooks.jsx | 4 ++-- .../components/SocialShareWidget/hooks.test.jsx | 4 ++-- .../VideoSettingsModal/components/SocialShareWidget/index.jsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx index 01ae560ae..f1d6db98c 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.jsx @@ -3,7 +3,7 @@ import { sendTrackEvent } from '@edx/frontend-platform/analytics'; import { selectors } from '../../../../../../data/redux'; import analyticsEvents from './constants'; -export const handleSocialSharingCheckboxChange = ({ updateField }) => { +export const useTrackSocialSharingChange = ({ updateField }) => { const analytics = useSelector(selectors.app.analytics); const allowVideoSharing = useSelector(selectors.video.allowVideoSharing); return (event) => { @@ -23,4 +23,4 @@ export const handleSocialSharingCheckboxChange = ({ updateField }) => { }; }; -export default handleSocialSharingCheckboxChange; +export default useTrackSocialSharingChange; diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx index 0bd60ab6a..987b73f83 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/hooks.test.jsx @@ -18,14 +18,14 @@ jest.mock('@edx/frontend-platform/analytics', () => ({ })); describe('SocialShareWidget hooks', () => { - describe('handleSocialSharingCheckboxChange when', () => { + describe('useTrackSocialSharingChange when', () => { let onClick; let updateField; describe.each([true, false])('box is toggled', (checked) => { beforeAll(() => { jest.resetAllMocks(); updateField = jest.fn(); - onClick = hooks.handleSocialSharingCheckboxChange({ updateField }); + onClick = hooks.useTrackSocialSharingChange({ updateField }); expect(typeof onClick).toBe('function'); onClick({ target: { checked } }); }); diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx index 66909af2a..37515caa6 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/SocialShareWidget/index.jsx @@ -33,7 +33,7 @@ export const SocialShareWidget = ({ const isSetByCourse = allowVideoSharing.level === 'course'; const videoSharingEnabled = isLibrary ? videoSharingEnabledForAll : videoSharingEnabledForCourse; const learnMoreLink = videoSharingLearnMoreLink || 'http://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/latest/developing_course/social_sharing.html'; - const onSocialSharingCheckboxChange = hooks.handleSocialSharingCheckboxChange({ updateField }); + const onSocialSharingCheckboxChange = hooks.useTrackSocialSharingChange({ updateField }); const getSubtitle = () => { if (allowVideoSharing.value) {