Skip to content

Commit 48ba65e

Browse files
feat: Add an error message when displaying a Course App Plugin fails
1 parent 0a0695b commit 48ba65e

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/pages-and-resources/PagesAndResources.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ const PagesAndResources = ({ courseId, intl }) => {
6666
</Hyperlink>
6767
</div>
6868

69-
<PageGrid pages={pages} />
70-
7169
<Routes>
7270
<Route path="discussion/configure/:appId" element={<PageWrap><DiscussionsSettings courseId={courseId} /></PageWrap>} />
7371
<Route path="discussion" element={<PageWrap><DiscussionsSettings courseId={courseId} /></PageWrap>} />
7472
<Route path="discussion/settings" element={<PageWrap><DiscussionsSettings courseId={courseId} /></PageWrap>} />
7573
<Route path=":appId/settings" element={<PageWrap><Suspense fallback="..."><SettingsComponent url={redirectUrl} /></Suspense></PageWrap>} />
7674
</Routes>
75+
76+
<PageGrid pages={pages} />
7777
</main>
7878
</PagesAndResourcesProvider>
7979
);

src/pages-and-resources/SettingsComponent.jsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { useParams, useNavigate } from 'react-router-dom';
4+
import { useIntl } from '@edx/frontend-platform/i18n';
5+
import { ErrorAlert } from '@edx/frontend-lib-content-components';
6+
7+
import messages from './messages';
48

59
const SettingsComponent = ({ url }) => {
610
const { appId } = useParams();
711
const navigate = useNavigate();
12+
const intl = useIntl();
813

9-
const LazyLoadedComponent = React.useMemo(() => React.lazy(async () => {
10-
try {
11-
// There seems to be a bug in babel-eslint that causes the checker to crash with the following error
12-
// if we use a template string here:
13-
// TypeError: Cannot read property 'range' of null with using template strings here.
14-
// Ref: https://github.com/babel/babel-eslint/issues/530
15-
return await import('@openedx-plugins/course-app-' + appId + '/Settings.jsx'); // eslint-disable-line
16-
} catch (error) {
17-
console.trace(error); // eslint-disable-line no-console
18-
return null;
19-
}
14+
const LazyLoadedComponent = React.useMemo(() => React.lazy(() => {
15+
return import(`@openedx-plugins/course-app-${appId}/Settings.jsx`).catch((err) => { // eslint-disable-line
16+
// If we couldn't load this plugin, log the details to the console.
17+
console.trace(err);
18+
return {
19+
default: () => <ErrorAlert isError={true}>{intl.formatMessage(messages.errorShowingConfiguration)}</ErrorAlert>,
20+
};
21+
});
2022
}), [appId]);
2123

2224
return <LazyLoadedComponent onClose={() => navigate(url)} />;

src/pages-and-resources/messages.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const messages = defineMessages({
1313
id: 'course-authoring.pages-resources.viewLive.button',
1414
defaultMessage: 'View live',
1515
},
16+
errorShowingConfiguration: {
17+
id: 'course-authoring.pages-resources.courseAppPlugin.errorMessage',
18+
defaultMessage: 'An error occurred when loading the configuration UI for that app.',
19+
},
1620
enabled: {
1721
id: 'course-authoring.badge.enabled',
1822
defaultMessage: 'Enabled',

0 commit comments

Comments
 (0)