Skip to content

Commit 3e4bcac

Browse files
committed
feat: Enable menus in component info sideber in unit page
1 parent 69f03ca commit 3e4bcac

16 files changed

Lines changed: 1057 additions & 48 deletions

File tree

plugins/course-apps/proctoring/Settings.test.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ describe('ProctoredExamSettings', () => {
7474
provider: null,
7575
});
7676

77+
axiosMock.onGet(/course_index/).reply(200, { sections: [] });
78+
7779
axiosMock.onGet(
7880
StudioApiService.getProctoredExamSettingsUrl(defaultProps.courseId),
7981
).reply(200, {
@@ -466,7 +468,8 @@ describe('ProctoredExamSettings', () => {
466468
// (1) for studio settings
467469
// (2) waffle flags
468470
// (3) for course details
469-
expect(axiosMock.history.get.length).toBe(3);
471+
// (4) for course outline index (from CourseAuthoringProvider)
472+
expect(axiosMock.history.get.length).toBe(4);
470473
expect(axiosMock.history.get[0].url.includes('proctored_exam_settings')).toEqual(true);
471474
});
472475

src/content-tags-drawer/data/apiHooks.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('useTaxonomyTagsData', () => {
7878
// Assert that useQueries was called with the correct arguments
7979
expect(useQueries).toHaveBeenCalledWith({
8080
queries: [
81-
{ queryKey: ['taxonomyTags', taxonomyId, null, 1, ''], queryFn: expect.any(Function), staleTime: Infinity },
81+
{ queryKey: ['contentTags', 'taxonomyTags', taxonomyId, null, 1, ''], queryFn: expect.any(Function), staleTime: Infinity },
8282
],
8383
});
8484

src/content-tags-drawer/data/apiHooks.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@ import { libraryAuthoringQueryKeys, libraryQueryPredicate, xblockQueryKeys } fro
2020
import { getLibraryId } from '../../generic/key-utils';
2121
import type { UpdateTagsData } from './types';
2222

23+
export const contentTagsQueryKeys = {
24+
all: ['contentTags'],
25+
taxonomyTags: (taxonomyId: number, parentTag: string | null, page: number, searchTerm: string) => [
26+
...contentTagsQueryKeys.all,
27+
'taxonomyTags',
28+
taxonomyId,
29+
parentTag,
30+
page,
31+
searchTerm,
32+
],
33+
contentTaxonomyTags: (contentId: string) => [
34+
...contentTagsQueryKeys.all,
35+
'contentTaxonomyTags',
36+
contentId,
37+
],
38+
contentData: (contentId?: string) => [
39+
...contentTagsQueryKeys.all,
40+
'contentData',
41+
contentId,
42+
],
43+
contentTagsCount: (contentPattern: string) => [
44+
...contentTagsQueryKeys.all,
45+
'contentTagsCount',
46+
contentPattern,
47+
],
48+
};
49+
2350
/**
2451
* Builds the query to get the taxonomy tags
2552
*/
@@ -43,7 +70,7 @@ export const useTaxonomyTagsData = (
4370
const queries: { queryKey: any[]; queryFn: typeof queryFn; staleTime: number }[] = [];
4471
for (let page = 1; page <= numPages; page++) {
4572
queries.push(
46-
{ queryKey: ['taxonomyTags', taxonomyId, parentTag, page, searchTerm], queryFn, staleTime: Infinity },
73+
{ queryKey: contentTagsQueryKeys.taxonomyTags(taxonomyId, parentTag, page, searchTerm), queryFn, staleTime: Infinity },
4774
);
4875
}
4976

@@ -74,7 +101,7 @@ export const useTaxonomyTagsData = (
74101

75102
// Store the pre-loaded descendants into the query cache:
76103
preLoadedData.forEach((tags, parentValue) => {
77-
const queryKey = ['taxonomyTags', taxonomyId, parentValue, 1, searchTerm];
104+
const queryKey = contentTagsQueryKeys.taxonomyTags(taxonomyId, parentValue, 1, searchTerm);
78105
const cachedData: TagListData = {
79106
next: '',
80107
previous: '',
@@ -106,7 +133,7 @@ export const useTaxonomyTagsData = (
106133
*/
107134
export const useContentTaxonomyTagsData = (contentId: string) => (
108135
useQuery({
109-
queryKey: ['contentTaxonomyTags', contentId],
136+
queryKey: contentTagsQueryKeys.contentTaxonomyTags(contentId),
110137
queryFn: () => getContentTaxonomyTagsData(contentId),
111138
})
112139
);
@@ -118,7 +145,7 @@ export const useContentTaxonomyTagsData = (contentId: string) => (
118145
*/
119146
export const useContentData = (contentId?: string, enabled: boolean = true) => (
120147
useQuery({
121-
queryKey: ['contentData', contentId],
148+
queryKey: contentTagsQueryKeys.contentData(contentId),
122149
queryFn: (enabled && contentId) ? () => getContentData(contentId) : skipToken,
123150
})
124151
);
@@ -137,15 +164,15 @@ export const useContentTaxonomyTagsUpdater = (contentId: string) => {
137164
updateContentTaxonomyTags(contentId, tagsData)
138165
),
139166
onSettled: () => {
140-
queryClient.invalidateQueries({ queryKey: ['contentTaxonomyTags', contentId] });
167+
queryClient.invalidateQueries({ queryKey: contentTagsQueryKeys.contentTaxonomyTags(contentId) });
141168
/// Invalidate query with pattern on course outline
142169
let contentPattern;
143170
if (contentId.includes('course-v1')) {
144171
contentPattern = contentId;
145172
} else {
146173
contentPattern = contentId.replace(/\+type@.*$/, '*');
147174
}
148-
queryClient.invalidateQueries({ queryKey: ['contentTagsCount', contentPattern] });
175+
queryClient.invalidateQueries({ queryKey: contentTagsQueryKeys.contentTagsCount(contentPattern) });
149176
if (contentId.startsWith('lb:') || contentId.startsWith('lib-collection:') || contentId.startsWith('lct:')) {
150177
// Obtain library id from contentId
151178
const libraryId = getLibraryId(contentId);

src/course-outline/outline-sidebar/OutlineSidebar.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jest.mock('@src/course-outline/data/apiHooks', () => ({
1515
useCourseDetails: jest.fn().mockReturnValue({ isPending: false, data: { title: 'Test Course' } }),
1616
useCreateCourseBlock: jest.fn(),
1717
useCourseItemData: jest.fn().mockReturnValue({ data: {} }),
18+
useDuplicateItem: jest.fn().mockReturnValue({ duplicateItem: jest.fn() }),
19+
useDeleteCourseItem: jest.fn().mockReturnValue({ mutateAsync: jest.fn() }),
1820
}));
1921

2022
const courseId = '123';

src/course-outline/outline-sidebar/info-sidebar/InfoSection.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export const InfoSection = ({ itemId }: Props) => {
5454
}
5555
}, [dispatch, selectedContainerState, queryClient, courseId]);
5656

57+
/* istanbul ignore next */
58+
if (!itemData) {
59+
return null;
60+
}
61+
5762
return (
5863
<>
5964
<LibraryReferenceCard

0 commit comments

Comments
 (0)