Skip to content

Commit bbdf3d4

Browse files
committed
fix: fixes from merge
1 parent 08f550b commit bbdf3d4

File tree

5 files changed

+17
-40
lines changed

5 files changed

+17
-40
lines changed

src/library-authoring/add-content/AddContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const AddContent = () => {
208208
unitId,
209209
} = useLibraryContext();
210210
const addComponentsToCollectionMutation = useAddItemsToCollection(libraryId, collectionId);
211-
const addComponentsToContainerMutation = useAddComponentsToContainer(libraryId, unitId);
211+
const addComponentsToContainerMutation = useAddComponentsToContainer(unitId);
212212
const createBlockMutation = useCreateLibraryBlock();
213213
const pasteClipboardMutation = useLibraryPasteClipboard();
214214
const { showToast } = useContext(ToastContext);

src/library-authoring/containers/UnitInfo.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,14 @@ const UnitInfo = () => {
112112
);
113113
}, [hiddenTabs, defaultTab.unit, unitId]);
114114

115-
// istanbul ignore if: this should never happen
116-
if (!unitId) {
117-
throw new Error('unitId is required');
118-
}
119-
120115
useEffect(() => {
121116
// Show Organize tab if JumpToAddCollections action is set in sidebarComponentInfo
122117
if (jumpToCollections) {
123118
setSidebarTab(UNIT_INFO_TABS.Organize);
124119
}
125120
}, [jumpToCollections, setSidebarTab]);
126121

