Skip to content

Commit

Permalink
style: Nits on library authoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Sep 9, 2024
1 parent ac50a2f commit 36f2e8b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
7 changes: 5 additions & 2 deletions src/library-authoring/add-content/AddContentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const AddContentButton = ({ contentType, onCreateContent } : AddContentButtonPro
} = contentType;
return (
<Button
key={`add-content-${blockType}`}
variant="outline-primary"
disabled={disabled}
className="m-2 rounded-0"
Expand Down Expand Up @@ -163,7 +162,11 @@ const AddContentContainer = () => {
<AddContentButton contentType={collectionButtonData} onCreateContent={onCreateContent} />
<hr className="w-100 bg-gray-500" />
{contentTypes.map((contentType) => (
<AddContentButton contentType={contentType} onCreateContent={onCreateContent} />
<AddContentButton
key={`add-content-${contentType.blockType}`}
contentType={contentType}
onCreateContent={onCreateContent}
/>
))}
</Stack>
);
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/create-collection/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const messages = defineMessages({
createCollectionModalNameInvalid: {
id: 'course-authoring.library-authoring.modals.create-collection.form.name.invalid',
defaultMessage: 'Collection name is required',
description: 'Mesasge when the Name field of the Create Collection modal form is invalid',
description: 'Message when the Name field of the Create Collection modal form is invalid',
},
createCollectionModalNameConflict: {
id: 'course-authoring.library-authoring.modals.create-collection.form.name.conflict',
defaultMessage: 'There is another collection with the same name',
description: 'Mesasge when the Name field of the Create Collection modal form is not unique',
description: 'Message when the Name field of the Create Collection modal form is not unique',
},
createCollectionModalDescriptionLabel: {
id: 'course-authoring.library-authoring.modals.create-collection.form.description',
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/data/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ describe('library api calls', () => {

axiosMock.onPost(url).reply(200);

await createCollection({
await createCollection(libraryId, {
title: 'This is a test',
description: 'This is only a test',
}, libraryId);
});

expect(axiosMock.history.post[0].url).toEqual(url);
});
Expand Down
6 changes: 1 addition & 5 deletions src/library-authoring/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,7 @@ export async function updateXBlockFields(usageKey: string, xblockData: UpdateXBl
/**
* Create a library collection
*/
export async function createCollection(collectionData: CreateLibraryCollectionDataRequest, libraryId?: string) {
if (!libraryId) {
throw new Error('libraryId is required');
}

export async function createCollection(libraryId: string, collectionData: CreateLibraryCollectionDataRequest) {
const client = getAuthenticatedHttpClient();
const { data } = await client.post(getLibraryCollectionsApiUrl(libraryId), collectionData);

Expand Down
15 changes: 11 additions & 4 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
CreateLibraryCollectionDataRequest,
} from './api';

const libraryQueryPredicate = (query: Query, libraryId?: string): boolean => {
const libraryQueryPredicate = (query: Query, libraryId: string): boolean => {
// Invalidate all content queries related to this library.
// If we allow searching "all courses and libraries" in the future,
// then we'd have to invalidate all `["content_search", "results"]`
Expand Down Expand Up @@ -215,12 +215,19 @@ export const useUpdateXBlockFields = (contentLibraryId: string, usageKey: string
/**
* Use this mutation to create a library collection
*/
export const useCreateLibraryCollection = (libraryId?: string) => {
export const useCreateLibraryCollection = (libraryId: string | undefined) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: CreateLibraryCollectionDataRequest) => createCollection(data, libraryId),
mutationFn: (data: CreateLibraryCollectionDataRequest) => {
if (libraryId) {
return createCollection(libraryId, data);
}
return Promise.resolve();
},
onSettled: () => {
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
if (libraryId) {
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
}
},
});
};

0 comments on commit 36f2e8b

Please sign in to comment.