From fb3c32cab35cd6d912e177fb9862e782f81010c5 Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Tue, 17 Dec 2024 15:39:13 +1100 Subject: [PATCH 1/4] refactor: block creation for text component in librries v2 --- .../containers/EditorContainer/hooks.ts | 13 ++++ src/editors/containers/TextEditor/index.jsx | 3 +- src/editors/data/constants/requests.ts | 1 + src/editors/data/redux/app/selectors.ts | 24 +++++++- src/editors/data/redux/thunkActions/app.js | 19 ++++++ .../data/redux/thunkActions/requests.js | 26 ++++++++ src/editors/hooks.ts | 22 ++++++- .../add-content/AddContentContainer.tsx | 60 +++++++++---------- .../common/context/LibraryContext.tsx | 7 ++- .../components/ComponentEditorModal.tsx | 2 +- 10 files changed, 135 insertions(+), 42 deletions(-) diff --git a/src/editors/containers/EditorContainer/hooks.ts b/src/editors/containers/EditorContainer/hooks.ts index 935e3ad89d..0fa1935de3 100644 --- a/src/editors/containers/EditorContainer/hooks.ts +++ b/src/editors/containers/EditorContainer/hooks.ts @@ -12,6 +12,7 @@ export const { navigateCallback, nullMethod, saveBlock, + createBlock, } = appHooks; export const state = StrictDict({ @@ -27,9 +28,21 @@ export const handleSaveClicked = ({ }) => { // eslint-disable-next-line react-hooks/rules-of-hooks const returnUrl = useSelector(selectors.app.returnUrl); + // eslint-disable-next-line react-hooks/rules-of-hooks + const isCreateBlock = useSelector(selectors.app.isCreateBlock); const destination = returnFunction ? '' : returnUrl; // eslint-disable-next-line react-hooks/rules-of-hooks const analytics = useSelector(selectors.app.analytics); + if (isCreateBlock) { + return () => createBlock({ + analytics, + content: getContent({ dispatch }), + destination, + dispatch, + returnFunction, + validateEntry, + }); + } return () => saveBlock({ analytics, diff --git a/src/editors/containers/TextEditor/index.jsx b/src/editors/containers/TextEditor/index.jsx index 0546e65b04..17cf885ac5 100644 --- a/src/editors/containers/TextEditor/index.jsx +++ b/src/editors/containers/TextEditor/index.jsx @@ -132,7 +132,8 @@ export const mapStateToProps = (state) => ({ blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }), blockId: selectors.app.blockId(state), showRawEditor: selectors.app.showRawEditor(state), - blockFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }), + blockFinished: selectors.app.isCreateBlock(state) + || selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }), learningContextId: selectors.app.learningContextId(state), images: selectors.app.images(state), isLibrary: selectors.app.isLibrary(state), diff --git a/src/editors/data/constants/requests.ts b/src/editors/data/constants/requests.ts index e12905d588..1336c7fdca 100644 --- a/src/editors/data/constants/requests.ts +++ b/src/editors/data/constants/requests.ts @@ -13,6 +13,7 @@ export const RequestKeys = StrictDict({ fetchImages: 'fetchImages', fetchUnit: 'fetchUnit', fetchStudioView: 'fetchStudioView', + creaateBlock: 'createBlock', saveBlock: 'saveBlock', uploadVideo: 'uploadVideo', allowThumbnailUpload: 'allowThumbnailUpload', diff --git a/src/editors/data/redux/app/selectors.ts b/src/editors/data/redux/app/selectors.ts index 3b7d151023..5e9301b13b 100644 --- a/src/editors/data/redux/app/selectors.ts +++ b/src/editors/data/redux/app/selectors.ts @@ -1,7 +1,7 @@ import { createSelector } from 'reselect'; import type { EditorState } from '..'; import { blockTypes } from '../../constants/app'; -import { isLibraryV1Key } from '../../../../generic/key-utils'; +import { isLibraryKey, isLibraryV1Key } from '../../../../generic/key-utils'; import * as urls from '../../services/cms/urls'; export const appSelector = (state: EditorState) => state.app; @@ -47,7 +47,19 @@ export const isLibrary = createSelector( if (isLibraryV1Key(learningContextId)) { return true; } - if (blockId && blockId.startsWith('lb:')) { + if ((blockId && blockId.startsWith('lb:')) || isLibraryKey(learningContextId)) { + return true; + } + return false; + }, +); + +export const isCreateBlock = createSelector( + [simpleSelectors.blockId, + simpleSelectors.blockType, + ], + (blockId, blockType) => { + if (blockId === '' && blockType) { return true; } return false; @@ -59,8 +71,13 @@ export const isInitialized = createSelector( simpleSelectors.unitUrl, simpleSelectors.blockValue, isLibrary, + isCreateBlock, ], - (unitUrl, blockValue, isLibraryBlock) => { + (unitUrl, blockValue, isLibraryBlock, isCreateEditor) => { + if (isCreateEditor) { + return true; + } + if (isLibraryBlock) { return !!blockValue; } @@ -105,4 +122,5 @@ export default { displayTitle, analytics, isLibrary, + isCreateBlock, }; diff --git a/src/editors/data/redux/thunkActions/app.js b/src/editors/data/redux/thunkActions/app.js index 09ab9eb61b..3a63b834d3 100644 --- a/src/editors/data/redux/thunkActions/app.js +++ b/src/editors/data/redux/thunkActions/app.js @@ -89,6 +89,12 @@ export const fetchCourseDetails = () => (dispatch) => { export const initialize = (data) => (dispatch) => { const editorType = data.blockType; dispatch(actions.app.initialize(data)); + + if (data.blockId === '' && data.blockType) { + dispatch(actions.app.initializeEditor()); + return; + } + dispatch(module.fetchBlock()); if (data.blockId?.startsWith('block-v1:')) { dispatch(module.fetchUnit()); @@ -125,6 +131,18 @@ export const saveBlock = (content, returnToUnit) => (dispatch) => { })); }; +/** + * @param {func} onSuccess + */ +export const createBlock = (content, returnToUnit) => (dispatch) => { + dispatch(requests.createBlock({ + onSuccess: (response) => { + dispatch(actions.app.setBlockId(response.id)); + dispatch(saveBlock(content, returnToUnit)); + }, + })); +}; + export const uploadAsset = ({ file, setSelection }) => (dispatch) => { dispatch(requests.uploadAsset({ asset: file, @@ -142,4 +160,5 @@ export default StrictDict({ saveBlock, fetchImages, uploadAsset, + createBlock, }); diff --git a/src/editors/data/redux/thunkActions/requests.js b/src/editors/data/redux/thunkActions/requests.js index edff3bf875..084aa45cae 100644 --- a/src/editors/data/redux/thunkActions/requests.js +++ b/src/editors/data/redux/thunkActions/requests.js @@ -4,6 +4,8 @@ import { RequestKeys } from '../../constants/requests'; import api, { loadImages } from '../../services/cms/api'; import { actions as requestsActions } from '../requests'; import { selectors as appSelectors } from '../app'; +import { v4 as uuid4 } from 'uuid'; + // This 'module' self-import hack enables mocking during tests. // See src/editors/decisions/0005-internal-editor-testability-decisions.md. The whole approach to how hooks are tested @@ -11,6 +13,7 @@ import { selectors as appSelectors } from '../app'; // eslint-disable-next-line import/no-self-import import * as module from './requests'; import { isLibraryKey } from '../../../../generic/key-utils'; +import { createLibraryBlock } from '../../../../library-authoring/data/api'; import { acceptedImgKeys } from '../../../sharedComponents/ImageUploadModal/SelectImageModal/utils'; // Similar to `import { actions, selectors } from '..';` but avoid circular imports: @@ -122,6 +125,29 @@ export const saveBlock = ({ content, ...rest }) => (dispatch, getState) => { ...rest, })); }; + +/** + * Tracked saveBlock api method. Tracked to the `saveBlock` request key. + * @param {string} content + * @param {[func]} onSuccess - onSuccess method ((response) => { ... }) + * @param {[func]} onFailure - onFailure method ((error) => { ... }) + */ +export const createBlock = ({ ...rest }) => (dispatch, getState) => { + const definitionId = selectors.app.blockTitle(getState()) + ? selectors.app.blockTitle(getState()).toLowerCase().replaceAll(' ', '-') + : `${uuid4()}`; + + dispatch(module.networkRequest({ + requestKey: RequestKeys.creaateBlock, + promise: createLibraryBlock({ + libraryId: selectors.app.learningContextId(getState()), + blockType: selectors.app.blockType(getState()), + definitionId, + }), + ...rest, + })); +}; + export const uploadAsset = ({ asset, ...rest }) => (dispatch, getState) => { const learningContextId = selectors.app.learningContextId(getState()); dispatch(module.networkRequest({ diff --git a/src/editors/hooks.ts b/src/editors/hooks.ts index c32d608008..ef98a2ea62 100644 --- a/src/editors/hooks.ts +++ b/src/editors/hooks.ts @@ -65,7 +65,27 @@ export const saveBlock = ({ )); } }; - +export const createBlock = ({ + analytics, + content, + destination, + dispatch, + returnFunction, + validateEntry, +}) => { + if (!content) { + return; + } + dispatch(thunkActions.app.createBlock( + content, + navigateCallback({ + destination, + analyticsEvent: analyticsEvt.editorSaveClick, + analytics, + returnFunction, + }), + )); +}; export const clearSaveError = ({ dispatch, }) => () => dispatch(actions.requests.clearRequest({ requestKey: RequestKeys.saveBlock })); diff --git a/src/library-authoring/add-content/AddContentContainer.tsx b/src/library-authoring/add-content/AddContentContainer.tsx index 1a2e28b1a9..12710ac418 100644 --- a/src/library-authoring/add-content/AddContentContainer.tsx +++ b/src/library-authoring/add-content/AddContentContainer.tsx @@ -24,9 +24,8 @@ import { v4 as uuid4 } from 'uuid'; import { ToastContext } from '../../generic/toast-context'; import { useCopyToClipboard } from '../../generic/clipboard'; import { getCanEdit } from '../../course-unit/data/selectors'; -import { useCreateLibraryBlock, useLibraryPasteClipboard, useAddComponentsToCollection } from '../data/apiHooks'; +import { useLibraryPasteClipboard, useAddComponentsToCollection } from '../data/apiHooks'; import { useLibraryContext } from '../common/context/LibraryContext'; -import { canEditComponent } from '../components/ComponentEditorModal'; import { PickLibraryContentModal } from './PickLibraryContentModal'; import messages from './messages'; @@ -72,7 +71,6 @@ const AddContentContainer = () => { openComponentEditor, componentPicker, } = useLibraryContext(); - const createBlockMutation = useCreateLibraryBlock(); const updateComponentsMutation = useAddComponentsToCollection(libraryId, collectionId); const pasteClipboardMutation = useLibraryPasteClipboard(); const { showToast } = useContext(ToastContext); @@ -192,27 +190,15 @@ const AddContentContainer = () => { }; const onCreateBlock = (blockType: string) => { - createBlockMutation.mutateAsync({ - libraryId, - blockType, - definitionId: `${uuid4()}`, - }).then((data) => { - const hasEditor = canEditComponent(data.id); - if (hasEditor) { - // linkComponent on editor close. - openComponentEditor(data.id, () => linkComponent(data.id)); - } else { - // We can't start editing this right away so just show a toast message: - showToast(intl.formatMessage(messages.successCreateMessage)); - linkComponent(data.id); - } - }).catch((error) => { - showToast(parseErrorMsg( - error, - messages.errorCreateMessageWithDetail, - messages.errorCreateMessage, - )); - }); + const mfeEditorTypes = ['html', 'problem', 'video']; + if (mfeEditorTypes.includes(blockType)) { + // linkComponent on editor close. + openComponentEditor('', () => {}, blockType); + } else { + // We can't start editing this right away so just show a toast message: + showToast(intl.formatMessage(messages.successCreateMessage)); + // linkComponent(data.id); + } }; const onCreateContent = (blockType: string) => { @@ -237,7 +223,10 @@ const AddContentContainer = () => { {collectionId ? ( componentPicker && ( <> - + { ) ) : ( - - )} -
- {/* Note: for MVP we are hiding the unuspported types, not just disabling them. */} - {contentTypes.filter(ct => !ct.disabled).map((contentType) => ( - ))} + )} +
+ {/* Note: for MVP we are hiding the unuspported types, not just disabling them. */} + {contentTypes + .filter((ct) => !ct.disabled) + .map((contentType) => ( + + ))} ); }; diff --git a/src/library-authoring/common/context/LibraryContext.tsx b/src/library-authoring/common/context/LibraryContext.tsx index 9612a92855..64c92cb251 100644 --- a/src/library-authoring/common/context/LibraryContext.tsx +++ b/src/library-authoring/common/context/LibraryContext.tsx @@ -14,6 +14,7 @@ import { useComponentPickerContext } from './ComponentPickerContext'; export interface ComponentEditorInfo { usageKey: string; + blockType?:string onClose?: () => void; } @@ -35,7 +36,7 @@ export type LibraryContextData = { /** If the editor is open and the user is editing some component, this is the component being edited. */ componentBeingEdited: ComponentEditorInfo | undefined; /** If an onClose callback is provided, it will be called when the editor is closed. */ - openComponentEditor: (usageKey: string, onClose?: () => void) => void; + openComponentEditor: (usageKey: string, onClose?: () => void, blockType?:string) => void; closeComponentEditor: () => void; componentPicker?: typeof ComponentPicker; }; @@ -82,8 +83,8 @@ export const LibraryProvider = ({ return undefined; }); }, []); - const openComponentEditor = useCallback((usageKey: string, onClose?: () => void) => { - setComponentBeingEdited({ usageKey, onClose }); + const openComponentEditor = useCallback((usageKey: string, onClose?: () => void, blockType?:string) => { + setComponentBeingEdited({ usageKey, onClose, blockType }); }, []); const { data: libraryData, isLoading: isLoadingLibraryData } = useContentLibrary(libraryId); diff --git a/src/library-authoring/components/ComponentEditorModal.tsx b/src/library-authoring/components/ComponentEditorModal.tsx index 6ba78979bd..2a965d4208 100644 --- a/src/library-authoring/components/ComponentEditorModal.tsx +++ b/src/library-authoring/components/ComponentEditorModal.tsx @@ -27,7 +27,7 @@ export const ComponentEditorModal: React.FC> = () => { if (componentBeingEdited === undefined) { return null; } - const blockType = getBlockType(componentBeingEdited.usageKey); + const blockType = componentBeingEdited.blockType || getBlockType(componentBeingEdited.usageKey); const onClose = () => { closeComponentEditor(); From 09fd30f285416d0415b28d9ca87802ba54e15cd3 Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Tue, 17 Dec 2024 18:34:24 +1100 Subject: [PATCH 2/4] refactor: allow init the modal for video creation --- src/editors/containers/VideoEditor/index.tsx | 3 ++- src/editors/data/redux/thunkActions/video.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/editors/containers/VideoEditor/index.tsx b/src/editors/containers/VideoEditor/index.tsx index f2ad7c670f..ac7464a826 100644 --- a/src/editors/containers/VideoEditor/index.tsx +++ b/src/editors/containers/VideoEditor/index.tsx @@ -20,7 +20,8 @@ const VideoEditor: React.FC = ({ }) => { const intl = useIntl(); const studioViewFinished = useSelector( - (state) => selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }), + (state) => selectors.app.isCreateBlock(state) + || selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }), ); const isLibrary = useSelector(selectors.app.isLibrary) as boolean; const { diff --git a/src/editors/data/redux/thunkActions/video.js b/src/editors/data/redux/thunkActions/video.js index 352d989737..842546f6f1 100644 --- a/src/editors/data/redux/thunkActions/video.js +++ b/src/editors/data/redux/thunkActions/video.js @@ -17,8 +17,8 @@ const selectors = { app: appSelectors, video: videoSelectors }; export const loadVideoData = (selectedVideoId, selectedVideoUrl) => (dispatch, getState) => { const state = getState(); - const blockValueData = state.app.blockValue.data; - let rawVideoData = blockValueData.metadata ? blockValueData.metadata : {}; + const blockValueData = state.app?.blockValue?.data; + let rawVideoData = blockValueData?.metadata ? blockValueData.metadata : {}; const rawVideos = Object.values(selectors.app.videos(state)); if (selectedVideoId !== undefined && selectedVideoId !== null) { const selectedVideo = _.find(rawVideos, video => { From 7b0b9c8e1dc036be3bb24a4e474c551ae67a422c Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Tue, 17 Dec 2024 20:13:16 +1100 Subject: [PATCH 3/4] refactor: allow open the problem modal when is a new component --- src/editors/containers/ProblemEditor/index.tsx | 6 ++++-- src/editors/data/redux/thunkActions/problem.ts | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/editors/containers/ProblemEditor/index.tsx b/src/editors/containers/ProblemEditor/index.tsx index d8154c7e87..519a87d79b 100644 --- a/src/editors/containers/ProblemEditor/index.tsx +++ b/src/editors/containers/ProblemEditor/index.tsx @@ -65,11 +65,13 @@ const ProblemEditor: React.FC = ({ }; export const mapStateToProps = (state) => ({ - blockFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }), + blockFinished: selectors.app.isCreateBlock(state) + || selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }), blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }), problemType: selectors.problem.problemType(state), blockValue: selectors.app.blockValue(state), - advancedSettingsFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchAdvancedSettings }), + advancedSettingsFinished: selectors.app.isCreateBlock(state) + || selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchAdvancedSettings }), }); export const mapDispatchToProps = { diff --git a/src/editors/data/redux/thunkActions/problem.ts b/src/editors/data/redux/thunkActions/problem.ts index 79916195e4..fce98d273e 100644 --- a/src/editors/data/redux/thunkActions/problem.ts +++ b/src/editors/data/redux/thunkActions/problem.ts @@ -59,6 +59,7 @@ export const getDataFromOlx = ({ rawOLX, rawSettings, defaultSettings }) => { }; export const loadProblem = ({ rawOLX, rawSettings, defaultSettings }) => (dispatch) => { + console.debug(rawOLX); if (isBlankProblem({ rawOLX })) { dispatch(actions.problem.setEnableTypeSelection(camelizeKeys(defaultSettings))); } else { @@ -84,7 +85,7 @@ export const fetchAdvancedSettings = ({ rawOLX, rawSettings }) => (dispatch) => }; export const initializeProblem = (blockValue) => (dispatch, getState) => { - const rawOLX = _.get(blockValue, 'data.data', {}); + const rawOLX = _.get(blockValue, 'data.data', ''); const rawSettings = _.get(blockValue, 'data.metadata', {}); const learningContextId = selectors.app.learningContextId(getState()); if (isLibraryKey(learningContextId)) { From 6af6ee7ac8ad2dee0a12b6c4cae318d42bcacc7c Mon Sep 17 00:00:00 2001 From: Diana Olarte Date: Wed, 18 Dec 2024 16:24:37 +1100 Subject: [PATCH 4/4] fix: clean the editor store when the moda is close --- src/editors/containers/EditorContainer/hooks.ts | 1 - src/editors/containers/EditorContainer/index.tsx | 3 +++ src/editors/containers/VideoEditor/index.tsx | 6 +++--- src/editors/data/redux/app/selectors.test.ts | 10 +++++----- src/editors/data/redux/index.ts | 10 +++++++++- src/editors/data/redux/thunkActions/problem.ts | 1 - src/editors/data/redux/thunkActions/requests.js | 3 +-- src/editors/hooks.ts | 1 - 8 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/editors/containers/EditorContainer/hooks.ts b/src/editors/containers/EditorContainer/hooks.ts index 0fa1935de3..de37327a23 100644 --- a/src/editors/containers/EditorContainer/hooks.ts +++ b/src/editors/containers/EditorContainer/hooks.ts @@ -40,7 +40,6 @@ export const handleSaveClicked = ({ destination, dispatch, returnFunction, - validateEntry, }); } diff --git a/src/editors/containers/EditorContainer/index.tsx b/src/editors/containers/EditorContainer/index.tsx index eb9e08ab2c..7bc04597a2 100644 --- a/src/editors/containers/EditorContainer/index.tsx +++ b/src/editors/containers/EditorContainer/index.tsx @@ -94,6 +94,7 @@ const EditorContainer: React.FC = ({ const onSave = () => { setSaved(true); handleSave(); + dispatch({ type: 'resetEditor' }); }; // Stops user from navigating away if they have unsaved changes. usePromptIfDirty(() => { @@ -109,6 +110,7 @@ const EditorContainer: React.FC = ({ openCancelConfirmModal(); } else { handleCancel(); + dispatch({ type: 'resetEditor' }); } }; return ( @@ -128,6 +130,7 @@ const EditorContainer: React.FC = ({ if (returnFunction) { closeCancelConfirmModal(); } + dispatch({ type: 'resetEditor' }); }} > diff --git a/src/editors/containers/VideoEditor/index.tsx b/src/editors/containers/VideoEditor/index.tsx index ac7464a826..01583bfd7d 100644 --- a/src/editors/containers/VideoEditor/index.tsx +++ b/src/editors/containers/VideoEditor/index.tsx @@ -20,10 +20,10 @@ const VideoEditor: React.FC = ({ }) => { const intl = useIntl(); const studioViewFinished = useSelector( - (state) => selectors.app.isCreateBlock(state) - || selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }), + (state) => selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }), ); const isLibrary = useSelector(selectors.app.isLibrary) as boolean; + const isCreateBlock = useSelector(selectors.app.isCreateBlock) as boolean; const { error, validateEntry, @@ -37,7 +37,7 @@ const VideoEditor: React.FC = ({ returnFunction={returnFunction} validateEntry={validateEntry} > - {studioViewFinished ? ( + {(isCreateBlock || studioViewFinished) ? (
diff --git a/src/editors/data/redux/app/selectors.test.ts b/src/editors/data/redux/app/selectors.test.ts index b380deca4f..f3ceed36e5 100644 --- a/src/editors/data/redux/app/selectors.test.ts +++ b/src/editors/data/redux/app/selectors.test.ts @@ -98,8 +98,8 @@ describe('app selectors unit tests', () => { }; [ - [[null, truthy.blockValue, true] as [any, any, any], true] as const, - [[null, null, true] as [any, any, any], false] as const, + [[null, truthy.blockValue, true, false] as [any, any, any, any], true] as const, + [[null, null, true, false] as [any, any, any, any], false] as const, ].map(([args, expected]) => expect(cb(...args)).toEqual(expected)); }); }); @@ -112,9 +112,9 @@ describe('app selectors unit tests', () => { }; [ - [[null, truthy.blockValue, false] as [any, any, any], false] as const, - [[truthy.unitUrl, null, false] as [any, any, any], false] as const, - [[truthy.unitUrl, truthy.blockValue, false] as [any, any, any], true] as const, + [[null, truthy.blockValue, false, false] as [any, any, any, any], false] as const, + [[truthy.unitUrl, null, false, false] as [any, any, any, any], false] as const, + [[truthy.unitUrl, truthy.blockValue, false, false] as [any, any, any, any], true] as const, ].map(([args, expected]) => expect(cb(...args)).toEqual(expected)); }); }); diff --git a/src/editors/data/redux/index.ts b/src/editors/data/redux/index.ts index 7758662965..3606f99aa2 100644 --- a/src/editors/data/redux/index.ts +++ b/src/editors/data/redux/index.ts @@ -12,7 +12,7 @@ import { AdvancedProblemType, ProblemType } from '../constants/problem'; export { default as thunkActions } from './thunkActions'; -const rootReducer = combineReducers({ +const editorReducer = combineReducers({ app: app.reducer, requests: requests.reducer, video: video.reducer, @@ -20,6 +20,14 @@ const rootReducer = combineReducers({ game: game.reducer, }); +const rootReducer = (state: any, action: any) => { + if (action.type === 'resetEditor') { + return editorReducer(undefined, action); + } + + return editorReducer(state, action); +}; + const actions = StrictDict({ app: app.actions, requests: requests.actions, diff --git a/src/editors/data/redux/thunkActions/problem.ts b/src/editors/data/redux/thunkActions/problem.ts index fce98d273e..cd9567d407 100644 --- a/src/editors/data/redux/thunkActions/problem.ts +++ b/src/editors/data/redux/thunkActions/problem.ts @@ -59,7 +59,6 @@ export const getDataFromOlx = ({ rawOLX, rawSettings, defaultSettings }) => { }; export const loadProblem = ({ rawOLX, rawSettings, defaultSettings }) => (dispatch) => { - console.debug(rawOLX); if (isBlankProblem({ rawOLX })) { dispatch(actions.problem.setEnableTypeSelection(camelizeKeys(defaultSettings))); } else { diff --git a/src/editors/data/redux/thunkActions/requests.js b/src/editors/data/redux/thunkActions/requests.js index 084aa45cae..cb0cd60d31 100644 --- a/src/editors/data/redux/thunkActions/requests.js +++ b/src/editors/data/redux/thunkActions/requests.js @@ -1,11 +1,10 @@ +import { v4 as uuid4 } from 'uuid'; import { StrictDict, parseLibraryImageData, getLibraryImageAssets } from '../../../utils'; import { RequestKeys } from '../../constants/requests'; import api, { loadImages } from '../../services/cms/api'; import { actions as requestsActions } from '../requests'; import { selectors as appSelectors } from '../app'; -import { v4 as uuid4 } from 'uuid'; - // This 'module' self-import hack enables mocking during tests. // See src/editors/decisions/0005-internal-editor-testability-decisions.md. The whole approach to how hooks are tested diff --git a/src/editors/hooks.ts b/src/editors/hooks.ts index ef98a2ea62..05d471198f 100644 --- a/src/editors/hooks.ts +++ b/src/editors/hooks.ts @@ -71,7 +71,6 @@ export const createBlock = ({ destination, dispatch, returnFunction, - validateEntry, }) => { if (!content) { return;