Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show info banner in component picker [FC-0062] #1498

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/library-authoring/component-picker/ComponentPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,14 @@ describe('<ComponentPicker />', () => {

await waitFor(() => expect(onChange).toHaveBeenCalledWith([]));
});

it('should display an alert banner when showOnlyPublished is true', async () => {
render(<ComponentPicker />);

expect(await screen.findByText('Test Library 1')).toBeInTheDocument();
fireEvent.click(screen.getByDisplayValue(/lib:sampletaxonomyorg1:tl1/i));

// Wait for the content library to load
await screen.findByText(/Only published content is visible and available for reuse./i);
});
});
13 changes: 11 additions & 2 deletions src/library-authoring/component-picker/ComponentPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import { useLocation } from 'react-router-dom';
import { Stepper } from '@openedx/paragon';
import { Alert, Stepper } from '@openedx/paragon';
import { FormattedMessage } from '@edx/frontend-platform/i18n';

import {
type ComponentSelectedEvent,
Expand All @@ -11,6 +12,7 @@ import {
import LibraryAuthoringPage from '../LibraryAuthoringPage';
import LibraryCollectionPage from '../collections/LibraryCollectionPage';
import SelectLibrary from './SelectLibrary';
import messages from './messages';

interface LibraryComponentPickerProps {
returnToLibrarySelection: () => void;
Expand Down Expand Up @@ -65,6 +67,7 @@ export const ComponentPicker: React.FC<ComponentPickerProps> = ({

const queryParams = new URLSearchParams(location.search);
const variant = queryParams.get('variant') || 'draft';
const showOnlyPublished = variant === 'published';

const handleLibrarySelection = (library: string) => {
setCurrentStep('pick-components');
Expand Down Expand Up @@ -99,9 +102,15 @@ export const ComponentPicker: React.FC<ComponentPickerProps> = ({
<Stepper.Step eventKey="pick-components" title="Pick some components">
<LibraryProvider
libraryId={selectedLibrary}
showOnlyPublished={variant === 'published'}
showOnlyPublished={showOnlyPublished}
{...libraryProviderProps}
>
{ showOnlyPublished
&& (
<Alert variant="info" className="m-2">
<FormattedMessage {...messages.pickerInfoBanner} />
</Alert>
)}
<InnerComponentPicker returnToLibrarySelection={returnToLibrarySelection} />
</LibraryProvider>
</Stepper.Step>
Expand Down
5 changes: 5 additions & 0 deletions src/library-authoring/component-picker/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const messages = defineMessages({
defaultMessage: 'Next',
description: 'The text for the next button in the select library component',
},
pickerInfoBanner: {
id: 'course-authoring.library-authoring.pick-components.component-picker.information-alert',
defaultMessage: 'Only published content is visible and available for reuse.',
description: 'The alert text on top of component-picker if only published content is visible.',
},
});

export default messages;