Skip to content

Commit

Permalink
fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Oct 10, 2024
1 parent 545e67b commit 7e61a2c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const LibraryAuthoringPage = () => {
return <Loading />;
}

// istanbul ignore if: this should never happen
if (activeKey === undefined) {
return <NotFoundAlert />;
}
Expand Down
12 changes: 7 additions & 5 deletions src/library-authoring/collections/LibraryCollectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Stack direction="vertical">
<Stack direction="horizontal" gap={2}>
Expand All @@ -80,7 +82,7 @@ const SubHeaderTitle = ({
variant="primary"
/>
</Stack>
{!canEditLibrary && (
{showReadOnlyBadge && (
<div>
<Badge variant="primary" style={{ fontSize: '50%' }}>
{intl.formatMessage(messages.readOnlyBadge)}
Expand Down Expand Up @@ -134,6 +136,7 @@ const LibraryCollectionPage = () => {
if (isError) {
return <ErrorAlert error={error} />;
}

const breadcumbs = !componentPickerMode ? (
<Breadcrumb
ariaLabel={intl.formatMessage(messages.breadcrumbsAriaLabel)}
Expand All @@ -159,7 +162,7 @@ const LibraryCollectionPage = () => {
ariaLabel={intl.formatMessage(messages.breadcrumbsAriaLabel)}
links={[
{
label: '← Test',
label: intl.formatMessage(messages.returnToLibrarySelection),
onClick: () => { setCollectionId(undefined); },

Check warning on line 166 in src/library-authoring/collections/LibraryCollectionPage.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/collections/LibraryCollectionPage.tsx#L166

Added line #L166 was not covered by tests
},
]}
Expand Down Expand Up @@ -188,7 +191,6 @@ const LibraryCollectionPage = () => {
title={(
<SubHeaderTitle
title={collectionData.title}
canEditLibrary={libraryData.canEditLibrary}
infoClickHandler={() => openCollectionInfoSidebar(collectionId)}
/>
)}
Expand Down
5 changes: 5 additions & 0 deletions src/library-authoring/collections/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 5 additions & 5 deletions src/library-authoring/component-info/ComponentInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ const ComponentInfo = () => {
componentPickerMode,
} = useLibraryContext();

// istanbul ignore if: this should never happen
if (!usageKey) {
throw new Error('usageKey is required');
}

const {
mutate: addComponentToCourse,
isSuccess: addComponentToCourseSuccess,
isError: addComponentToCourseError,
} = useAddComponentToCourse();

if (addComponentToCourseSuccess) {
// TODO: Call endpoint to add component to course
window.parent.postMessage('closeComponentPicker', '*');

Check warning on line 43 in src/library-authoring/component-info/ComponentInfo.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentInfo.tsx#L43

Added line #L43 was not covered by tests
}

if (addComponentToCourseError) {
showToast(intl.formatMessage(messages.addComponentToCourseError));

Check warning on line 47 in src/library-authoring/component-info/ComponentInfo.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentInfo.tsx#L47

Added line #L47 was not covered by tests
}

if (!usageKey) {
return null;
}

const canEdit = canEditComponent(usageKey);

const handleAddComponentToCourse = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
1 change: 0 additions & 1 deletion src/library-authoring/components/ComponentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => {
} = useAddComponentToCourse();

if (addComponentToCourseSuccess) {
// TODO: Call endpoint to add component to course
window.parent.postMessage('closeComponentPicker', '*');

Check warning on line 97 in src/library-authoring/components/ComponentCard.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/components/ComponentCard.tsx#L97

Added line #L97 was not covered by tests
}

Expand Down
9 changes: 9 additions & 0 deletions src/library-authoring/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
6 changes: 5 additions & 1 deletion src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
restoreCollection,
setXBlockOLX,
getXBlockAssets,
addComponentToCourse,
} from './api';

export const libraryQueryPredicate = (query: Query, libraryId: string): boolean => {
Expand Down Expand Up @@ -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,
})
);

0 comments on commit 7e61a2c

Please sign in to comment.