From 7e61a2c70797fae18440bff5c99d9eda6e7c5d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Thu, 10 Oct 2024 19:18:11 -0300 Subject: [PATCH] fix: minor fixes --- src/library-authoring/LibraryAuthoringPage.tsx | 1 + .../collections/LibraryCollectionPage.tsx | 12 +++++++----- src/library-authoring/collections/messages.ts | 5 +++++ .../component-info/ComponentInfo.tsx | 10 +++++----- .../component-info/ComponentManagement.tsx | 1 + src/library-authoring/components/ComponentCard.tsx | 1 - src/library-authoring/data/api.ts | 9 +++++++++ src/library-authoring/data/apiHooks.ts | 6 +++++- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index 5d4c02909..9879ae6c4 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -167,6 +167,7 @@ const LibraryAuthoringPage = () => { return ; } + // istanbul ignore if: this should never happen if (activeKey === undefined) { return ; } diff --git a/src/library-authoring/collections/LibraryCollectionPage.tsx b/src/library-authoring/collections/LibraryCollectionPage.tsx index cd9360468..ed566933a 100644 --- a/src/library-authoring/collections/LibraryCollectionPage.tsx +++ b/src/library-authoring/collections/LibraryCollectionPage.tsx @@ -59,15 +59,17 @@ const HeaderActions = () => { const SubHeaderTitle = ({ title, - canEditLibrary, infoClickHandler, }: { title: string; - canEditLibrary: boolean; infoClickHandler: () => void; }) => { const intl = useIntl(); + const { readOnly, componentPickerMode } = useLibraryContext(); + + const showReadOnlyBadge = readOnly && !componentPickerMode; + return ( @@ -80,7 +82,7 @@ const SubHeaderTitle = ({ variant="primary" /> - {!canEditLibrary && ( + {showReadOnlyBadge && (
{intl.formatMessage(messages.readOnlyBadge)} @@ -134,6 +136,7 @@ const LibraryCollectionPage = () => { if (isError) { return ; } + const breadcumbs = !componentPickerMode ? ( { ariaLabel={intl.formatMessage(messages.breadcrumbsAriaLabel)} links={[ { - label: '← Test', + label: intl.formatMessage(messages.returnToLibrarySelection), onClick: () => { setCollectionId(undefined); }, }, ]} @@ -188,7 +191,6 @@ const LibraryCollectionPage = () => { title={( openCollectionInfoSidebar(collectionId)} /> )} diff --git a/src/library-authoring/collections/messages.ts b/src/library-authoring/collections/messages.ts index 5c5e0c03a..20a856006 100644 --- a/src/library-authoring/collections/messages.ts +++ b/src/library-authoring/collections/messages.ts @@ -126,6 +126,11 @@ const messages = defineMessages({ defaultMessage: 'Edit collection title', description: 'Alt text for edit collection title icon button', }, + returnToLibrarySelection: { + id: 'course-authoring.library-authoring.collection.component-picker.return-to-library-selection', + defaultMessage: '← Change Library', + description: 'Breadcrumbs link to return to library selection', + }, }); export default messages; diff --git a/src/library-authoring/component-info/ComponentInfo.tsx b/src/library-authoring/component-info/ComponentInfo.tsx index 815415286..0dca48eeb 100644 --- a/src/library-authoring/component-info/ComponentInfo.tsx +++ b/src/library-authoring/component-info/ComponentInfo.tsx @@ -28,6 +28,11 @@ const ComponentInfo = () => { componentPickerMode, } = useLibraryContext(); + // istanbul ignore if: this should never happen + if (!usageKey) { + throw new Error('usageKey is required'); + } + const { mutate: addComponentToCourse, isSuccess: addComponentToCourseSuccess, @@ -35,7 +40,6 @@ const ComponentInfo = () => { } = useAddComponentToCourse(); if (addComponentToCourseSuccess) { - // TODO: Call endpoint to add component to course window.parent.postMessage('closeComponentPicker', '*'); } @@ -43,10 +47,6 @@ const ComponentInfo = () => { showToast(intl.formatMessage(messages.addComponentToCourseError)); } - if (!usageKey) { - return null; - } - const canEdit = canEditComponent(usageKey); const handleAddComponentToCourse = () => { diff --git a/src/library-authoring/component-info/ComponentManagement.tsx b/src/library-authoring/component-info/ComponentManagement.tsx index 4804329d5..668280c22 100644 --- a/src/library-authoring/component-info/ComponentManagement.tsx +++ b/src/library-authoring/component-info/ComponentManagement.tsx @@ -15,6 +15,7 @@ const ComponentManagement = () => { const intl = useIntl(); const { sidebarComponentUsageKey: usageKey, readOnly } = useLibraryContext(); + // istanbul ignore if: this should never happen if (!usageKey) { throw new Error('usageKey is required'); } diff --git a/src/library-authoring/components/ComponentCard.tsx b/src/library-authoring/components/ComponentCard.tsx index ba1d634ef..44e0e5922 100644 --- a/src/library-authoring/components/ComponentCard.tsx +++ b/src/library-authoring/components/ComponentCard.tsx @@ -94,7 +94,6 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => { } = useAddComponentToCourse(); if (addComponentToCourseSuccess) { - // TODO: Call endpoint to add component to course window.parent.postMessage('closeComponentPicker', '*'); } diff --git a/src/library-authoring/data/api.ts b/src/library-authoring/data/api.ts index e08d4af72..d565881c7 100644 --- a/src/library-authoring/data/api.ts +++ b/src/library-authoring/data/api.ts @@ -378,3 +378,12 @@ export async function restoreCollection(libraryId: string, collectionId: string) const client = getAuthenticatedHttpClient(); await client.post(getLibraryCollectionRestoreApiUrl(libraryId, collectionId)); } + +/** + * Add a component to a course. + */ +// istanbul ignore next +export async function addComponentToCourse() { + // TODO: Call endpoint to add component to course + return Promise.resolve(); +} diff --git a/src/library-authoring/data/apiHooks.ts b/src/library-authoring/data/apiHooks.ts index 5aab7a449..082bc4f6f 100644 --- a/src/library-authoring/data/apiHooks.ts +++ b/src/library-authoring/data/apiHooks.ts @@ -34,6 +34,7 @@ import { restoreCollection, setXBlockOLX, getXBlockAssets, + addComponentToCourse, } from './api'; export const libraryQueryPredicate = (query: Query, libraryId: string): boolean => { @@ -373,8 +374,11 @@ export const useRestoreCollection = (libraryId: string, collectionId: string) => }); }; +/** + * Use this mutation to add a component to a course + */ export const useAddComponentToCourse = () => ( useMutation({ - mutationFn: async () => {}, + mutationFn: addComponentToCourse, }) );