From 3662b8294a5e2dee1300f5a035e3dcc7e2648a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Fri, 29 Nov 2024 16:32:10 -0300 Subject: [PATCH] refactor: move context files --- src/library-authoring/EmptyStates.tsx | 2 +- .../LibraryAuthoringPage.tsx | 3 +- src/library-authoring/LibraryContent.test.tsx | 2 +- src/library-authoring/LibraryContent.tsx | 2 +- src/library-authoring/LibraryLayout.tsx | 2 +- .../add-content/AddContentContainer.test.tsx | 2 +- .../add-content/AddContentContainer.tsx | 2 +- .../PickLibraryContentModal.test.tsx | 2 +- .../add-content/PickLibraryContentModal.tsx | 3 +- .../collections/CollectionDetails.test.tsx | 2 +- .../collections/CollectionDetails.tsx | 2 +- .../collections/CollectionInfo.tsx | 5 +- .../collections/CollectionInfoHeader.test.tsx | 2 +- .../collections/CollectionInfoHeader.tsx | 2 +- .../LibraryCollectionComponents.tsx | 2 +- .../collections/LibraryCollectionPage.tsx | 3 +- .../common/context/ComponentPickerContext.tsx | 163 +++++++++++++++++ .../LibraryContext.tsx} | 172 +----------------- .../ComponentAdvancedAssets.tsx | 2 +- .../ComponentAdvancedInfo.test.tsx | 2 +- .../component-info/ComponentAdvancedInfo.tsx | 2 +- .../component-info/ComponentDetails.test.tsx | 2 +- .../component-info/ComponentDetails.tsx | 2 +- .../component-info/ComponentInfo.test.tsx | 2 +- .../component-info/ComponentInfo.tsx | 6 +- .../ComponentInfoHeader.test.tsx | 2 +- .../component-info/ComponentInfoHeader.tsx | 2 +- .../ComponentManagement.test.tsx | 2 +- .../component-info/ComponentManagement.tsx | 2 +- .../component-info/ComponentPreview.test.tsx | 4 +- .../component-info/ComponentPreview.tsx | 2 +- .../component-info/ManageCollections.test.tsx | 2 +- .../component-info/ManageCollections.tsx | 2 +- .../component-picker/ComponentPicker.tsx | 6 +- .../components/CollectionCard.test.tsx | 2 +- .../components/CollectionCard.tsx | 3 +- .../components/ComponentCard.test.tsx | 2 +- .../components/ComponentCard.tsx | 3 +- .../components/ComponentDeleter.test.tsx | 2 +- .../components/ComponentDeleter.tsx | 2 +- .../components/ComponentEditorModal.tsx | 2 +- .../CreateCollectionModal.tsx | 2 +- .../PreviewChangesEmbed.tsx | 2 +- .../library-info/LibraryInfo.test.tsx | 2 +- .../library-info/LibraryInfo.tsx | 2 +- .../library-info/LibraryInfoHeader.test.tsx | 2 +- .../library-info/LibraryInfoHeader.tsx | 2 +- .../library-info/LibraryPublishStatus.tsx | 2 +- .../library-sidebar/LibrarySidebar.tsx | 2 +- .../library-team/LibraryTeam.test.tsx | 2 +- .../library-team/LibraryTeam.tsx | 2 +- .../library-team/LibraryTeamModal.tsx | 2 +- 52 files changed, 235 insertions(+), 218 deletions(-) create mode 100644 src/library-authoring/common/context/ComponentPickerContext.tsx rename src/library-authoring/common/{context.tsx => context/LibraryContext.tsx} (60%) diff --git a/src/library-authoring/EmptyStates.tsx b/src/library-authoring/EmptyStates.tsx index 71297926de..ac69e56d16 100644 --- a/src/library-authoring/EmptyStates.tsx +++ b/src/library-authoring/EmptyStates.tsx @@ -6,7 +6,7 @@ import { import { Add } from '@openedx/paragon/icons'; import { ClearFiltersButton } from '../search-manager'; import messages from './messages'; -import { useLibraryContext } from './common/context'; +import { useLibraryContext } from './common/context/LibraryContext'; export const NoComponents = ({ infoText = messages.noComponents, diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index 46fe733a9d..e314295c8e 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -37,7 +37,8 @@ import { } from '../search-manager'; import LibraryContent, { ContentType } from './LibraryContent'; import { LibrarySidebar } from './library-sidebar'; -import { SidebarBodyComponentId, useLibraryContext, useComponentPickerContext } from './common/context'; +import { SidebarBodyComponentId, useLibraryContext } from './common/context/LibraryContext'; +import { useComponentPickerContext } from './common/context/ComponentPickerContext'; import messages from './messages'; const HeaderActions = () => { diff --git a/src/library-authoring/LibraryContent.test.tsx b/src/library-authoring/LibraryContent.test.tsx index d7b49320ee..2c7f869aa1 100644 --- a/src/library-authoring/LibraryContent.test.tsx +++ b/src/library-authoring/LibraryContent.test.tsx @@ -9,7 +9,7 @@ import { import { getContentSearchConfigUrl } from '../search-manager/data/api'; import { mockContentLibrary } from './data/api.mocks'; import mockEmptyResult from '../search-modal/__mocks__/empty-search-result.json'; -import { LibraryProvider } from './common/context'; +import { LibraryProvider } from './common/context/LibraryContext'; import LibraryContent from './LibraryContent'; import { libraryComponentsMock } from './__mocks__'; diff --git a/src/library-authoring/LibraryContent.tsx b/src/library-authoring/LibraryContent.tsx index 15049e25b6..8befeb7cd6 100644 --- a/src/library-authoring/LibraryContent.tsx +++ b/src/library-authoring/LibraryContent.tsx @@ -2,7 +2,7 @@ import { useEffect } from 'react'; import { LoadingSpinner } from '../generic/Loading'; import { useSearchContext } from '../search-manager'; import { NoComponents, NoSearchResults } from './EmptyStates'; -import { useLibraryContext } from './common/context'; +import { useLibraryContext } from './common/context/LibraryContext'; import CollectionCard from './components/CollectionCard'; import ComponentCard from './components/ComponentCard'; import { useLoadOnScroll } from '../hooks'; diff --git a/src/library-authoring/LibraryLayout.tsx b/src/library-authoring/LibraryLayout.tsx index 04bfc25c64..c29ecce754 100644 --- a/src/library-authoring/LibraryLayout.tsx +++ b/src/library-authoring/LibraryLayout.tsx @@ -6,7 +6,7 @@ import { } from 'react-router-dom'; import LibraryAuthoringPage from './LibraryAuthoringPage'; -import { LibraryProvider } from './common/context'; +import { LibraryProvider } from './common/context/LibraryContext'; import { CreateCollectionModal } from './create-collection'; import { LibraryTeamModal } from './library-team'; import LibraryCollectionPage from './collections/LibraryCollectionPage'; diff --git a/src/library-authoring/add-content/AddContentContainer.test.tsx b/src/library-authoring/add-content/AddContentContainer.test.tsx index 9bf9a5368e..2f233629cd 100644 --- a/src/library-authoring/add-content/AddContentContainer.test.tsx +++ b/src/library-authoring/add-content/AddContentContainer.test.tsx @@ -12,7 +12,7 @@ import { getContentLibraryApiUrl, getCreateLibraryBlockUrl, getLibraryCollectionComponentApiUrl, getLibraryPasteClipboardUrl, } from '../data/api'; import { mockBroadcastChannel, mockClipboardEmpty, mockClipboardHtml } from '../../generic/data/api.mock'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import AddContentContainer from './AddContentContainer'; import { ComponentEditorModal } from '../components/ComponentEditorModal'; import editorCmsApi from '../../editors/data/services/cms/api'; diff --git a/src/library-authoring/add-content/AddContentContainer.tsx b/src/library-authoring/add-content/AddContentContainer.tsx index 4837d269c0..1a2e28b1a9 100644 --- a/src/library-authoring/add-content/AddContentContainer.tsx +++ b/src/library-authoring/add-content/AddContentContainer.tsx @@ -25,7 +25,7 @@ import { ToastContext } from '../../generic/toast-context'; import { useCopyToClipboard } from '../../generic/clipboard'; import { getCanEdit } from '../../course-unit/data/selectors'; import { useCreateLibraryBlock, useLibraryPasteClipboard, useAddComponentsToCollection } from '../data/apiHooks'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { canEditComponent } from '../components/ComponentEditorModal'; import { PickLibraryContentModal } from './PickLibraryContentModal'; diff --git a/src/library-authoring/add-content/PickLibraryContentModal.test.tsx b/src/library-authoring/add-content/PickLibraryContentModal.test.tsx index a179dff4b6..f5d3606c5d 100644 --- a/src/library-authoring/add-content/PickLibraryContentModal.test.tsx +++ b/src/library-authoring/add-content/PickLibraryContentModal.test.tsx @@ -9,7 +9,7 @@ import { import { studioHomeMock } from '../../studio-home/__mocks__'; import { getStudioHomeApiUrl } from '../../studio-home/data/api'; import mockResult from '../__mocks__/library-search.json'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import { ComponentPicker } from '../component-picker'; import * as api from '../data/api'; import { diff --git a/src/library-authoring/add-content/PickLibraryContentModal.tsx b/src/library-authoring/add-content/PickLibraryContentModal.tsx index f96723a841..e5977d2407 100644 --- a/src/library-authoring/add-content/PickLibraryContentModal.tsx +++ b/src/library-authoring/add-content/PickLibraryContentModal.tsx @@ -3,7 +3,8 @@ import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; import { ActionRow, Button, StandardModal } from '@openedx/paragon'; import { ToastContext } from '../../generic/toast-context'; -import { type SelectedComponent, useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; +import type { SelectedComponent } from '../common/context/ComponentPickerContext'; import { useAddComponentsToCollection } from '../data/apiHooks'; import messages from './messages'; diff --git a/src/library-authoring/collections/CollectionDetails.test.tsx b/src/library-authoring/collections/CollectionDetails.test.tsx index e2651a1395..da031ee64d 100644 --- a/src/library-authoring/collections/CollectionDetails.test.tsx +++ b/src/library-authoring/collections/CollectionDetails.test.tsx @@ -10,7 +10,7 @@ import { waitFor, within, } from '../../testUtils'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import * as api from '../data/api'; import { mockContentLibrary, mockGetCollectionMetadata } from '../data/api.mocks'; import CollectionDetails from './CollectionDetails'; diff --git a/src/library-authoring/collections/CollectionDetails.tsx b/src/library-authoring/collections/CollectionDetails.tsx index 07a883dea5..1b205bcc6e 100644 --- a/src/library-authoring/collections/CollectionDetails.tsx +++ b/src/library-authoring/collections/CollectionDetails.tsx @@ -6,7 +6,7 @@ import classNames from 'classnames'; import { getItemIcon } from '../../generic/block-type-utils'; import { ToastContext } from '../../generic/toast-context'; import { BlockTypeLabel, useGetBlockTypes } from '../../search-manager'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useCollection, useUpdateCollection } from '../data/apiHooks'; import HistoryWidget from '../generic/history-widget'; import messages from './messages'; diff --git a/src/library-authoring/collections/CollectionInfo.tsx b/src/library-authoring/collections/CollectionInfo.tsx index 6f9199e3c5..04eb24ebd5 100644 --- a/src/library-authoring/collections/CollectionInfo.tsx +++ b/src/library-authoring/collections/CollectionInfo.tsx @@ -7,15 +7,14 @@ import { } from '@openedx/paragon'; import { useCallback } from 'react'; import { useNavigate, useMatch } from 'react-router-dom'; - +import { useComponentPickerContext } from '../common/context/ComponentPickerContext'; import { - useComponentPickerContext, useLibraryContext, type CollectionInfoTab, COLLECTION_INFO_TABS, isCollectionInfoTab, COMPONENT_INFO_TABS, -} from '../common/context'; +} from '../common/context/LibraryContext'; import CollectionDetails from './CollectionDetails'; import messages from './messages'; import { ContentTagsDrawer } from '../../content-tags-drawer'; diff --git a/src/library-authoring/collections/CollectionInfoHeader.test.tsx b/src/library-authoring/collections/CollectionInfoHeader.test.tsx index 7e1b7af374..12bacd4578 100644 --- a/src/library-authoring/collections/CollectionInfoHeader.test.tsx +++ b/src/library-authoring/collections/CollectionInfoHeader.test.tsx @@ -8,7 +8,7 @@ import { screen, waitFor, } from '../../testUtils'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import { mockContentLibrary, mockGetCollectionMetadata } from '../data/api.mocks'; import * as api from '../data/api'; import CollectionInfoHeader from './CollectionInfoHeader'; diff --git a/src/library-authoring/collections/CollectionInfoHeader.tsx b/src/library-authoring/collections/CollectionInfoHeader.tsx index 83be4c2139..2a6b4ab591 100644 --- a/src/library-authoring/collections/CollectionInfoHeader.tsx +++ b/src/library-authoring/collections/CollectionInfoHeader.tsx @@ -9,7 +9,7 @@ import { import { Edit } from '@openedx/paragon/icons'; import { ToastContext } from '../../generic/toast-context'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useCollection, useUpdateCollection } from '../data/apiHooks'; import messages from './messages'; diff --git a/src/library-authoring/collections/LibraryCollectionComponents.tsx b/src/library-authoring/collections/LibraryCollectionComponents.tsx index 87dacd3ab3..732dbf744e 100644 --- a/src/library-authoring/collections/LibraryCollectionComponents.tsx +++ b/src/library-authoring/collections/LibraryCollectionComponents.tsx @@ -2,7 +2,7 @@ import { Stack } from '@openedx/paragon'; import { NoComponents, NoSearchResults } from '../EmptyStates'; import { useSearchContext } from '../../search-manager'; import messages from './messages'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import LibraryContent, { ContentType } from '../LibraryContent'; const LibraryCollectionComponents = () => { diff --git a/src/library-authoring/collections/LibraryCollectionPage.tsx b/src/library-authoring/collections/LibraryCollectionPage.tsx index 4106285671..21944714d9 100644 --- a/src/library-authoring/collections/LibraryCollectionPage.tsx +++ b/src/library-authoring/collections/LibraryCollectionPage.tsx @@ -27,7 +27,8 @@ import { SearchSortWidget, } from '../../search-manager'; import { useCollection, useContentLibrary } from '../data/apiHooks'; -import { useComponentPickerContext, useLibraryContext } from '../common/context'; +import { useComponentPickerContext } from '../common/context/ComponentPickerContext'; +import { useLibraryContext } from '../common/context/LibraryContext'; import messages from './messages'; import { LibrarySidebar } from '../library-sidebar'; import LibraryCollectionComponents from './LibraryCollectionComponents'; diff --git a/src/library-authoring/common/context/ComponentPickerContext.tsx b/src/library-authoring/common/context/ComponentPickerContext.tsx new file mode 100644 index 0000000000..d1ce9b807b --- /dev/null +++ b/src/library-authoring/common/context/ComponentPickerContext.tsx @@ -0,0 +1,163 @@ +import { + createContext, + useCallback, + useContext, + useMemo, + useState, +} from 'react'; + +export interface SelectedComponent { + usageKey: string; + blockType: string; +} + +export type ComponentSelectedEvent = (selectedComponent: SelectedComponent) => void; +export type ComponentSelectionChangedEvent = (selectedComponents: SelectedComponent[]) => void; + +type NoComponentPickerType = { + componentPickerMode: false; + /** We add the `never` type to ensure that the other properties are not used, + * but allow it to be desconstructed from the return value of `useComponentPickerContext()` + */ + onComponentSelected?: never; + selectedComponents?: never; + addComponentToSelectedComponents?: never; + removeComponentFromSelectedComponents?: never; + restrictToLibrary?: never; +}; + +type ComponentPickerSingleType = { + componentPickerMode: 'single'; + onComponentSelected: ComponentSelectedEvent; + selectedComponents?: never; + addComponentToSelectedComponents?: never; + removeComponentFromSelectedComponents?: never; + restrictToLibrary: boolean; +}; + +type ComponentPickerMultipleType = { + componentPickerMode: 'multiple'; + onComponentSelected?: never; + selectedComponents: SelectedComponent[]; + addComponentToSelectedComponents: ComponentSelectedEvent; + removeComponentFromSelectedComponents: ComponentSelectedEvent; + restrictToLibrary: boolean; +}; + +type ComponentPickerContextData = ComponentPickerSingleType | ComponentPickerMultipleType; + +/** + * Component Picker Context. + * This context is used to provide the component picker mode and the selected components. + * + * Get this using `useComponentPickerContext()` + */ +const ComponentPickerContext = createContext(undefined); + +export type ComponentPickerSingleProps = { + componentPickerMode: 'single'; + onComponentSelected: ComponentSelectedEvent; + onChangeComponentSelection?: never; + restrictToLibrary?: boolean; +}; + +export type ComponentPickerMultipleProps = { + componentPickerMode: 'multiple'; + onComponentSelected?: never; + onChangeComponentSelection?: ComponentSelectionChangedEvent; + restrictToLibrary?: boolean; +}; + +type ComponentPickerProps = ComponentPickerSingleProps | ComponentPickerMultipleProps; + +type ComponentPickerProviderProps = { + children?: React.ReactNode; +} & ComponentPickerProps; + +/** + * React component to provide `ComponentPickerContext` + */ +export const ComponentPickerProvider = ({ + children, + componentPickerMode, + restrictToLibrary = false, + onComponentSelected, + onChangeComponentSelection, +}: ComponentPickerProviderProps) => { + const [selectedComponents, setSelectedComponents] = useState([]); + + const addComponentToSelectedComponents = useCallback(( + selectedComponent: SelectedComponent, + ) => { + setSelectedComponents((prevSelectedComponents) => { + // istanbul ignore if: this should never happen + if (prevSelectedComponents.some((component) => component.usageKey === selectedComponent.usageKey)) { + return prevSelectedComponents; + } + const newSelectedComponents = [...prevSelectedComponents, selectedComponent]; + onChangeComponentSelection?.(newSelectedComponents); + return newSelectedComponents; + }); + }, []); + + const removeComponentFromSelectedComponents = useCallback(( + selectedComponent: SelectedComponent, + ) => { + setSelectedComponents((prevSelectedComponents) => { + // istanbul ignore if: this should never happen + if (!prevSelectedComponents.some((component) => component.usageKey === selectedComponent.usageKey)) { + return prevSelectedComponents; + } + const newSelectedComponents = prevSelectedComponents.filter( + (component) => component.usageKey !== selectedComponent.usageKey, + ); + onChangeComponentSelection?.(newSelectedComponents); + return newSelectedComponents; + }); + }, []); + + const context = useMemo(() => { + switch (componentPickerMode) { + case 'single': + return { + componentPickerMode, + restrictToLibrary, + onComponentSelected, + }; + case 'multiple': + return { + componentPickerMode, + restrictToLibrary, + selectedComponents, + addComponentToSelectedComponents, + removeComponentFromSelectedComponents, + }; + default: + throw new Error('Invalid component picker mode'); + } + }, [ + componentPickerMode, + restrictToLibrary, + onComponentSelected, + addComponentToSelectedComponents, + removeComponentFromSelectedComponents, + selectedComponents, + onChangeComponentSelection, + ]); + + return ( + + {children} + + ); +}; + +export function useComponentPickerContext(): ComponentPickerContextData | NoComponentPickerType { + const ctx = useContext(ComponentPickerContext); + if (ctx === undefined) { + return { + componentPickerMode: false, + }; + } + return ctx; +} diff --git a/src/library-authoring/common/context.tsx b/src/library-authoring/common/context/LibraryContext.tsx similarity index 60% rename from src/library-authoring/common/context.tsx rename to src/library-authoring/common/context/LibraryContext.tsx index b0945012b8..637d14ccc0 100644 --- a/src/library-authoring/common/context.tsx +++ b/src/library-authoring/common/context/LibraryContext.tsx @@ -6,9 +6,10 @@ import React, { useState, } from 'react'; -import type { ComponentPicker } from '../component-picker'; -import type { ContentLibrary } from '../data/api'; -import { useContentLibrary } from '../data/apiHooks'; +import type { ComponentPicker } from '../../component-picker'; +import type { ContentLibrary } from '../../data/api'; +import { useContentLibrary } from '../../data/apiHooks'; +import { useComponentPickerContext } from './ComponentPickerContext'; export enum SidebarBodyComponentId { AddContent = 'add-content', @@ -188,8 +189,11 @@ export const LibraryProvider = ({ const { data: libraryData, isLoading: isLoadingLibraryData } = useContentLibrary(libraryId); - // const readOnly = !!componentPickerMode || !libraryData?.canEditLibrary; - const readOnly = !libraryData?.canEditLibrary; // FIXME: Check componentPickerMode + const { + componentPickerMode, + } = useComponentPickerContext(); + + const readOnly = !!componentPickerMode || !libraryData?.canEditLibrary; const context = useMemo(() => { const contextValue = { @@ -263,161 +267,3 @@ export function useLibraryContext(): LibraryContextData { } return ctx; } - -// FIXME: Move this to another file ############################################################ - -export interface SelectedComponent { - usageKey: string; - blockType: string; -} - -export type ComponentSelectedEvent = (selectedComponent: SelectedComponent) => void; -export type ComponentSelectionChangedEvent = (selectedComponents: SelectedComponent[]) => void; - -type NoComponentPickerType = { - componentPickerMode: false; - /** We add the `never` type to ensure that the other properties are not used, - * but allow it to be desconstructed from the return value of `useComponentPickerContext()` - */ - onComponentSelected?: never; - selectedComponents?: never; - addComponentToSelectedComponents?: never; - removeComponentFromSelectedComponents?: never; - restrictToLibrary?: never; -}; - -type ComponentPickerSingleType = { - componentPickerMode: 'single'; - onComponentSelected: ComponentSelectedEvent; - selectedComponents?: never; - addComponentToSelectedComponents?: never; - removeComponentFromSelectedComponents?: never; - restrictToLibrary: boolean; -}; - -type ComponentPickerMultipleType = { - componentPickerMode: 'multiple'; - onComponentSelected?: never; - selectedComponents: SelectedComponent[]; - addComponentToSelectedComponents: ComponentSelectedEvent; - removeComponentFromSelectedComponents: ComponentSelectedEvent; - restrictToLibrary: boolean; -}; - -type ComponentPickerContextData = ComponentPickerSingleType | ComponentPickerMultipleType; - -/** - * Component Picker Context. - * This context is used to provide the component picker mode and the selected components. - * - * Get this using `useComponentPickerContext()` - */ -const ComponentPickerContext = React.createContext(undefined); - -export type ComponentPickerSingleProps = { - componentPickerMode: 'single'; - onComponentSelected: ComponentSelectedEvent; - onChangeComponentSelection?: never; - restrictToLibrary?: boolean; -}; - -export type ComponentPickerMultipleProps = { - componentPickerMode: 'multiple'; - onComponentSelected?: never; - onChangeComponentSelection?: ComponentSelectionChangedEvent; - restrictToLibrary?: boolean; -}; - -type ComponentPickerProps = ComponentPickerSingleProps | ComponentPickerMultipleProps; - -type ComponentPickerProviderProps = { - children?: React.ReactNode; -} & ComponentPickerProps; - -/** - * React component to provide `ComponentPickerContext` - */ -export const ComponentPickerProvider = ({ - children, - componentPickerMode, - restrictToLibrary = false, - onComponentSelected, - onChangeComponentSelection, -}: ComponentPickerProviderProps) => { - const [selectedComponents, setSelectedComponents] = useState([]); - - const addComponentToSelectedComponents = useCallback(( - selectedComponent: SelectedComponent, - ) => { - setSelectedComponents((prevSelectedComponents) => { - // istanbul ignore if: this should never happen - if (prevSelectedComponents.some((component) => component.usageKey === selectedComponent.usageKey)) { - return prevSelectedComponents; - } - const newSelectedComponents = [...prevSelectedComponents, selectedComponent]; - onChangeComponentSelection?.(newSelectedComponents); - return newSelectedComponents; - }); - }, []); - - const removeComponentFromSelectedComponents = useCallback(( - selectedComponent: SelectedComponent, - ) => { - setSelectedComponents((prevSelectedComponents) => { - // istanbul ignore if: this should never happen - if (!prevSelectedComponents.some((component) => component.usageKey === selectedComponent.usageKey)) { - return prevSelectedComponents; - } - const newSelectedComponents = prevSelectedComponents.filter( - (component) => component.usageKey !== selectedComponent.usageKey, - ); - onChangeComponentSelection?.(newSelectedComponents); - return newSelectedComponents; - }); - }, []); - - const context = useMemo(() => { - switch (componentPickerMode) { - case 'single': - return { - componentPickerMode, - restrictToLibrary, - onComponentSelected, - }; - case 'multiple': - return { - componentPickerMode, - restrictToLibrary, - selectedComponents, - addComponentToSelectedComponents, - removeComponentFromSelectedComponents, - }; - default: - throw new Error('Invalid component picker mode'); - } - }, [ - componentPickerMode, - restrictToLibrary, - onComponentSelected, - addComponentToSelectedComponents, - removeComponentFromSelectedComponents, - selectedComponents, - onChangeComponentSelection, - ]); - - return ( - - {children} - - ); -}; - -export function useComponentPickerContext(): ComponentPickerContextData | NoComponentPickerType { - const ctx = useContext(ComponentPickerContext); - if (ctx === undefined) { - return { - componentPickerMode: false, - }; - } - return ctx; -} diff --git a/src/library-authoring/component-info/ComponentAdvancedAssets.tsx b/src/library-authoring/component-info/ComponentAdvancedAssets.tsx index b9ea9ba567..f478f58516 100644 --- a/src/library-authoring/component-info/ComponentAdvancedAssets.tsx +++ b/src/library-authoring/component-info/ComponentAdvancedAssets.tsx @@ -10,7 +10,7 @@ import { FormattedMessage, FormattedNumber, useIntl } from '@edx/frontend-platfo import { LoadingSpinner } from '../../generic/Loading'; import DeleteModal from '../../generic/delete-modal/DeleteModal'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { getXBlockAssetsApiUrl } from '../data/api'; import { useDeleteXBlockAsset, useInvalidateXBlockAssets, useXBlockAssets } from '../data/apiHooks'; import messages from './messages'; diff --git a/src/library-authoring/component-info/ComponentAdvancedInfo.test.tsx b/src/library-authoring/component-info/ComponentAdvancedInfo.test.tsx index 238be40d39..d073fd7576 100644 --- a/src/library-authoring/component-info/ComponentAdvancedInfo.test.tsx +++ b/src/library-authoring/component-info/ComponentAdvancedInfo.test.tsx @@ -12,7 +12,7 @@ import { mockXBlockAssets, mockXBlockOLX, } from '../data/api.mocks'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import { ComponentAdvancedInfo } from './ComponentAdvancedInfo'; import { getXBlockAssetsApiUrl } from '../data/api'; diff --git a/src/library-authoring/component-info/ComponentAdvancedInfo.tsx b/src/library-authoring/component-info/ComponentAdvancedInfo.tsx index a558ef6902..98a212a11f 100644 --- a/src/library-authoring/component-info/ComponentAdvancedInfo.tsx +++ b/src/library-authoring/component-info/ComponentAdvancedInfo.tsx @@ -11,7 +11,7 @@ import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; import { LoadingSpinner } from '../../generic/Loading'; import { CodeEditor, EditorAccessor } from '../../generic/CodeEditor'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useUpdateXBlockOLX, useXBlockOLX, diff --git a/src/library-authoring/component-info/ComponentDetails.test.tsx b/src/library-authoring/component-info/ComponentDetails.test.tsx index 514e66bdf8..b17d6bfd3e 100644 --- a/src/library-authoring/component-info/ComponentDetails.test.tsx +++ b/src/library-authoring/component-info/ComponentDetails.test.tsx @@ -9,7 +9,7 @@ import { mockXBlockAssets, mockXBlockOLX, } from '../data/api.mocks'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import ComponentDetails from './ComponentDetails'; mockContentLibrary.applyMock(); diff --git a/src/library-authoring/component-info/ComponentDetails.tsx b/src/library-authoring/component-info/ComponentDetails.tsx index 0bac9d3234..5641e79f33 100644 --- a/src/library-authoring/component-info/ComponentDetails.tsx +++ b/src/library-authoring/component-info/ComponentDetails.tsx @@ -3,7 +3,7 @@ import { Stack } from '@openedx/paragon'; import AlertError from '../../generic/alert-error'; import Loading from '../../generic/Loading'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useLibraryBlockMetadata } from '../data/apiHooks'; import HistoryWidget from '../generic/history-widget'; import { ComponentAdvancedInfo } from './ComponentAdvancedInfo'; diff --git a/src/library-authoring/component-info/ComponentInfo.test.tsx b/src/library-authoring/component-info/ComponentInfo.test.tsx index 7cb44cfee6..1e3c211c23 100644 --- a/src/library-authoring/component-info/ComponentInfo.test.tsx +++ b/src/library-authoring/component-info/ComponentInfo.test.tsx @@ -6,7 +6,7 @@ import { } from '../../testUtils'; import { mockContentLibrary, mockLibraryBlockMetadata } from '../data/api.mocks'; import { mockBroadcastChannel } from '../../generic/data/api.mock'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import ComponentInfo from './ComponentInfo'; import { getXBlockPublishApiUrl } from '../data/api'; diff --git a/src/library-authoring/component-info/ComponentInfo.tsx b/src/library-authoring/component-info/ComponentInfo.tsx index 305390fc60..44988a04f9 100644 --- a/src/library-authoring/component-info/ComponentInfo.tsx +++ b/src/library-authoring/component-info/ComponentInfo.tsx @@ -11,14 +11,16 @@ import { CheckBoxOutlineBlank, } from '@openedx/paragon/icons'; +import { + useComponentPickerContext, +} from '../common/context/ComponentPickerContext'; import { SidebarAdditionalActions, useLibraryContext, COMPONENT_INFO_TABS, ComponentInfoTab, isComponentInfoTab, - useComponentPickerContext, -} from '../common/context'; +} from '../common/context/LibraryContext'; import ComponentMenu from '../components'; import { canEditComponent } from '../components/ComponentEditorModal'; import ComponentDetails from './ComponentDetails'; diff --git a/src/library-authoring/component-info/ComponentInfoHeader.test.tsx b/src/library-authoring/component-info/ComponentInfoHeader.test.tsx index 832f0eebf0..f51bc1c306 100644 --- a/src/library-authoring/component-info/ComponentInfoHeader.test.tsx +++ b/src/library-authoring/component-info/ComponentInfoHeader.test.tsx @@ -9,7 +9,7 @@ import { } from '../../testUtils'; import { mockContentLibrary } from '../data/api.mocks'; import { getXBlockFieldsVersionApiUrl, getXBlockFieldsApiUrl } from '../data/api'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import ComponentInfoHeader from './ComponentInfoHeader'; const { libraryId: mockLibraryId, libraryIdReadOnly } = mockContentLibrary; diff --git a/src/library-authoring/component-info/ComponentInfoHeader.tsx b/src/library-authoring/component-info/ComponentInfoHeader.tsx index 295e4a3821..7d8419f025 100644 --- a/src/library-authoring/component-info/ComponentInfoHeader.tsx +++ b/src/library-authoring/component-info/ComponentInfoHeader.tsx @@ -9,7 +9,7 @@ import { import { Edit } from '@openedx/paragon/icons'; import { ToastContext } from '../../generic/toast-context'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useUpdateXBlockFields, useXBlockFields } from '../data/apiHooks'; import messages from './messages'; diff --git a/src/library-authoring/component-info/ComponentManagement.test.tsx b/src/library-authoring/component-info/ComponentManagement.test.tsx index 93a5872df2..decb850099 100644 --- a/src/library-authoring/component-info/ComponentManagement.test.tsx +++ b/src/library-authoring/component-info/ComponentManagement.test.tsx @@ -7,7 +7,7 @@ import { screen, waitFor, } from '../../testUtils'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import { mockContentLibrary, mockLibraryBlockMetadata } from '../data/api.mocks'; import ComponentManagement from './ComponentManagement'; diff --git a/src/library-authoring/component-info/ComponentManagement.tsx b/src/library-authoring/component-info/ComponentManagement.tsx index 0cfb1c14c9..1e249231cd 100644 --- a/src/library-authoring/component-info/ComponentManagement.tsx +++ b/src/library-authoring/component-info/ComponentManagement.tsx @@ -6,7 +6,7 @@ import { BookOpen, ExpandLess, ExpandMore, Tag, } from '@openedx/paragon/icons'; -import { SidebarAdditionalActions, useLibraryContext } from '../common/context'; +import { SidebarAdditionalActions, useLibraryContext } from '../common/context/LibraryContext'; import { useLibraryBlockMetadata } from '../data/apiHooks'; import StatusWidget from '../generic/status-widget'; import messages from './messages'; diff --git a/src/library-authoring/component-info/ComponentPreview.test.tsx b/src/library-authoring/component-info/ComponentPreview.test.tsx index cf71dab382..a45ecea71e 100644 --- a/src/library-authoring/component-info/ComponentPreview.test.tsx +++ b/src/library-authoring/component-info/ComponentPreview.test.tsx @@ -4,7 +4,7 @@ import { render as baseRender, screen, } from '../../testUtils'; -import { LibraryProvider, SidebarBodyComponentId } from '../common/context'; +import { LibraryProvider, SidebarBodyComponentId } from '../common/context/LibraryContext'; import { mockContentLibrary, mockLibraryBlockMetadata } from '../data/api.mocks'; import ComponentPreview from './ComponentPreview'; @@ -26,7 +26,7 @@ const render = () => baseRender(, { type: SidebarBodyComponentId.ComponentInfo, }} > - { children } + {children} ), }); diff --git a/src/library-authoring/component-info/ComponentPreview.tsx b/src/library-authoring/component-info/ComponentPreview.tsx index 05c91c1468..b3bc6bfbb7 100644 --- a/src/library-authoring/component-info/ComponentPreview.tsx +++ b/src/library-authoring/component-info/ComponentPreview.tsx @@ -2,7 +2,7 @@ import { useIntl } from '@edx/frontend-platform/i18n'; import { Button, StandardModal, useToggle } from '@openedx/paragon'; import { OpenInFull } from '@openedx/paragon/icons'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { LibraryBlock } from '../LibraryBlock'; import messages from './messages'; import { useLibraryBlockMetadata } from '../data/apiHooks'; diff --git a/src/library-authoring/component-info/ManageCollections.test.tsx b/src/library-authoring/component-info/ManageCollections.test.tsx index abcd643dc3..600551b4e5 100644 --- a/src/library-authoring/component-info/ManageCollections.test.tsx +++ b/src/library-authoring/component-info/ManageCollections.test.tsx @@ -12,7 +12,7 @@ import mockCollectionsResults from '../__mocks__/collection-search.json'; import { mockContentSearchConfig } from '../../search-manager/data/api.mock'; import { mockContentLibrary, mockLibraryBlockMetadata } from '../data/api.mocks'; import ManageCollections from './ManageCollections'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import { getLibraryBlockCollectionsUrl } from '../data/api'; let axiosMock: MockAdapter; diff --git a/src/library-authoring/component-info/ManageCollections.tsx b/src/library-authoring/component-info/ManageCollections.tsx index 099e66631f..1124d0b74e 100644 --- a/src/library-authoring/component-info/ManageCollections.tsx +++ b/src/library-authoring/component-info/ManageCollections.tsx @@ -15,7 +15,7 @@ import messages from './messages'; import { useUpdateComponentCollections } from '../data/apiHooks'; import { ToastContext } from '../../generic/toast-context'; import { CollectionMetadata } from '../data/api'; -import { SidebarAdditionalActions, useLibraryContext } from '../common/context'; +import { SidebarAdditionalActions, useLibraryContext } from '../common/context/LibraryContext'; interface ManageCollectionsProps { usageKey: string; diff --git a/src/library-authoring/component-picker/ComponentPicker.tsx b/src/library-authoring/component-picker/ComponentPicker.tsx index b65aa9a30c..00460d9ea3 100644 --- a/src/library-authoring/component-picker/ComponentPicker.tsx +++ b/src/library-authoring/component-picker/ComponentPicker.tsx @@ -6,10 +6,12 @@ import { FormattedMessage } from '@edx/frontend-platform/i18n'; import { type ComponentSelectedEvent, type ComponentSelectionChangedEvent, - LibraryProvider, ComponentPickerProvider, +} from '../common/context/ComponentPickerContext'; +import { + LibraryProvider, useLibraryContext, -} from '../common/context'; +} from '../common/context/LibraryContext'; import LibraryAuthoringPage from '../LibraryAuthoringPage'; import LibraryCollectionPage from '../collections/LibraryCollectionPage'; import SelectLibrary from './SelectLibrary'; diff --git a/src/library-authoring/components/CollectionCard.test.tsx b/src/library-authoring/components/CollectionCard.test.tsx index eefbc7ba53..d359011084 100644 --- a/src/library-authoring/components/CollectionCard.test.tsx +++ b/src/library-authoring/components/CollectionCard.test.tsx @@ -4,7 +4,7 @@ import type MockAdapter from 'axios-mock-adapter'; import { initializeMocks, render as baseRender, screen, waitFor, waitForElementToBeRemoved, within, } from '../../testUtils'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import { type CollectionHit } from '../../search-manager'; import CollectionCard from './CollectionCard'; import messages from './messages'; diff --git a/src/library-authoring/components/CollectionCard.tsx b/src/library-authoring/components/CollectionCard.tsx index 8a9ac47555..b73c0dd87d 100644 --- a/src/library-authoring/components/CollectionCard.tsx +++ b/src/library-authoring/components/CollectionCard.tsx @@ -11,7 +11,8 @@ import { MoreVert } from '@openedx/paragon/icons'; import { Link } from 'react-router-dom'; import { type CollectionHit } from '../../search-manager'; -import { useComponentPickerContext, useLibraryContext } from '../common/context'; +import { useComponentPickerContext } from '../common/context/ComponentPickerContext'; +import { useLibraryContext } from '../common/context/LibraryContext'; import BaseComponentCard from './BaseComponentCard'; import { ToastContext } from '../../generic/toast-context'; import { useDeleteCollection, useRestoreCollection } from '../data/apiHooks'; diff --git a/src/library-authoring/components/ComponentCard.test.tsx b/src/library-authoring/components/ComponentCard.test.tsx index fb5fb9685d..d90db3ac6f 100644 --- a/src/library-authoring/components/ComponentCard.test.tsx +++ b/src/library-authoring/components/ComponentCard.test.tsx @@ -5,7 +5,7 @@ import { waitFor, initializeMocks, } from '../../testUtils'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import { getClipboardUrl } from '../../generic/data/api'; import { ContentHit } from '../../search-manager'; import ComponentCard from './ComponentCard'; diff --git a/src/library-authoring/components/ComponentCard.tsx b/src/library-authoring/components/ComponentCard.tsx index a53d3a7196..b1dea2f4eb 100644 --- a/src/library-authoring/components/ComponentCard.tsx +++ b/src/library-authoring/components/ComponentCard.tsx @@ -19,7 +19,8 @@ import { STUDIO_CLIPBOARD_CHANNEL } from '../../constants'; import { updateClipboard } from '../../generic/data/api'; import { ToastContext } from '../../generic/toast-context'; import { type ContentHit } from '../../search-manager'; -import { SidebarAdditionalActions, useComponentPickerContext, useLibraryContext } from '../common/context'; +import { useComponentPickerContext } from '../common/context/ComponentPickerContext'; +import { SidebarAdditionalActions, useLibraryContext } from '../common/context/LibraryContext'; import { useRemoveComponentsFromCollection } from '../data/apiHooks'; import BaseComponentCard from './BaseComponentCard'; import { canEditComponent } from './ComponentEditorModal'; diff --git a/src/library-authoring/components/ComponentDeleter.test.tsx b/src/library-authoring/components/ComponentDeleter.test.tsx index 5db365efe1..aab4803d5b 100644 --- a/src/library-authoring/components/ComponentDeleter.test.tsx +++ b/src/library-authoring/components/ComponentDeleter.test.tsx @@ -6,7 +6,7 @@ import { initializeMocks, waitFor, } from '../../testUtils'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import { mockContentLibrary, mockDeleteLibraryBlock, mockLibraryBlockMetadata } from '../data/api.mocks'; import ComponentDeleter from './ComponentDeleter'; diff --git a/src/library-authoring/components/ComponentDeleter.tsx b/src/library-authoring/components/ComponentDeleter.tsx index b71f139ae4..34cdcb39e8 100644 --- a/src/library-authoring/components/ComponentDeleter.tsx +++ b/src/library-authoring/components/ComponentDeleter.tsx @@ -7,7 +7,7 @@ import { } from '@openedx/paragon'; import { Warning } from '@openedx/paragon/icons'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useDeleteLibraryBlock, useLibraryBlockMetadata } from '../data/apiHooks'; import messages from './messages'; diff --git a/src/library-authoring/components/ComponentEditorModal.tsx b/src/library-authoring/components/ComponentEditorModal.tsx index 6fbe8a46b3..6ba78979bd 100644 --- a/src/library-authoring/components/ComponentEditorModal.tsx +++ b/src/library-authoring/components/ComponentEditorModal.tsx @@ -4,7 +4,7 @@ import React from 'react'; import { useQueryClient } from '@tanstack/react-query'; import EditorPage from '../../editors/EditorPage'; import { getBlockType } from '../../generic/key-utils'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { invalidateComponentData } from '../data/apiHooks'; export function canEditComponent(usageKey: string): boolean { diff --git a/src/library-authoring/create-collection/CreateCollectionModal.tsx b/src/library-authoring/create-collection/CreateCollectionModal.tsx index 1b160ab0ee..de9e776cf9 100644 --- a/src/library-authoring/create-collection/CreateCollectionModal.tsx +++ b/src/library-authoring/create-collection/CreateCollectionModal.tsx @@ -10,7 +10,7 @@ import { useIntl } from '@edx/frontend-platform/i18n'; import { Formik } from 'formik'; import * as Yup from 'yup'; import FormikControl from '../../generic/FormikControl'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import messages from './messages'; import { useCreateLibraryCollection } from '../data/apiHooks'; import { ToastContext } from '../../generic/toast-context'; diff --git a/src/library-authoring/legacy-integration/PreviewChangesEmbed.tsx b/src/library-authoring/legacy-integration/PreviewChangesEmbed.tsx index 648ca83d64..21e86cad0e 100644 --- a/src/library-authoring/legacy-integration/PreviewChangesEmbed.tsx +++ b/src/library-authoring/legacy-integration/PreviewChangesEmbed.tsx @@ -2,7 +2,7 @@ import { useIntl } from '@edx/frontend-platform/i18n'; import { useParams, useSearchParams } from 'react-router-dom'; import { Helmet } from 'react-helmet'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import { getLibraryId } from '../../generic/key-utils'; import CompareChangesWidget from '../component-comparison/CompareChangesWidget'; import { useLibraryBlockMetadata } from '../data/apiHooks'; diff --git a/src/library-authoring/library-info/LibraryInfo.test.tsx b/src/library-authoring/library-info/LibraryInfo.test.tsx index bbd1aa5bc8..69aa4c14f0 100644 --- a/src/library-authoring/library-info/LibraryInfo.test.tsx +++ b/src/library-authoring/library-info/LibraryInfo.test.tsx @@ -9,7 +9,7 @@ import { } from '../../testUtils'; import { mockContentLibrary } from '../data/api.mocks'; import { getCommitLibraryChangesUrl } from '../data/api'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import LibraryInfo from './LibraryInfo'; const { diff --git a/src/library-authoring/library-info/LibraryInfo.tsx b/src/library-authoring/library-info/LibraryInfo.tsx index 62fbaa02e3..bee37acfc4 100644 --- a/src/library-authoring/library-info/LibraryInfo.tsx +++ b/src/library-authoring/library-info/LibraryInfo.tsx @@ -3,7 +3,7 @@ import { FormattedDate, useIntl } from '@edx/frontend-platform/i18n'; import messages from './messages'; import LibraryPublishStatus from './LibraryPublishStatus'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; const LibraryInfo = () => { const intl = useIntl(); diff --git a/src/library-authoring/library-info/LibraryInfoHeader.test.tsx b/src/library-authoring/library-info/LibraryInfoHeader.test.tsx index 855d68f441..33630af5b6 100644 --- a/src/library-authoring/library-info/LibraryInfoHeader.test.tsx +++ b/src/library-authoring/library-info/LibraryInfoHeader.test.tsx @@ -9,7 +9,7 @@ import { } from '../../testUtils'; import { mockContentLibrary } from '../data/api.mocks'; import { getContentLibraryApiUrl } from '../data/api'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import LibraryInfoHeader from './LibraryInfoHeader'; const { libraryId: mockLibraryId, libraryIdReadOnly, libraryData } = mockContentLibrary; diff --git a/src/library-authoring/library-info/LibraryInfoHeader.tsx b/src/library-authoring/library-info/LibraryInfoHeader.tsx index 9bbbad82a2..95d2f5fd20 100644 --- a/src/library-authoring/library-info/LibraryInfoHeader.tsx +++ b/src/library-authoring/library-info/LibraryInfoHeader.tsx @@ -9,7 +9,7 @@ import { Edit } from '@openedx/paragon/icons'; import { useIntl } from '@edx/frontend-platform/i18n'; import { ToastContext } from '../../generic/toast-context'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useUpdateLibraryMetadata } from '../data/apiHooks'; import messages from './messages'; diff --git a/src/library-authoring/library-info/LibraryPublishStatus.tsx b/src/library-authoring/library-info/LibraryPublishStatus.tsx index 1bd707958c..89ac4e8468 100644 --- a/src/library-authoring/library-info/LibraryPublishStatus.tsx +++ b/src/library-authoring/library-info/LibraryPublishStatus.tsx @@ -3,7 +3,7 @@ import { useIntl } from '@edx/frontend-platform/i18n'; import { useToggle } from '@openedx/paragon'; import { ToastContext } from '../../generic/toast-context'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { useCommitLibraryChanges, useRevertLibraryChanges } from '../data/apiHooks'; import StatusWidget from '../generic/status-widget'; import messages from './messages'; diff --git a/src/library-authoring/library-sidebar/LibrarySidebar.tsx b/src/library-authoring/library-sidebar/LibrarySidebar.tsx index be9c33c426..98d8363e04 100644 --- a/src/library-authoring/library-sidebar/LibrarySidebar.tsx +++ b/src/library-authoring/library-sidebar/LibrarySidebar.tsx @@ -9,7 +9,7 @@ import { useIntl } from '@edx/frontend-platform/i18n'; import { AddContentContainer, AddContentHeader } from '../add-content'; import { CollectionInfo, CollectionInfoHeader } from '../collections'; -import { SidebarBodyComponentId, useLibraryContext } from '../common/context'; +import { SidebarBodyComponentId, useLibraryContext } from '../common/context/LibraryContext'; import { ComponentInfo, ComponentInfoHeader } from '../component-info'; import { LibraryInfo, LibraryInfoHeader } from '../library-info'; import messages from '../messages'; diff --git a/src/library-authoring/library-team/LibraryTeam.test.tsx b/src/library-authoring/library-team/LibraryTeam.test.tsx index 2ab5ec52ab..4ab5b8c0e6 100644 --- a/src/library-authoring/library-team/LibraryTeam.test.tsx +++ b/src/library-authoring/library-team/LibraryTeam.test.tsx @@ -14,7 +14,7 @@ import { getLibraryTeamApiUrl, getLibraryTeamMemberApiUrl, } from '../data/api'; -import { LibraryProvider } from '../common/context'; +import { LibraryProvider } from '../common/context/LibraryContext'; import LibraryTeam from './LibraryTeam'; mockContentLibrary.applyMock(); diff --git a/src/library-authoring/library-team/LibraryTeam.tsx b/src/library-authoring/library-team/LibraryTeam.tsx index b41be5acf2..d709e03c7c 100644 --- a/src/library-authoring/library-team/LibraryTeam.tsx +++ b/src/library-authoring/library-team/LibraryTeam.tsx @@ -12,7 +12,7 @@ import { Add as IconAdd } from '@openedx/paragon/icons'; import AlertError from '../../generic/alert-error'; import Loading from '../../generic/Loading'; import { ToastContext } from '../../generic/toast-context'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import { LibraryAccessLevel } from '../data/api'; import { useContentLibrary, diff --git a/src/library-authoring/library-team/LibraryTeamModal.tsx b/src/library-authoring/library-team/LibraryTeamModal.tsx index 5b29eafdc1..74ca6c3843 100644 --- a/src/library-authoring/library-team/LibraryTeamModal.tsx +++ b/src/library-authoring/library-team/LibraryTeamModal.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { StandardModal } from '@openedx/paragon'; import { useIntl } from '@edx/frontend-platform/i18n'; -import { useLibraryContext } from '../common/context'; +import { useLibraryContext } from '../common/context/LibraryContext'; import LibraryTeam from './LibraryTeam'; import messages from './messages';