Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

feat: add missing items button #354

Merged
merged 3 commits into from
Oct 31, 2023
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
27 changes: 17 additions & 10 deletions src/library-authoring/author-library/LibraryAuthoringPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
DeleteOutline,
EditOutline,
HelpOutline,
Sync,
TextFields,
VideoCamera,
} from '@edx/paragon/icons';
Expand Down Expand Up @@ -301,21 +300,29 @@ BlockPreviewContainerBase.propTypes = {

const ButtonTogglesBase = ({ setShowPreviews, showPreviews, intl }) => (
<>
{/* todo: either reimplement the scroll to the add components button functionality,
figure out a better UX for the add component button at the top, or just
remove it entirely */}
{/* <Button variant="primary" className="mr-1" disabled={sending} onClick={quickAddBehavior} iconBefore={Add}>
{intl.formatMessage(messages[`library.detail.add_${library.type}`])}
</Button> */}
<Button
variant="primary"
variant="outline-primary"
className="ml-1"
onClick={() => setShowPreviews(!showPreviews)}
iconBefore={Sync}
size="sm"
>
{ intl.formatMessage(showPreviews ? messages['library.detail.hide_previews'] : messages['library.detail.show_previews']) }
</Button>
{/* todo: either replace the scroll to the add components button functionality
with a better UX for the add component button at the top, or just
remove it entirely */}
<Button
variant="primary"
className="mr-1"
size="sm"
onClick={() => {
const addComponentSection = document.getElementById('add-component-section');
addComponentSection.scrollIntoView({ behavior: 'smooth' });
}}
iconBefore={Add}
>
{intl.formatMessage(messages['library.detail.add.new.component.item'])}
</Button>
</>
);

Expand Down Expand Up @@ -540,7 +547,7 @@ export const LibraryAuthoringPageBase = ({
</Button>
)}
{library.type === LIBRARY_TYPES.COMPLEX && (
<Row>
<Row id="add-component-section">
<Col xs={12}>
<h3>{intl.formatMessage(messages['library.detail.add_component_heading'])}</h3>
</Col>
Expand Down
5 changes: 5 additions & 0 deletions src/library-authoring/author-library/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const messages = defineMessages({
defaultMessage: 'New component',
description: 'Text on the new component button.',
},
'library.detail.add.new.component.item': {
id: 'library.detail.add.new.component.item',
defaultMessage: 'Add library item',
description: 'Title on the add library item button',
},
'library.detail.add.new.component': {
id: 'library.detail.add.new.component',
defaultMessage: 'Add a new component',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ testSuite('<LibraryAuthoringPageContainer />', () => {
expect(localStorage.getItem('showPreviews')).toBe('false');
});

it('Add library button scrolls page', async () => {
const scrollIntoViewMock = jest.fn();
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
const library = libraryFactory();
const blocks = [blockFactory(undefined, { library })];
await render(library, genState(library, blocks));
screen.getAllByText('Add library item')[0].click();
expect(scrollIntoViewMock).toHaveBeenCalled();
});

it('Fetches block information', async () => {
const library = libraryFactory();
const blocks = [blockFactory({ id: 'testBlock' }, { library })];
Expand Down