Skip to content

Commit 0e91373

Browse files
authored
Merge pull request #488 from openedx/revert-484-KristinAoki/improve-asset-loading
Revert "feat: improve asset loading"
2 parents c84e322 + ba8141e commit 0e91373

File tree

47 files changed

+404
-635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+404
-635
lines changed

src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/hooks.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,19 @@ export const setAnswerTitle = ({
3939
};
4040

4141
export const setSelectedFeedback = ({ answer, hasSingleAnswer, dispatch }) => (e) => {
42-
if (e.target) {
43-
dispatch(actions.problem.updateAnswer({
44-
id: answer.id,
45-
hasSingleAnswer,
46-
selectedFeedback: e.target.value,
47-
}));
48-
}
42+
dispatch(actions.problem.updateAnswer({
43+
id: answer.id,
44+
hasSingleAnswer,
45+
selectedFeedback: e.target.value,
46+
}));
4947
};
5048

5149
export const setUnselectedFeedback = ({ answer, hasSingleAnswer, dispatch }) => (e) => {
52-
if (e.target) {
53-
dispatch(actions.problem.updateAnswer({
54-
id: answer.id,
55-
hasSingleAnswer,
56-
unselectedFeedback: e.target.value,
57-
}));
58-
}
50+
dispatch(actions.problem.updateAnswer({
51+
id: answer.id,
52+
hasSingleAnswer,
53+
unselectedFeedback: e.target.value,
54+
}));
5955
};
6056

6157
export const useFeedback = (answer) => {

src/editors/containers/ProblemEditor/components/EditProblemView/ExplanationWidget/__snapshots__/index.test.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exports[`SolutionWidget render snapshot: renders correct default 1`] = `
2323
/>
2424
</div>
2525
<[object Object]
26-
editorContentHtml="This is my solution"
26+
editorContentHtml="This is my question"
2727
editorType="solution"
2828
id="solution"
2929
minHeight={150}

src/editors/containers/ProblemEditor/components/EditProblemView/ExplanationWidget/index.jsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@ import { selectors } from '../../../../../data/redux';
66
import messages from './messages';
77

88
import TinyMceWidget from '../../../../../sharedComponents/TinyMceWidget';
9-
import { prepareEditorRef, replaceStaticWithAsset } from '../../../../../sharedComponents/TinyMceWidget/hooks';
9+
import { prepareEditorRef } from '../../../../../sharedComponents/TinyMceWidget/hooks';
1010

1111
export const ExplanationWidget = ({
1212
// redux
1313
settings,
14-
learningContextId,
1514
// injected
1615
intl,
1716
}) => {
1817
const { editorRef, refReady, setEditorRef } = prepareEditorRef();
19-
const solutionContent = replaceStaticWithAsset({
20-
initialContent: settings?.solutionExplanation,
21-
learningContextId,
22-
});
2318
if (!refReady) { return null; }
2419
return (
2520
<div className="tinyMceWidget mt-4 text-primary-500">
@@ -33,7 +28,7 @@ export const ExplanationWidget = ({
3328
id="solution"
3429
editorType="solution"
3530
editorRef={editorRef}
36-
editorContentHtml={solutionContent}
31+
editorContentHtml={settings?.solutionExplanation}
3732
setEditorRef={setEditorRef}
3833
minHeight={150}
3934
placeholder={intl.formatMessage(messages.placeholder)}
@@ -46,13 +41,11 @@ ExplanationWidget.propTypes = {
4641
// redux
4742
// eslint-disable-next-line
4843
settings: PropTypes.any.isRequired,
49-
learningContextId: PropTypes.string.isRequired,
5044
// injected
5145
intl: intlShape.isRequired,
5246
};
5347
export const mapStateToProps = (state) => ({
5448
settings: selectors.problem.settings(state),
55-
learningContextId: selectors.app.learningContextId(state),
5649
});
5750

5851
export default injectIntl(connect(mapStateToProps)(ExplanationWidget));

src/editors/containers/ProblemEditor/components/EditProblemView/ExplanationWidget/index.test.jsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ jest.mock('../../../../../data/redux', () => ({
1212
problem: {
1313
settings: jest.fn(state => ({ question: state })),
1414
},
15-
app: {
16-
learningContextId: jest.fn(state => ({ learningContextId: state })),
17-
},
1815
},
1916
thunkActions: {
2017
video: {
@@ -28,13 +25,11 @@ jest.mock('../../../../../sharedComponents/TinyMceWidget/hooks', () => ({
2825
refReady: true,
2926
setEditorRef: jest.fn().mockName('prepareEditorRef.setEditorRef'),
3027
})),
31-
replaceStaticWithAsset: jest.fn(() => 'This is my solution'),
3228
}));
3329

3430
describe('SolutionWidget', () => {
3531
const props = {
36-
settings: { solutionExplanation: 'This is my solution' },
37-
learningContextId: 'course+org+run',
32+
settings: { solutionExplanation: 'This is my question' },
3833
// injected
3934
intl: { formatMessage },
4035
};
@@ -45,11 +40,8 @@ describe('SolutionWidget', () => {
4540
});
4641
describe('mapStateToProps', () => {
4742
const testState = { A: 'pple', B: 'anana', C: 'ucumber' };
48-
test('settings from problem.settings', () => {
43+
test('question from problem.question', () => {
4944
expect(mapStateToProps(testState).settings).toEqual(selectors.problem.settings(testState));
5045
});
51-
test('learningContextId from app.learningContextId', () => {
52-
expect(mapStateToProps(testState).learningContextId).toEqual(selectors.app.learningContextId(testState));
53-
});
5446
});
5547
});

src/editors/containers/ProblemEditor/components/EditProblemView/QuestionWidget/index.jsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@ import { selectors } from '../../../../../data/redux';
66
import messages from './messages';
77

88
import TinyMceWidget from '../../../../../sharedComponents/TinyMceWidget';
9-
import { prepareEditorRef, replaceStaticWithAsset } from '../../../../../sharedComponents/TinyMceWidget/hooks';
9+
import { prepareEditorRef } from '../../../../../sharedComponents/TinyMceWidget/hooks';
1010

1111
export const QuestionWidget = ({
1212
// redux
1313
question,
14-
learningContextId,
1514
// injected
1615
intl,
1716
}) => {
1817
const { editorRef, refReady, setEditorRef } = prepareEditorRef();
19-
const questionContent = replaceStaticWithAsset({
20-
initialContent: question,
21-
learningContextId,
22-
});
2318
if (!refReady) { return null; }
2419
return (
2520
<div className="tinyMceWidget">
@@ -30,7 +25,7 @@ export const QuestionWidget = ({
3025
id="question"
3126
editorType="question"
3227
editorRef={editorRef}
33-
editorContentHtml={questionContent}
28+
editorContentHtml={question}
3429
setEditorRef={setEditorRef}
3530
minHeight={150}
3631
placeholder={intl.formatMessage(messages.placeholder)}
@@ -42,13 +37,11 @@ export const QuestionWidget = ({
4237
QuestionWidget.propTypes = {
4338
// redux
4439
question: PropTypes.string.isRequired,
45-
learningContextId: PropTypes.string.isRequired,
4640
// injected
4741
intl: intlShape.isRequired,
4842
};
4943
export const mapStateToProps = (state) => ({
5044
question: selectors.problem.question(state),
51-
learningContextId: selectors.app.learningContextId(state),
5245
});
5346

5447
export default injectIntl(connect(mapStateToProps)(QuestionWidget));

src/editors/containers/ProblemEditor/components/EditProblemView/QuestionWidget/index.test.jsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ jest.mock('../../../../../data/redux', () => ({
1515
},
1616
selectors: {
1717
app: {
18-
learningContextId: jest.fn(state => ({ learningContextId: state })),
18+
isLibrary: jest.fn(state => ({ isLibrary: state })),
19+
lmsEndpointUrl: jest.fn(state => ({ lmsEndpointUrl: state })),
20+
studioEndpointUrl: jest.fn(state => ({ studioEndpointUrl: state })),
1921
},
2022
problem: {
2123
question: jest.fn(state => ({ question: state })),
@@ -33,14 +35,13 @@ jest.mock('../../../../../sharedComponents/TinyMceWidget/hooks', () => ({
3335
refReady: true,
3436
setEditorRef: jest.fn().mockName('prepareEditorRef.setEditorRef'),
3537
})),
36-
replaceStaticWithAsset: jest.fn(() => 'This is my question'),
38+
// problemEditorConfig: jest.fn(args => ({ problemEditorConfig: args })),
3739
}));
3840

3941
describe('QuestionWidget', () => {
4042
const props = {
4143
question: 'This is my question',
4244
updateQuestion: jest.fn(),
43-
learningContextId: 'course+org+run',
4445
// injected
4546
intl: { formatMessage },
4647
};
@@ -54,8 +55,5 @@ describe('QuestionWidget', () => {
5455
test('question from problem.question', () => {
5556
expect(mapStateToProps(testState).question).toEqual(selectors.problem.question(testState));
5657
});
57-
test('learningContextId from app.learningContextId', () => {
58-
expect(mapStateToProps(testState).learningContextId).toEqual(selectors.app.learningContextId(testState));
59-
});
6058
});
6159
});

src/editors/containers/ProblemEditor/components/EditProblemView/hooks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ export const parseState = ({
5656
problem,
5757
isAdvanced,
5858
ref,
59+
assets,
5960
lmsEndpointUrl,
6061
}) => () => {
6162
const rawOLX = ref?.current?.state.doc.toString();
6263
const editorObject = fetchEditorContent({ format: '' });
6364
const reactOLXParser = new ReactStateOLXParser({ problem, editorObject });
6465
const reactSettingsParser = new ReactStateSettingsParser({ problem, rawOLX });
65-
const reactBuiltOlx = setAssetToStaticUrl({ editorValue: reactOLXParser.buildOLX(), lmsEndpointUrl });
66+
const reactBuiltOlx = setAssetToStaticUrl({ editorValue: reactOLXParser.buildOLX(), assets, lmsEndpointUrl });
6667
return {
6768
settings: isAdvanced ? reactSettingsParser.parseRawOlxSettings() : reactSettingsParser.getSettings(),
6869
olx: isAdvanced ? rawOLX : reactBuiltOlx,
@@ -142,6 +143,7 @@ export const getContent = ({
142143
openSaveWarningModal,
143144
isAdvancedProblemType,
144145
editorRef,
146+
assets,
145147
lmsEndpointUrl,
146148
}) => {
147149
const problem = problemState;
@@ -159,6 +161,7 @@ export const getContent = ({
159161
isAdvanced: isAdvancedProblemType,
160162
ref: editorRef,
161163
problem,
164+
assets,
162165
lmsEndpointUrl,
163166
})();
164167
return data;

src/editors/containers/ProblemEditor/components/EditProblemView/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const EditProblemView = ({
2929
// redux
3030
problemType,
3131
problemState,
32+
assets,
3233
lmsEndpointUrl,
3334
returnUrl,
3435
analytics,
@@ -47,6 +48,7 @@ export const EditProblemView = ({
4748
openSaveWarningModal,
4849
isAdvancedProblemType,
4950
editorRef,
51+
assets,
5052
lmsEndpointUrl,
5153
})}
5254
returnFunction={returnFunction}
@@ -68,6 +70,7 @@ export const EditProblemView = ({
6870
problem: problemState,
6971
isAdvanced: isAdvancedProblemType,
7072
ref: editorRef,
73+
assets,
7174
lmsEndpointUrl,
7275
})(),
7376
returnFunction,
@@ -115,6 +118,7 @@ export const EditProblemView = ({
115118
};
116119

117120
EditProblemView.defaultProps = {
121+
assets: null,
118122
lmsEndpointUrl: null,
119123
returnFunction: null,
120124
};
@@ -124,6 +128,7 @@ EditProblemView.propTypes = {
124128
returnFunction: PropTypes.func,
125129
// eslint-disable-next-line
126130
problemState: PropTypes.any.isRequired,
131+
assets: PropTypes.shape({}),
127132
analytics: PropTypes.shape({}).isRequired,
128133
lmsEndpointUrl: PropTypes.string,
129134
returnUrl: PropTypes.string.isRequired,
@@ -132,6 +137,7 @@ EditProblemView.propTypes = {
132137
};
133138

134139
export const mapStateToProps = (state) => ({
140+
assets: selectors.app.assets(state),
135141
analytics: selectors.app.analytics(state),
136142
lmsEndpointUrl: selectors.app.lmsEndpointUrl(state),
137143
returnUrl: selectors.app.returnUrl(state),

src/editors/containers/ProblemEditor/index.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ export const ProblemEditor = ({
1616
problemType,
1717
blockFinished,
1818
blockFailed,
19+
studioViewFinished,
1920
blockValue,
2021
initializeProblemEditor,
22+
assetsFinished,
2123
advancedSettingsFinished,
2224
}) => {
2325
React.useEffect(() => {
24-
if (blockFinished && !blockFailed) {
26+
if (blockFinished && studioViewFinished && assetsFinished && !blockFailed) {
2527
initializeProblemEditor(blockValue);
2628
}
27-
}, [blockFinished, blockFailed]);
29+
}, [blockFinished, studioViewFinished, assetsFinished, blockFailed]);
2830

29-
if (!blockFinished || !advancedSettingsFinished) {
31+
if (!blockFinished || !studioViewFinished || !assetsFinished || !advancedSettingsFinished) {
3032
return (
3133
<div className="text-center p-6">
3234
<Spinner
@@ -53,15 +55,18 @@ export const ProblemEditor = ({
5355
};
5456

5557
ProblemEditor.defaultProps = {
58+
assetsFinished: null,
5659
returnFunction: null,
5760
};
5861
ProblemEditor.propTypes = {
5962
onClose: PropTypes.func.isRequired,
6063
returnFunction: PropTypes.func,
6164
// redux
65+
assetsFinished: PropTypes.bool,
6266
advancedSettingsFinished: PropTypes.bool.isRequired,
6367
blockFinished: PropTypes.bool.isRequired,
6468
blockFailed: PropTypes.bool.isRequired,
69+
studioViewFinished: PropTypes.bool.isRequired,
6570
problemType: PropTypes.string.isRequired,
6671
initializeProblemEditor: PropTypes.func.isRequired,
6772
blockValue: PropTypes.objectOf(PropTypes.shape({})).isRequired,
@@ -70,8 +75,10 @@ ProblemEditor.propTypes = {
7075
export const mapStateToProps = (state) => ({
7176
blockFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }),
7277
blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }),
78+
studioViewFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }),
7379
problemType: selectors.problem.problemType(state),
7480
blockValue: selectors.app.blockValue(state),
81+
assetsFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchAssets }),
7582
advancedSettingsFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchAdvancedSettings }),
7683
});
7784

0 commit comments

Comments
 (0)