Skip to content

Commit cbec650

Browse files
refactor: replacing injectIntl with useIntl part 1 (#2296)
1 parent 654daa5 commit cbec650

File tree

14 files changed

+109
-123
lines changed

14 files changed

+109
-123
lines changed

src/course-checklist/AriaLiveRegion.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { injectIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
3+
import { FormattedMessage } from '@edx/frontend-platform/i18n';
44

55
import messages from './messages';
66

@@ -33,4 +33,4 @@ AriaLiveRegion.propTypes = {
3333
enableQuality: PropTypes.bool.isRequired,
3434
};
3535

36-
export default injectIntl(AriaLiveRegion);
36+
export default AriaLiveRegion;

src/course-checklist/ChecklistSection/ChecklistSection.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { injectIntl } from '@edx/frontend-platform/i18n';
43
import { Container, Stack } from '@openedx/paragon';
5-
64
import { LoadingSpinner } from '../../generic/Loading';
75
import { getCompletionCount, useChecklistState } from './hooks';
86
import ChecklistItemBody from './ChecklistItemBody';
@@ -129,4 +127,4 @@ ChecklistSection.propTypes = {
129127
isLoading: PropTypes.bool.isRequired,
130128
};
131129

132-
export default injectIntl(ChecklistSection);
130+
export default ChecklistSection;

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/ShowAnswerCard.jsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
4-
import { injectIntl, FormattedMessage, intlShape } from '@edx/frontend-platform/i18n';
4+
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
55
import { Form, Hyperlink } from '@openedx/paragon';
66
import SettingsOption from '../SettingsOption';
77
import { ShowAnswerTypes, ShowAnswerTypesKeys } from '../../../../../../data/constants/problem';
@@ -13,13 +13,12 @@ const ShowAnswerCard = ({
1313
showAnswer,
1414
updateSettings,
1515
defaultValue,
16-
// inject
17-
intl,
1816
// redux
1917
studioEndpointUrl,
2018
learningContextId,
2119
isLibrary,
2220
}) => {
21+
const intl = useIntl();
2322
const {
2423
handleShowAnswerChange,
2524
handleAttemptsChange,
@@ -90,7 +89,6 @@ const ShowAnswerCard = ({
9089
};
9190

9291
ShowAnswerCard.propTypes = {
93-
intl: intlShape.isRequired,
9492
// eslint-disable-next-line
9593
showAnswer: PropTypes.any.isRequired,
9694
solutionExplanation: PropTypes.string,
@@ -115,4 +113,4 @@ export const mapStateToProps = (state) => ({
115113
export const mapDispatchToProps = {};
116114

117115
export const ShowAnswerCardInternal = ShowAnswerCard; // For testing only
118-
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ShowAnswerCard));
116+
export default connect(mapStateToProps, mapDispatchToProps)(ShowAnswerCard);

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/ShowAnswerCard.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import {
33
render, screen, initializeMocks,
44
} from '@src/testUtils';
5-
import { formatMessage } from '@src/editors/testUtils';
65
import { selectors } from '../../../../../../data/redux';
76
import { ShowAnswerCardInternal as ShowAnswerCard, mapStateToProps, mapDispatchToProps } from './ShowAnswerCard';
87
import * as hooks from '../hooks';
@@ -25,15 +24,12 @@ describe('ShowAnswerCard', () => {
2524
on: 'after_attempts',
2625
afterAttempts: 5,
2726
updateSettings: jest.fn().mockName('args.updateSettings'),
28-
intl: { formatMessage },
2927
};
3028

3129
const props = {
3230
showAnswer,
3331
defaultValue: 'finished',
3432
updateSettings: jest.fn(),
35-
// injected
36-
intl: { formatMessage },
3733
// redux
3834
studioEndpointUrl: 'SoMEeNDpOinT',
3935
learningContextId: 'sOMEcouRseId',

src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { connect } from 'react-redux';
33
import PropTypes from 'prop-types';
44

5-
import { FormattedMessage, injectIntl } from '@edx/frontend-platform/i18n';
5+
import { FormattedMessage } from '@edx/frontend-platform/i18n';
66
import {
77
ActionRow,
88
Button,
@@ -58,4 +58,4 @@ export const mapDispatchToProps = {
5858
};
5959

6060
export const ImportTranscriptCardInternal = ImportTranscriptCard; // For testing only
61-
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ImportTranscriptCard));
61+
export default connect(mapStateToProps, mapDispatchToProps)(ImportTranscriptCard);

src/editors/example.jsx

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { connect } from 'react-redux';
1515
import PropTypes from 'prop-types';
1616

1717
import { Spinner } from '@openedx/paragon';
18-
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
18+
import { useIntl } from '@edx/frontend-platform/i18n';
1919

2020
import EditorContainer from '../EditorContainer';
2121
// This 'module' self-import hack enables mocking during tests.
@@ -32,48 +32,51 @@ export const hooks = {
3232
}),
3333
};
3434

35-
export const thumbEditor = ({
36-
onClose,
37-
// redux
38-
blockValue,
39-
lmsEndpointUrl,
40-
blockFailed,
41-
blockFinished,
42-
initializeEditor,
43-
// inject
44-
intl,
45-
}) => (
46-
<EditorContainer
47-
getContent={module.hooks.getContent}
48-
onClose={onClose}
49-
>
50-
<div className="editor-body h-75 overflow-auto">
51-
{!blockFinished
52-
? (
53-
<div className="text-center p-6">
54-
<Spinner
55-
animation="border"
56-
className="m-3"
57-
// Use a messages.js file for intl messages.
58-
screenreadertext={intl.formatMessage('Loading Spinner')}
59-
/>
60-
</div>
61-
)
62-
: (
63-
<p>
64-
Your Editor Goes here.
65-
You can get at the xblock data with the blockValue field.
66-
here is what is in your xblock: {JSON.stringify(blockValue)}
67-
</p>
68-
)}
69-
</div>
70-
</EditorContainer>
71-
);
72-
thumbEditor.defaultProps = {
35+
export const ThumbEditor = (
36+
{
37+
onClose,
38+
// redux
39+
blockValue,
40+
lmsEndpointUrl,
41+
blockFailed,
42+
blockFinished,
43+
initializeEditor,
44+
},
45+
) => {
46+
const intl = useIntl();
47+
return (
48+
<EditorContainer
49+
getContent={module.hooks.getContent}
50+
onClose={onClose}
51+
>
52+
<div className="editor-body h-75 overflow-auto">
53+
{!blockFinished
54+
? (
55+
<div className="text-center p-6">
56+
<Spinner
57+
animation="border"
58+
className="m-3"
59+
// Use a messages.js file for intl messages.
60+
screenreadertext={intl.formatMessage('Loading Spinner')}
61+
/>
62+
</div>
63+
)
64+
: (
65+
<p>
66+
Your Editor Goes here.
67+
You can get at the xblock data with the blockValue field.
68+
here is what is in your xblock: {JSON.stringify(blockValue)}
69+
</p>
70+
)}
71+
</div>
72+
</EditorContainer>
73+
);
74+
};
75+
ThumbEditor.defaultProps = {
7376
blockValue: null,
7477
lmsEndpointUrl: null,
7578
};
76-
thumbEditor.propTypes = {
79+
ThumbEditor.propTypes = {
7780
onClose: PropTypes.func.isRequired,
7881
// redux
7982
blockValue: PropTypes.shape({
@@ -83,8 +86,6 @@ thumbEditor.propTypes = {
8386
blockFailed: PropTypes.bool.isRequired,
8487
blockFinished: PropTypes.bool.isRequired,
8588
initializeEditor: PropTypes.func.isRequired,
86-
// inject
87-
intl: intlShape.isRequired,
8889
};
8990

9091
export const mapStateToProps = (state) => ({
@@ -98,4 +99,4 @@ export const mapDispatchToProps = {
9899
initializeEditor: actions.app.initializeEditor,
99100
};
100101

101-
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(thumbEditor));
102+
export default connect(mapStateToProps, mapDispatchToProps)(ThumbEditor);

src/editors/sharedComponents/ErrorBoundary/ErrorPage.jsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import PropTypes from 'prop-types';
33
import {
44
Button, Container, Row, Col,
55
} from '@openedx/paragon';
6-
7-
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
6+
import { useIntl } from '@edx/frontend-platform/i18n';
87
import messages from './messages';
98
import { isLibraryV1Key } from '../../../generic/key-utils';
109
import { navigateTo } from '../../hooks';
@@ -20,9 +19,8 @@ const ErrorPage = ({
2019
learningContextId,
2120
// redux
2221
unitData,
23-
// injected
24-
intl,
2522
}) => {
23+
const intl = useIntl();
2624
const outlineType = isLibraryV1Key(learningContextId) ? 'library' : 'course';
2725
const outlineUrl = `${studioEndpointUrl}/${outlineType}/${learningContextId}`;
2826
const unitUrl = unitData?.data ? `${studioEndpointUrl}/container/${unitData?.data.ancestors[0].id}` : null;
@@ -73,8 +71,6 @@ ErrorPage.propTypes = {
7371
),
7472
}),
7573
}),
76-
// injected
77-
intl: intlShape.isRequired,
7874
};
7975

8076
ErrorPage.defaultProps = {
@@ -87,4 +83,4 @@ export const mapStateToProps = (state) => ({
8783
});
8884

8985
export const ErrorPageInternal = ErrorPage; // For testing only
90-
export default injectIntl(connect(mapStateToProps)(ErrorPage));
86+
export default connect(mapStateToProps)(ErrorPage);

src/editors/sharedComponents/ErrorBoundary/ErrorPage.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { render, screen, initializeMocks } from '@src/testUtils';
3-
import { formatMessage } from '../../testUtils';
43
import { ErrorPageInternal as ErrorPage } from './ErrorPage';
54

65
jest.mock('../../data/redux', () => ({
@@ -15,13 +14,11 @@ describe('Editor Page', () => {
1514
const emptyProps = {
1615
learningContextId: 'course-v1:edX+DemoX+Demo_Course',
1716
studioEndpointUrl: 'fakeurl.com',
18-
intl: { formatMessage },
1917
};
2018
const passedProps = {
2119
learningContextId: 'course-v1:edX+DemoX+Demo_Course',
2220
studioEndpointUrl: 'fakeurl.com',
2321
message: 'cUStomMEssagE',
24-
intl: { formatMessage },
2522
};
2623
const unitData = {
2724
data: {

src/files-and-videos/generic/table-components/table-custom-columns/AccessColumn.jsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import React from 'react';
22
import { PropTypes } from 'prop-types';
33
import { Icon, OverlayTrigger, Tooltip } from '@openedx/paragon';
44
import { Locked, LockOpen } from '@openedx/paragon/icons';
5-
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
5+
import { useIntl } from '@edx/frontend-platform/i18n';
66
import messages from '../../messages';
77

8-
const AccessColumn = ({
9-
row,
10-
// injected
11-
intl,
12-
}) => {
8+
const AccessColumn = ({ row }) => {
9+
const intl = useIntl();
1310
const { locked } = row.original;
1411
return (
1512
<OverlayTrigger
@@ -35,8 +32,6 @@ AccessColumn.propTypes = {
3532
locked: PropTypes.bool.isRequired,
3633
}.isRequired,
3734
}.isRequired,
38-
// injected
39-
intl: intlShape.isRequired,
4035
};
4136

42-
export default injectIntl(AccessColumn);
37+
export default AccessColumn;

src/files-and-videos/videos-page/info-sidebar/transcript-item/TranscriptMenu.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
3-
import { FormattedMessage, injectIntl } from '@edx/frontend-platform/i18n';
3+
import { FormattedMessage } from '@edx/frontend-platform/i18n';
44
import {
55
Button,
66
Icon,
@@ -82,4 +82,4 @@ TranscriptActionMenu.propTypes = {
8282
}).isRequired,
8383
};
8484

85-
export default injectIntl(TranscriptActionMenu);
85+
export default TranscriptActionMenu;

0 commit comments

Comments
 (0)