Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit 3565741

Browse files
authored
fix image resize (#299)
Description: This is a bug where the image resizing in text editor and problem editor was completely broken. Putting in a text value when the aspect ratio lock was enabled would change both values but not to the size you wanted. If you disabled the lock, not just one but both values would change. This is a problem that mostly affects images that are rectangular, not square. There's an example image below which is one that caused problems on prod. Main fixes: when I keep the image ratio locked, I can change one value (like width) and the other will jump to the proportionate value, but rounded to full pixels. when I unlock the aspect ratio and change a value, then click save on the image dimension modal, only the one value will change, which will stretch the image in whatever direction. This is reflected in the tinymce image and then the updated value will appear when I reopen the image dimension modal. It is not possible to reset the image to the original dimensions any longer. The new values are saved. The image dimensions in the edit image settings modal should always reflect the actual dimensions of the image when I look at it e.g. in the course outline. (Otherwise I may click save and the image is squished.) There was a problem with deselecting an image: when you edit image dimensions and then save or press cancel, the "edit image" button will not disappear, but the image is not selected anymore. When you do not click anything else but immediately click on this button, sometimes (at least the second or third time you do this) this will throw an error. I fixed it so it will just open the default "select image" modal. Other requirements: Resizing the image means that when I open the dimensions update, I see the new dimensions. Images in the editor are now displayed with the correct dimensions, proportional or stretched, if those dimensions don't exceed the size of the editor. A known smaller bug emerging from this is that when you have more than one instance of the same image in the same editor, you cannot get or set its dimensions correctly. I believe I have gotten it into the following state: When you click one of the copies, you will either get the correct dimensions of the selected copy, or if not, it will display the original image dimensions. When you edit the dimensions, the correct copy of the image will be updated. Out of Scope: This cannot handle more than one instance of the same image properly. There will be a separate bug issue for this. Sometimes, when you edit image dimensions and then reopen the image dimension modal, the dimensions will be null and thus just not appear in the modal - randomly. This is a bug as well.
1 parent 4a5eaaf commit 3565741

File tree

27 files changed

+913
-237
lines changed

27 files changed

+913
-237
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const config = createConfig('eslint', {
1010
'react-hooks/rules-of-hooks': 2,
1111
'react-hooks/exhaustive-deps': 'off',
1212
'no-promise-executor-return': 'off',
13+
'no-param-reassign': ['error', { props: false }],
1314
radix: 'off',
1415
},
1516
});

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,12 +23,12 @@ exports[`SolutionWidget render snapshot: renders correct default 1`] = `
2323
/>
2424
</div>
2525
<[object Object]
26+
editorContentHtml="This is my question"
2627
editorType="solution"
2728
id="solution"
2829
minHeight={150}
2930
placeholder="Enter your explanation"
3031
setEditorRef={[MockFunction prepareEditorRef.setEditorRef]}
31-
textValue="This is my question"
3232
/>
3333
</div>
3434
`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const ExplanationWidget = ({
2828
id="solution"
2929
editorType="solution"
3030
editorRef={editorRef}
31-
textValue={settings?.solutionExplanation}
31+
editorContentHtml={settings?.solutionExplanation}
3232
setEditorRef={setEditorRef}
3333
minHeight={150}
3434
placeholder={intl.formatMessage(messages.placeholder)}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ exports[`QuestionWidget render snapshot: renders correct default 1`] = `
1414
/>
1515
</div>
1616
<[object Object]
17+
editorContentHtml="This is my question"
1718
editorType="question"
1819
id="question"
1920
minHeight={150}
2021
placeholder="Enter your question"
2122
setEditorRef={[MockFunction prepareEditorRef.setEditorRef]}
22-
textValue="This is my question"
2323
/>
2424
</div>
2525
`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const QuestionWidget = ({
2525
id="question"
2626
editorType="question"
2727
editorRef={editorRef}
28-
textValue={question}
28+
editorContentHtml={question}
2929
setEditorRef={setEditorRef}
3030
minHeight={150}
3131
placeholder={intl.formatMessage(messages.placeholder)}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const checkForSettingDiscrepancy = ({ problem, ref, openSaveWarningModal
124124
const problemSettings = reactSettingsParser.getSettings();
125125
const rawOlxSettings = reactSettingsParser.parseRawOlxSettings();
126126
let isMismatched = false;
127-
// console.log(rawOlxSettings);
127+
128128
Object.entries(rawOlxSettings).forEach(([key, value]) => {
129129
if (value !== problemSettings[key]) {
130130
isMismatched = true;

src/editors/containers/TextEditor/__snapshots__/index.test.jsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ exports[`TextEditor snapshots block failed to load, Toast is shown 1`] = `
3636
/>
3737
</Toast>
3838
<[object Object]
39+
editorContentHtml="eDiTablE Text"
3940
editorRef={
4041
Object {
4142
"current": Object {
@@ -48,7 +49,6 @@ exports[`TextEditor snapshots block failed to load, Toast is shown 1`] = `
4849
initializeEditor={[MockFunction args.intializeEditor]}
4950
minHeight={500}
5051
setEditorRef={[MockFunction hooks.prepareEditorRef.setEditorRef]}
51-
textValue="eDiTablE Text"
5252
/>
5353
</div>
5454
</EditorContainer>
@@ -194,6 +194,7 @@ exports[`TextEditor snapshots renders as expected with default behavior 1`] = `
194194
/>
195195
</Toast>
196196
<[object Object]
197+
editorContentHtml="eDiTablE Text"
197198
editorRef={
198199
Object {
199200
"current": Object {
@@ -206,7 +207,6 @@ exports[`TextEditor snapshots renders as expected with default behavior 1`] = `
206207
initializeEditor={[MockFunction args.intializeEditor]}
207208
minHeight={500}
208209
setEditorRef={[MockFunction hooks.prepareEditorRef.setEditorRef]}
209-
textValue="eDiTablE Text"
210210
/>
211211
</div>
212212
</EditorContainer>

src/editors/containers/TextEditor/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const TextEditor = ({
4848
<TinyMceWidget
4949
editorType="text"
5050
editorRef={editorRef}
51-
textValue={blockValue ? blockValue.data.data : ''}
51+
editorContentHtml={blockValue ? blockValue.data.data : ''}
5252
setEditorRef={setEditorRef}
5353
minHeight={500}
5454
height="100%"

src/editors/data/constants/tinyMCEStyles.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ const getStyles = () => (
198198
}
199199
.mce-content-body img {
200200
max-width: 100%;
201-
height: auto;
202201
}
203202
.mce-content-body pre {
204203
margin: 1em 0;

src/editors/sharedComponents/ExpandableTextArea/__snapshots__/index.test.jsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`ExpandableTextArea snapshots renders as expected with default behavior
66
className="expandable-mce error"
77
>
88
<TinyMceWidget
9+
editorContentHtml="text"
910
editorRef={
1011
Object {
1112
"current": null,
@@ -14,7 +15,6 @@ exports[`ExpandableTextArea snapshots renders as expected with default behavior
1415
editorType="expandable"
1516
placeholder={null}
1617
setEditorRef={[Function]}
17-
textValue="text"
1818
updateContent={[MockFunction]}
1919
/>
2020
</div>
@@ -27,6 +27,7 @@ exports[`ExpandableTextArea snapshots renders error message 1`] = `
2727
className="expandable-mce error"
2828
>
2929
<TinyMceWidget
30+
editorContentHtml="text"
3031
editorRef={
3132
Object {
3233
"current": null,
@@ -35,7 +36,6 @@ exports[`ExpandableTextArea snapshots renders error message 1`] = `
3536
editorType="expandable"
3637
placeholder={null}
3738
setEditorRef={[Function]}
38-
textValue="text"
3939
updateContent={[MockFunction]}
4040
/>
4141
</div>

0 commit comments

Comments
 (0)