Skip to content

Commit e39136c

Browse files
author
mashal-m
committed
Merge branch 'master' of https://github.com/openedx/frontend-app-ora into mashal-m/react-upgrade-to-v17
2 parents 9a28732 + 37f9043 commit e39136c

28 files changed

+6610
-1030
lines changed

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
coverage/*
22
dist/
33
node_modules/
4-
jest.config.js
4+
jest.config.js
5+
webpack.*.js
6+
.eslintrc.js

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
node-version: ${{ env.NODE_VER }}
2424
- name: Install dependencies
25-
run: npm ci
25+
run: npm ci --legacy-peer-deps
2626
- name: Lint
2727
run: npm run lint
2828
- name: Test

.github/workflows/commitlint.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ on:
77

88
jobs:
99
commitlint:
10-
uses: openedx/.github/.github/workflows/commitlint.yml@master
10+
runs-on: ubuntu-20.04
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
- name: remove tsconfig.json # see issue https://github.com/conventional-changelog/commitlint/issues/3256
17+
run: |
18+
rm tsconfig.json
19+
- name: Check commits
20+
uses: wagoid/commitlint-github-action@v5

jest.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { createConfig } = require('@edx/frontend-build');
22

3-
module.exports = createConfig('jest', {
3+
const config = createConfig('jest', {
44
// setupFilesAfterEnv is used after the jest environment has been loaded. In general this is what you want.
55
// If you want to add config BEFORE jest loads, use setupFiles instead.
66
setupFilesAfterEnv: [
@@ -11,3 +11,8 @@ module.exports = createConfig('jest', {
1111
'src/i18n',
1212
],
1313
});
14+
15+
config.moduleDirectories = ['node_modules', 'src'];
16+
// config.moduleNameMapper['@/(.*)'] = '<rootDir>/src/$1';
17+
18+
module.exports = config;

package-lock.json

Lines changed: 5761 additions & 823 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,25 @@
3434
},
3535
"dependencies": {
3636
"@edx/brand": "npm:@edx/[email protected]",
37-
"@edx/frontend-component-footer": "^12.1.2",
38-
"@edx/frontend-component-header": "^4.5.0",
39-
"@edx/frontend-platform": "^4.6.1",
40-
"@edx/paragon": "^20.45.0",
37+
"@edx/frontend-component-footer": "12.2.0",
38+
"@edx/frontend-component-header": "4.6.0",
39+
"@edx/frontend-platform": "4.5.1",
40+
"@edx/paragon": "^20.20.0",
4141
"@edx/react-unit-test-utils": "1.5.3",
4242
"@edx/tinymce-language-selector": "1.1.0",
43+
"@edx/typescript-config": "^1.0.1",
4344
"@fortawesome/fontawesome-svg-core": "1.2.36",
4445
"@fortawesome/free-brands-svg-icons": "5.15.4",
4546
"@fortawesome/free-regular-svg-icons": "5.15.4",
4647
"@fortawesome/free-solid-svg-icons": "5.15.4",
4748
"@fortawesome/react-fontawesome": "0.2.0",
4849
"@tanstack/react-query": "^4.29.25",
49-
"@tinymce/tinymce-react": "^3.14.0",
50+
"@tanstack/react-query-devtools": "^4.32.1",
51+
"@tinymce/tinymce-react": "3.8.4",
5052
"classnames": "^2.3.2",
5153
"core-js": "3.31.1",
5254
"filesize": "^8.0.6",
55+
"jest-when": "^3.6.0",
5356
"prop-types": "15.8.1",
5457
"query-string": "^8.1.0",
5558
"react": "^17.0.2",
@@ -65,10 +68,11 @@
6568
},
6669
"devDependencies": {
6770
"@edx/browserslist-config": "^1.1.1",
68-
"@edx/frontend-build": "12.9.4",
71+
"@edx/frontend-build": "12.9.0-alpha.6",
6972
"@edx/reactifex": "^2.1.1",
7073
"glob": "7.2.3",
7174
"husky": "7.0.4",
72-
"jest": "29.6.2"
75+
"jest": "29.6.2",
76+
"ts-jest": "^26.5.6"
7377
}
7478
}

src/components/TextResponse/Editor.jsx

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { Editor } from '@tinymce/tinymce-react';
5+
import 'tinymce/tinymce.min';
6+
import 'tinymce/icons/default';
7+
import 'tinymce/plugins/link';
8+
import 'tinymce/plugins/lists';
9+
import 'tinymce/plugins/code';
10+
import 'tinymce/plugins/image';
11+
import 'tinymce/themes/silver';
12+
import 'tinymce/skins/ui/oxide/skin.min.css';
13+
14+
import { StrictDict, useKeyedState } from '@edx/react-unit-test-utils';
15+
import { useIntl } from '@edx/frontend-platform/i18n';
16+
import messages from './messages';
17+
18+
export const stateKeys = StrictDict({
19+
value: 'value',
20+
});
21+
22+
const RichTextEditor = ({
23+
// id,
24+
initialValue,
25+
disabled,
26+
optional,
27+
}) => {
28+
const [value, setValue] = useKeyedState(stateKeys.value, initialValue);
29+
const { formatMessage } = useIntl();
30+
31+
const extraConfig = disabled ? {
32+
toolbar: false,
33+
readonly: 1,
34+
} : {
35+
// eslint-disable-next-line max-len
36+
toolbar: 'formatselect | bold italic underline | link blockquote image | numlist bullist outdent indent | strikethrough | code | undo redo',
37+
};
38+
39+
return (
40+
<div className="form-group">
41+
<label htmlFor="rich-text-response">
42+
{formatMessage(messages.yourResponse)} ({formatMessage(optional ? messages.optional : messages.required)})
43+
</label>
44+
<Editor
45+
name="rich-text-response"
46+
initialValue={value}
47+
init={{
48+
menubar: false,
49+
statusbar: false,
50+
skin: false,
51+
content_css: false,
52+
height: '300',
53+
schema: 'html5',
54+
plugins: 'code image link lists',
55+
...extraConfig,
56+
}}
57+
onChange={(e) => setValue(e.target.getContent())}
58+
disabled={disabled}
59+
/>
60+
</div>
61+
);
62+
};
63+
64+
RichTextEditor.defaultProps = {
65+
disabled: false,
66+
initialValue: '',
67+
optional: false,
68+
};
69+
70+
RichTextEditor.propTypes = {
71+
// id: PropTypes.string.isRequired,
72+
input: PropTypes.shape({
73+
value: PropTypes.string,
74+
name: PropTypes.string,
75+
onChange: PropTypes.func.isRequired,
76+
}).isRequired,
77+
meta: PropTypes.shape({
78+
touched: PropTypes.bool,
79+
submitFailed: PropTypes.bool,
80+
error: PropTypes.string,
81+
}).isRequired,
82+
disabled: PropTypes.bool,
83+
initialValue: PropTypes.string,
84+
optional: PropTypes.bool,
85+
};
86+
87+
export default RichTextEditor;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { useState } from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { TextArea } from '@edx/paragon';
5+
import { StrictDict } from '@edx/react-unit-test-utils';
6+
import { useIntl } from '@edx/frontend-platform/i18n';
7+
import messages from './messages';
8+
9+
export const stateKeys = StrictDict({
10+
value: 'value',
11+
});
12+
13+
const TextEditor = ({
14+
// id,
15+
initialValue,
16+
disabled,
17+
optional,
18+
}) => {
19+
const { formatMessage } = useIntl();
20+
const [value, setValue] = useState(initialValue);
21+
22+
return (
23+
<TextArea
24+
name="text-response"
25+
className="textarea-response"
26+
label={`
27+
${formatMessage(messages.yourResponse)} (${formatMessage(optional ? messages.optional : messages.required)})
28+
`}
29+
value={value}
30+
onChange={setValue}
31+
placeholder={formatMessage(messages.textResponsePlaceholder)}
32+
disabled={disabled}
33+
/>
34+
);
35+
};
36+
37+
TextEditor.defaultProps = {
38+
disabled: false,
39+
initialValue: '',
40+
optional: false,
41+
};
42+
43+
TextEditor.propTypes = {
44+
// id: PropTypes.string.isRequired,
45+
input: PropTypes.shape({
46+
value: PropTypes.string,
47+
name: PropTypes.string,
48+
onChange: PropTypes.func.isRequired,
49+
}).isRequired,
50+
meta: PropTypes.shape({
51+
touched: PropTypes.bool,
52+
submitFailed: PropTypes.bool,
53+
error: PropTypes.string,
54+
}).isRequired,
55+
disabled: PropTypes.bool,
56+
initialValue: PropTypes.string,
57+
optional: PropTypes.bool,
58+
};
59+
60+
export default TextEditor;

src/components/TextResponse/index.jsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import {
5-
// useSubmissionConfig,
6-
useSubmissionResponse,
5+
useSubmissionConfig,
6+
// useSubmissionResponse,
77
// useSubmissionStatus,
88
// useSubmissionTeamInfo,
99
} from 'data/services/lms/hooks/selectors';
1010

11-
export const TextResponse = ({
12-
promptIndex,
13-
}) => {
14-
// const config = useSubmissionConfig().textResponseConfig;
15-
const response = useSubmissionResponse();
16-
// const submissionStatus = useSubmissionStatus();
17-
// const teamInfo = useSubmissionTeamInfo();
11+
import TextEditor from 'components/TextResponse/TextEditor';
12+
import RichTextEditor from 'components/TextResponse/RichTextEditor';
13+
14+
import './index.scss';
15+
16+
export const TextResponse = () => {
17+
const { textResponseConfig } = useSubmissionConfig();
18+
const { optional, enabled } = textResponseConfig;
19+
const props = {
20+
optional,
21+
disabled: !enabled,
22+
};
23+
1824
return (
19-
<div>
20-
<h3>Text Response</h3>
21-
{response.textResponses[promptIndex]}
25+
<div className="mt-2">
26+
{
27+
textResponseConfig?.editorType === 'text' ? <TextEditor {...props} /> : <RichTextEditor {...props} />
28+
}
2229
</div>
2330
);
2431
};

0 commit comments

Comments
 (0)