From 9062b528370a91038c785f7861fa6b4ae5c7da1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Thu, 10 Oct 2024 14:59:13 -0300 Subject: [PATCH] refactor: change context state names --- .../LibraryAuthoringPage.tsx | 6 +- src/library-authoring/LibraryLayout.tsx | 4 +- .../collections/CollectionDetails.test.tsx | 2 +- .../collections/CollectionDetails.tsx | 4 +- .../collections/CollectionInfo.tsx | 17 +++-- .../collections/CollectionInfoHeader.test.tsx | 2 +- .../collections/CollectionInfoHeader.tsx | 2 +- .../collections/LibraryCollectionPage.tsx | 4 +- src/library-authoring/common/context.tsx | 70 +++++++++++-------- .../component-info/ComponentDetails.test.tsx | 2 +- .../component-info/ComponentDetails.tsx | 2 +- .../component-info/ComponentInfo.test.tsx | 21 +++--- .../component-info/ComponentInfo.tsx | 2 +- .../ComponentInfoHeader.test.tsx | 2 +- .../component-info/ComponentInfoHeader.tsx | 2 +- .../ComponentManagement.test.tsx | 2 +- .../component-info/ComponentManagement.tsx | 2 +- .../component-info/ComponentPreview.test.tsx | 29 ++++++-- .../component-info/ComponentPreview.tsx | 2 +- .../components/CollectionCard.tsx | 6 +- 20 files changed, 111 insertions(+), 72 deletions(-) diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index d4f0583f6..61f035689 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -70,10 +70,6 @@ const HeaderActions = () => { readOnly, } = useLibraryContext(); - if (!readOnly) { - return null; - } - const infoSidebarIsOpen = () => ( sidebarBodyComponent === SidebarBodyComponentId.Info ); @@ -105,7 +101,7 @@ const HeaderActions = () => { iconBefore={Add} variant="primary rounded-0" onClick={openAddContentSidebar} - disabled={!canEditLibrary} + disabled={readOnly} > {intl.formatMessage(messages.newContentButton)} diff --git a/src/library-authoring/LibraryLayout.tsx b/src/library-authoring/LibraryLayout.tsx index 78d60674a..a37d3d040 100644 --- a/src/library-authoring/LibraryLayout.tsx +++ b/src/library-authoring/LibraryLayout.tsx @@ -11,7 +11,7 @@ import LibraryCollectionPage from './collections/LibraryCollectionPage'; import { ComponentEditorModal } from './components/ComponentEditorModal'; const LibraryLayout = () => { - const { libraryId } = useParams(); + const { libraryId, collectionId } = useParams(); if (libraryId === undefined) { // istanbul ignore next - This shouldn't be possible; it's just here to satisfy the type checker. @@ -19,7 +19,7 @@ const LibraryLayout = () => { } return ( - + baseRender(, { extraWrapper: ({ children }) => ( - + { children } ), diff --git a/src/library-authoring/collections/CollectionDetails.tsx b/src/library-authoring/collections/CollectionDetails.tsx index 7a63447dd..73f9f6959 100644 --- a/src/library-authoring/collections/CollectionDetails.tsx +++ b/src/library-authoring/collections/CollectionDetails.tsx @@ -37,7 +37,7 @@ const BlockCount = ({ }; const CollectionStatsWidget = () => { - const { libraryId, currentCollectionId: collectionId } = useLibraryContext(); + const { libraryId, sidebarCollectionId: collectionId } = useLibraryContext(); const { data: blockTypes } = useGetBlockTypes([ `context_key = "${libraryId}"`, @@ -98,7 +98,7 @@ const CollectionDetails = () => { const { showToast } = useContext(ToastContext); const { libraryId, - currentCollectionId: collectionId, + sidebarCollectionId: collectionId, readOnly, } = useLibraryContext(); diff --git a/src/library-authoring/collections/CollectionInfo.tsx b/src/library-authoring/collections/CollectionInfo.tsx index a7f4f8df4..03e7fe6b4 100644 --- a/src/library-authoring/collections/CollectionInfo.tsx +++ b/src/library-authoring/collections/CollectionInfo.tsx @@ -5,7 +5,8 @@ import { Tab, Tabs, } from '@openedx/paragon'; -import { Link, useMatch } from 'react-router-dom'; +import { useCallback } from 'react'; +import { useNavigate, useMatch } from 'react-router-dom'; import { useLibraryContext } from '../common/context'; import CollectionDetails from './CollectionDetails'; @@ -13,12 +14,21 @@ import messages from './messages'; const CollectionInfo = () => { const intl = useIntl(); + const navigate = useNavigate(); - const { libraryId, currentCollectionId: collectionId } = useLibraryContext(); + const { libraryId, sidebarCollectionId: collectionId, componentPickerMode } = useLibraryContext(); const url = `/library/${libraryId}/collection/${collectionId}/`; const urlMatch = useMatch(url); + const handleOpenCollection = useCallback(() => { + if (!componentPickerMode) { + navigate(url); + } else { + // FIXME: Set state here + } + }, [componentPickerMode, url]); + if (!collectionId) { return null; } @@ -28,8 +38,7 @@ const CollectionInfo = () => { {!urlMatch && (