127-
if (!container) {
122+
if (!container || !unitId) {
128123
return null;
129124
}
130125

src/library-authoring/data/apiHooks.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,13 @@ describe('library api hooks', () => {
259259
});
260260

261261
it('should add components to container', async () => {
262-
const libraryId = 'lib:org:1';
263262
const componentId = 'lb:org:lib:html:1';
264263
const containerId = 'ltc:org:lib:unit:1';
265264

266265
const url = getLibraryContainerChildrenApiUrl(containerId);
267266

268267
axiosMock.onPost(url).reply(200);
269-
const { result } = renderHook(() => useAddComponentsToContainer(libraryId, containerId), { wrapper });
268+
const { result } = renderHook(() => useAddComponentsToContainer(containerId), { wrapper });
270269
await result.current.mutateAsync([componentId]);
271270

272271
expect(axiosMock.history.post[0].url).toEqual(url);

src/library-authoring/data/apiHooks.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,14 @@ export const libraryAuthoringQueryKeys = {
100100
'blockTypes',
101101
libraryId,
102102
],
103-
container: (libraryId?: string, containerId?: string) => [
103+
container: (containerId?: string) => [
104104
...libraryAuthoringQueryKeys.all,
105105
'container',
106-
libraryId,
107106
containerId,
108107
],
109-
containerChildren: (libraryId?: string, containerId?: string) => [
108+
containerChildren: (containerId?: string) => [
110109
...libraryAuthoringQueryKeys.all,
111110
'container',
112-
libraryId,
113111
containerId,
114112
'children',
115113
],
@@ -131,14 +129,6 @@ export const xblockQueryKeys = {
131129
componentDownstreamLinks: (usageKey: string) => [...xblockQueryKeys.xblock(usageKey), 'downstreamLinks'],
132130
};
133131

134-
export const containerQueryKeys = {
135-
all: ['container', 'children'],
136-
/**
137-
* Base key for data specific to a container
138-
*/
139-
container: (containerId?: string) => [...containerQueryKeys.all, containerId],
140-
};
141-
142132
/**
143133
* Tell react-query to refresh its cache of any data related to the given
144134
* component (XBlock).
@@ -276,7 +266,7 @@ export const useRevertLibraryChanges = () => {
276266
/**
277267
* Hook to fetch a content library's team members
278268
*/
279-
export const useLibraryTeam = (libraryId: string | undefined) => (
269+
export const useLibraryTeam = (libraryId?: string) => (
280270
useQuery({
281271
queryKey: libraryAuthoringQueryKeys.libraryTeam(libraryId),
282272
queryFn: () => getLibraryTeam(libraryId!),
@@ -287,7 +277,7 @@ export const useLibraryTeam = (libraryId: string | undefined) => (
287277
/**
288278
* Hook to fetch the list of XBlock types that can be added to this library.
289279
*/
290-
export const useBlockTypesMetadata = (libraryId: string | undefined) => (
280+
export const useBlockTypesMetadata = (libraryId?: string) => (
291281
useQuery({
292282
queryKey: libraryAuthoringQueryKeys.blockTypes(libraryId),
293283
queryFn: () => getBlockTypes(libraryId!),
@@ -612,7 +602,7 @@ export const useCreateLibraryContainer = (libraryId: string) => {
612602
export const useContainer = (containerId?: string) => (
613603
useQuery({
614604
enabled: !!containerId,
615-
queryKey: containerQueryKeys.container(containerId),
605+
queryKey: libraryAuthoringQueryKeys.container(containerId!),
616606
queryFn: () => getContainerMetadata(containerId!),
617607
})
618608
);
@@ -629,7 +619,7 @@ export const useUpdateContainer = (containerId: string) => {
629619
// NOTE: We invalidate the library query here because we need to update the library's
630620
// container list.
631621
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
632-
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.containerChildren(libraryId, containerId) });
622+
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.container(containerId) });
633623
},
634624
});
635625
};
@@ -666,19 +656,18 @@ export const useRestoreContainer = (containerId: string) => {
666656
/**
667657
* Get the metadata and children for a container in a library
668658
*/
669-
export const useContainerChildren = (containerId: string) => {
670-
const libraryId = getLibraryId(containerId);
671-
return useQuery({
659+
export const useContainerChildren = (containerId?: string) => (
660+
useQuery({
672661
enabled: !!containerId,
673-
queryKey: libraryAuthoringQueryKeys.containerChildren(libraryId, containerId),
662+
queryKey: libraryAuthoringQueryKeys.containerChildren(containerId),
674663
queryFn: () => getLibraryContainerChildren(containerId!),
675-
});
664+
})
676665
);
677666

678667
/**
679668
* Use this mutation to add components to a container
680669
*/
681-
export const useAddComponentsToContainer = (libraryId?: string, containerId?: string) => {
670+
export const useAddComponentsToContainer = (containerId?: string) => {
682671
const queryClient = useQueryClient();
683672
return useMutation({
684673
mutationFn: async (componentIds: string[]) => {
@@ -688,7 +677,7 @@ export const useAddComponentsToContainer = (libraryId?: string, containerId?: st
688677
return undefined;
689678
},
690679
onSettled: () => {
691-
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.containerChildren(libraryId, containerId) });
680+
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.containerChildren(containerId!) });
692681
},
693682
});
694683
};

src/library-authoring/units/LibraryUnitBlocks.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import TagCount from '../../generic/tag-count';
1818
import { useLibraryContext } from '../common/context/LibraryContext';
1919
import ComponentMenu from '../components';
2020
import { LibraryBlockMetadata } from '../data/api';
21-
import { containerQueryKeys, useContainerChildren } from '../data/apiHooks';
21+
import { libraryAuthoringQueryKeys, useContainerChildren } from '../data/apiHooks';
2222
import { LibraryBlock } from '../LibraryBlock';
2323
import { useLibraryRoutes } from '../routes';
2424
import messages from './messages';
@@ -42,11 +42,6 @@ export const LibraryUnitBlocks = () => {
4242
openAddContentSidebar,
4343
} = useSidebarContext();
4444

45-
// istanbul ignore if: this should never happen
46-
if (!unitId) {
47-
throw new Error('unitId is required');
48-
}
49-
5045
const queryClient = useQueryClient();
5146
const {
5247
data: blocks,
@@ -55,7 +50,6 @@ export const LibraryUnitBlocks = () => {
5550
error,
5651
} = useContainerChildren(unitId);
5752

58-
5953
useEffect(() => setOrderedBlocks(blocks || []), [blocks]);
6054

6155
if (isLoading) {
@@ -75,7 +69,7 @@ export const LibraryUnitBlocks = () => {
7569
};
7670

7771
const onTagSidebarClose = () => {
78-
queryClient.invalidateQueries(containerQueryKeys.children(unitId));
72+
queryClient.invalidateQueries(libraryAuthoringQueryKeys.containerChildren(unitId));
7973
closeManageTagsDrawer();
8074
};
8175

0 commit comments

Comments
 (0)