Skip to content

Commit d7f006c

Browse files
committed
refactor: Migrate Help Urls to React Query
1 parent f9e09f0 commit d7f006c

9 files changed

Lines changed: 98 additions & 118 deletions

File tree

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
module.exports = {
2+
advanced: 'https://docs.openedx.org/en/latest/educators/navigation/advanced_features.html',
3+
certificates: 'https://docs.openedx.org/en/latest/educators/navigation/creating_course.html#set-up-course-certificates',
4+
checklist: 'https://docs.openedx.org/en/latest/educators/quickstarts/build_a_course.html#quick-start-build-a-course',
5+
container: 'https://docs.openedx.org/en/latest/educators/references/course_development/parent_child_components.html',
6+
contentGroups: 'https://docs.openedx.org/en/latest/educators/navigation/advanced_features.html#manage-course-cohorts',
7+
contentHighlights: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/manage_course_highlight_emails.html#set-course-section-highlights',
8+
contentLibraries: 'https://docs.openedx.org/en/latest/educators/navigation/content_creation_management.html#work-with-content-libraries',
29
default: 'https://docs.openedx.org/en/latest/educators/index.html',
3-
home: 'https://docs.openedx.org/en/latest/educators/navigation/content_creation_management.html',
4-
develop_course: 'https://docs.openedx.org/en/latest/educators/references/course_content_development.html',
5-
outline: 'https://docs.openedx.org/en/latest/educators/concepts/open_edx_platform/about_course_outline.html',
6-
unit: 'https://docs.openedx.org/en/latest/educators/concepts/open_edx_platform/about_course_units.html',
7-
visibility: 'https://docs.openedx.org/en/latest/educators/references/controlling_content_visibility.html',
8-
updates: 'https://docs.openedx.org/en/latest/educators/concepts/communication/about_course_updates_handouts.html',
9-
pages: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/manage_custom_page.html',
10+
developCourse: 'https://docs.openedx.org/en/latest/educators/references/course_content_development.html',
11+
enrollmentTracks: 'https://docs.openedx.org/en/latest/educators/how-tos/advanced_features/create_content_for_specific_enrollment_tracks.html',
12+
exportCourse: 'https://docs.openedx.org/en/latest/educators/how-tos/releasing-course/export_course.html',
13+
exportLibrary: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/export_import_library.html',
1014
files: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/manage_course_files.html',
11-
textbooks: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/manage_textbooks.html',
12-
schedule: 'https://docs.openedx.org/en/latest/educators/references/course_development/about_page.html',
1315
grading: 'https://docs.openedx.org/en/latest/educators/concepts/grading/about_graded_subsections.html',
14-
team_course: 'https://docs.openedx.org/en/latest/educators/references/course_development/course_team_roles.html#guide-to-course-team-roles',
15-
team_library: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/library_access.html',
16-
advanced: 'https://docs.openedx.org/en/latest/educators/navigation/advanced_features.html',
17-
checklist: 'https://docs.openedx.org/en/latest/educators/quickstarts/build_a_course.html#quick-start-build-a-course',
18-
import_library: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/export_import_library.html',
19-
import_course: 'https://docs.openedx.org/en/latest/educators/how-tos/releasing-course/import_course.html',
20-
export_library: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/export_import_library.html',
21-
export_course: 'https://docs.openedx.org/en/latest/educators/how-tos/releasing-course/export_course.html',
22-
welcome: 'https://docs.openedx.org/en/latest/educators/quickstarts/build_a_course.html#quick-start-build-a-course',
16+
groupConfigurations: 'https://docs.openedx.org/en/latest/educators/concepts/advanced_features/about_group_configurations.html',
17+
home: 'https://docs.openedx.org/en/latest/educators/navigation/content_creation_management.html',
18+
imageAccessibility: 'https://docs.openedx.org/en/latest/educators/references/imageAccessibility/image_accessibility.html',
19+
importCourse: 'https://docs.openedx.org/en/latest/educators/how-tos/releasing-course/import_course.html',
20+
importLibrary: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/export_import_library.html',
2321
login: 'https://docs.openedx.org/en/latest/educators/quickstarts/build_a_course.html#quick-start-build-a-course',
22+
outline: 'https://docs.openedx.org/en/latest/educators/concepts/open_edx_platform/about_course_outline.html',
23+
pages: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/manage_custom_page.html',
2424
register: 'https://docs.openedx.org/en/latest/educators/quickstarts/build_a_course.html#quick-start-build-a-course',
25-
content_libraries: 'https://docs.openedx.org/en/latest/educators/navigation/content_creation_management.html#work-with-content-libraries',
26-
content_groups: 'https://docs.openedx.org/en/latest/educators/navigation/advanced_features.html#manage-course-cohorts',
27-
enrollment_tracks: 'https://docs.openedx.org/en/latest/educators/how-tos/advanced_features/create_content_for_specific_enrollment_tracks.html',
28-
group_configurations: 'https://docs.openedx.org/en/latest/educators/concepts/advanced_features/about_group_configurations.html',
29-
container: 'https://docs.openedx.org/en/latest/educators/references/course_development/parent_child_components.html',
25+
schedule: 'https://docs.openedx.org/en/latest/educators/references/course_development/about_page.html',
26+
socialSharing: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/social_sharing.html',
27+
teamCourse: 'https://docs.openedx.org/en/latest/educators/references/course_development/course_team_roles.html#guide-to-course-team-roles',
28+
teamLibrary: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/library_access.html',
29+
textbooks: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/manage_textbooks.html',
30+
unit: 'https://docs.openedx.org/en/latest/educators/concepts/open_edx_platform/about_course_units.html',
31+
updates: 'https://docs.openedx.org/en/latest/educators/concepts/communication/about_course_updates_handouts.html',
3032
video: 'https://docs.openedx.org/en/latest/educators/navigation/content_creation_management.html#manage-video-components',
31-
certificates: 'https://docs.openedx.org/en/latest/educators/navigation/creating_course.html#set-up-course-certificates',
32-
content_highlights: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/manage_course_highlight_emails.html#set-course-section-highlights',
33-
image_accessibility: 'https://docs.openedx.org/en/latest/educators/references/accessibility/accessibility_best_practices_checklist.html#use-best-practices-for-describing-images',
34-
social_sharing: 'https://docs.openedx.org/en/latest/educators/how-tos/course_development/social_sharing.html',
33+
visibility: 'https://docs.openedx.org/en/latest/educators/references/controlling_content_visibility.html',
34+
welcome: 'https://docs.openedx.org/en/latest/educators/quickstarts/build_a_course.html#quick-start-build-a-course',
3535
};

