From d99a09efba39aa8e70a44b910bf9a95e4ef2e1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Ch=C3=A1vez?= Date: Mon, 26 Aug 2024 15:33:54 -0500 Subject: [PATCH] fix: Library v2 info sidebar UI fixes (#1226) --- .../LibraryAuthoringPage.scss | 11 +++++++ .../LibraryAuthoringPage.test.tsx | 9 ++++-- .../LibraryAuthoringPage.tsx | 30 +++++++++++++++---- src/library-authoring/index.scss | 1 + .../library-info/LibraryInfoHeader.tsx | 4 ++- .../library-sidebar/LibrarySidebar.tsx | 2 ++ 6 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/library-authoring/LibraryAuthoringPage.scss diff --git a/src/library-authoring/LibraryAuthoringPage.scss b/src/library-authoring/LibraryAuthoringPage.scss new file mode 100644 index 000000000..3ce8cb718 --- /dev/null +++ b/src/library-authoring/LibraryAuthoringPage.scss @@ -0,0 +1,11 @@ +.library-authoring-page { + .header-actions { + .normal-border { + border: 1px solid; + } + + .open-border { + border: 2px solid; + } + } +} diff --git a/src/library-authoring/LibraryAuthoringPage.test.tsx b/src/library-authoring/LibraryAuthoringPage.test.tsx index 2481ce80e..b2fe866a0 100644 --- a/src/library-authoring/LibraryAuthoringPage.test.tsx +++ b/src/library-authoring/LibraryAuthoringPage.test.tsx @@ -370,17 +370,22 @@ describe('', () => { expect((await screen.findAllByText(libraryData.title))[0]).toBeInTheDocument(); expect((await screen.findAllByText(libraryData.title))[1]).toBeInTheDocument(); + // Open by default; close the library info sidebar const closeButton = screen.getByRole('button', { name: /close/i }); fireEvent.click(closeButton); - expect(screen.queryByText('Draft')).not.toBeInTheDocument(); expect(screen.queryByText('(Never Published)')).not.toBeInTheDocument(); + // Open library info sidebar with 'Library info' button const libraryInfoButton = screen.getByRole('button', { name: /library info/i }); fireEvent.click(libraryInfoButton); - expect(screen.getByText('Draft')).toBeInTheDocument(); expect(screen.getByText('(Never Published)')).toBeInTheDocument(); + + // CLose library info sidebar with 'Library info' button + fireEvent.click(libraryInfoButton); + expect(screen.queryByText('Draft')).not.toBeInTheDocument(); + expect(screen.queryByText('(Never Published)')).not.toBeInTheDocument(); }); it('show the "View All" button when viewing library with many components', async () => { diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index c2eb96929..c2cc8bc7f 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -1,4 +1,5 @@ import React, { useContext, useEffect } from 'react'; +import classNames from 'classnames'; import { StudioFooter } from '@edx/frontend-component-footer'; import { useIntl } from '@edx/frontend-platform/i18n'; import { @@ -33,7 +34,7 @@ import LibraryCollections from './LibraryCollections'; import LibraryHome from './LibraryHome'; import { useContentLibrary } from './data/apiHooks'; import { LibrarySidebar } from './library-sidebar'; -import { LibraryContext } from './common/context'; +import { LibraryContext, SidebarBodyComponentId } from './common/context'; import messages from './messages'; enum TabList { @@ -51,22 +52,41 @@ const HeaderActions = ({ canEditLibrary }: HeaderActionsProps) => { const { openAddContentSidebar, openInfoSidebar, + closeLibrarySidebar, + sidebarBodyComponent, } = useContext(LibraryContext); if (!canEditLibrary) { return null; } + const infoSidebarIsOpen = () => ( + sidebarBodyComponent === SidebarBodyComponentId.Info + ); + + const handleOnClickInfoSidebar = () => { + if (infoSidebarIsOpen()) { + closeLibrarySidebar(); + } else { + openInfoSidebar(); + } + }; + return ( - <> +
- +
); }; @@ -132,7 +152,7 @@ const LibraryAuthoringPage = () => { }; return ( - +
{ ) : ( <> - + {library.title} {library.canEditLibrary && ( @@ -75,6 +75,8 @@ const LibraryInfoHeader = ({ library } : LibraryInfoHeaderProps) => { iconAs={Icon} alt={intl.formatMessage(messages.editNameButtonAlt)} onClick={handleClick} + className="mt-1" + size="inline" /> )} diff --git a/src/library-authoring/library-sidebar/LibrarySidebar.tsx b/src/library-authoring/library-sidebar/LibrarySidebar.tsx index 314de8792..1f8afe782 100644 --- a/src/library-authoring/library-sidebar/LibrarySidebar.tsx +++ b/src/library-authoring/library-sidebar/LibrarySidebar.tsx @@ -49,11 +49,13 @@ const LibrarySidebar = ({ library }: LibrarySidebarProps) => { {buildHeader()}