src/help-urls/data/api.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/help-urls/data/api.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
2+
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
3+
4+
export const getHelpUrlsApiUrl = () => `${getConfig().STUDIO_BASE_URL}/api/contentstore/v1/help_urls`;
5+
6+
export interface HelpUrls {
7+
advanced: string;
8+
certificates: string;
9+
checklist: string;
10+
container: string;
11+
contentGroups: string;
12+
contentHighlights: string;
13+
contentLibraries: string;
14+
default: string;
15+
developCourse: string;
16+
enrollmentTracks: string;
17+
exportCourse: string;
18+
exportLibrary: string;
19+
files: string;
20+
grading: string;
21+
groupConfigurations: string;
22+
home: string;
23+
imageAccessibility: string;
24+
importCourse: string;
25+
importLibrary: string;
26+
login: string;
27+
outline: string;
28+
pages: string;
29+
register: string;
30+
schedule: string;
31+
socialSharing: string;
32+
teamCourse: string;
33+
teamLibrary: string;
34+
textbooks: string;
35+
unit: string;
36+
updates: string;
37+
video: string;
38+
visibility: string;
39+
welcome: string;
40+
}
41+
42+
export async function getHelpUrls(): Promise<HelpUrls> {
43+
const { data } = await getAuthenticatedHttpClient()
44+
.get(getHelpUrlsApiUrl());
45+
return camelCaseObject(data);
46+
}

src/help-urls/data/apiHooks.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
3+
import * as api from './api';
4+
5+
/**
6+
* Hook to fetch all help urls
7+
*/
8+
export const useAllHelpUrls = () => (
9+
useQuery({
10+
queryKey: ['helpURLs'],
11+
queryFn: api.getHelpUrls,
12+
})
13+
);

src/help-urls/data/selectors.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/help-urls/data/slice.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/help-urls/data/thunks.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/help-urls/hooks.jsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import { useEffect } from 'react';
2-
import { useDispatch, useSelector } from 'react-redux';
3-
import { isEmpty } from 'lodash';
4-
5-
import { fetchHelpUrls } from './data/thunks';
6-
import { getPages, selectHelpUrlsByNames } from './data/selectors';
1+
import { useAllHelpUrls } from './data/apiHooks';
72

83
const useHelpUrls = (tokenNames) => {
9-
const dispatch = useDispatch();
10-
const helpTokens = useSelector(selectHelpUrlsByNames(tokenNames));
11-
const pages = useSelector(getPages);
4+
const {
5+
data: pages,
6+
} = useAllHelpUrls();
7+
8+
const urlsDictionary = {};
129

13-
useEffect(() => {
14-
if (isEmpty(pages)) {
15-
dispatch(fetchHelpUrls());
16-
}
17-
}, []);
10+
if (pages) {
11+
tokenNames.forEach(name => {
12+
urlsDictionary[name] = pages[name] || null;
13+
});
14+
}
1815

19-
return helpTokens;
16+
return urlsDictionary;
2017
};
2118

2219
export { useHelpUrls };

src/store.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { reducer as filesReducer } from './files-and-videos/files-page/data/slic
1616
import { reducer as courseTeamReducer } from './course-team/data/slice';
1717
import { reducer as CourseUpdatesReducer } from './course-updates/data/slice';
1818
import { reducer as processingNotificationReducer } from './generic/processing-notification/data/slice';
19-
import { reducer as helpUrlsReducer } from './help-urls/data/slice';
2019
import { reducer as courseExportReducer } from './export-page/data/slice';
2120
import { reducer as courseOptimizerReducer } from './optimizer-page/data/slice';
2221
import { reducer as genericReducer } from './generic/data/slice';
@@ -50,7 +49,6 @@ export interface DeprecatedReduxState {
5049
courseTeam: Record<string, any>;
5150
courseUpdates: Record<string, any>;
5251
processingNotification: Record<string, any>;
53-
helpUrls: Record<string, any>;
5452
courseExport: Record<string, any>;
5553
courseOptimizer: Record<string, any>;
5654
generic: Record<string, any>;
@@ -81,7 +79,6 @@ export default function initializeStore(preloadedState: Partial<DeprecatedReduxS
8179
courseTeam: courseTeamReducer,
8280
courseUpdates: CourseUpdatesReducer,
8381
processingNotification: processingNotificationReducer,
84-
helpUrls: helpUrlsReducer,
8582
courseExport: courseExportReducer,
8683
courseOptimizer: courseOptimizerReducer,
8784
generic: genericReducer,

0 commit comments

Comments
 (0)