import { useEffect } from 'react'; import { StudioFooterSlot } from '@openedx/frontend-slot-footer'; import { useIntl } from '@edx/frontend-platform/i18n'; import { ActionRow, Button, Breadcrumb, Container, Icon, } from '@openedx/paragon'; import { Add, ArrowBack, InfoOutline } from '@openedx/paragon/icons'; import classNames from 'classnames'; import { Helmet } from 'react-helmet'; import { Link } from 'react-router-dom'; import { useLibraryRoutes } from '../routes'; import Loading from '../../generic/Loading'; import ErrorAlert from '../../generic/alert-error'; import SubHeader from '../../generic/sub-header/SubHeader'; import Header from '../../header'; import NotFoundAlert from '../../generic/NotFoundAlert'; import { ClearFiltersButton, FilterByBlockType, FilterByPublished, FilterByTags, SearchContextProvider, SearchKeywordsField, SearchSortWidget, } from '../../search-manager'; import { SubHeaderTitle } from '../LibraryAuthoringPage'; import { useCollection, useContentLibrary } from '../data/apiHooks'; import { useComponentPickerContext } from '../common/context/ComponentPickerContext'; import { useLibraryContext } from '../common/context/LibraryContext'; import { SidebarBodyComponentId, useSidebarContext } from '../common/context/SidebarContext'; import messages from './messages'; import { LibrarySidebar } from '../library-sidebar'; import LibraryCollectionComponents from './LibraryCollectionComponents'; const HeaderActions = () => { const intl = useIntl(); const { componentPickerMode } = useComponentPickerContext(); const { collectionId, readOnly } = useLibraryContext(); const { closeLibrarySidebar, openAddContentSidebar, openCollectionInfoSidebar, sidebarComponentInfo, } = useSidebarContext(); const { navigateTo } = useLibraryRoutes(); // istanbul ignore if: this should never happen if (!collectionId) { throw new Error('it should not be possible to render HeaderActions without a collectionId'); } const infoSidebarIsOpen = sidebarComponentInfo?.type === SidebarBodyComponentId.CollectionInfo && sidebarComponentInfo?.id === collectionId; const handleOnClickInfoSidebar = () => { if (infoSidebarIsOpen) { closeLibrarySidebar(); } else { openCollectionInfoSidebar(collectionId); } if (!componentPickerMode) { navigateTo({ collectionId }); } }; return (
{!componentPickerMode && ( )}
); }; const LibraryCollectionPage = () => { const intl = useIntl(); const { libraryId, collectionId } = useLibraryContext(); if (!collectionId || !libraryId) { // istanbul ignore next - This shouldn't be possible; it's just here to satisfy the type checker. throw new Error('Rendered without collectionId or libraryId URL parameter'); } const { componentPickerMode } = useComponentPickerContext(); const { showOnlyPublished, setCollectionId, componentId } = useLibraryContext(); const { sidebarComponentInfo, openInfoSidebar } = useSidebarContext(); const { data: collectionData, isLoading, isError, error, } = useCollection(libraryId, collectionId); useEffect(() => { openInfoSidebar(componentId, collectionId, ''); }, []); const { data: libraryData, isLoading: isLibLoading } = useContentLibrary(libraryId); // Only show loading if collection data is not fetched from index yet // Loading info for search results will be handled by LibraryCollectionComponents component. if (isLibLoading || isLoading) { return ; } if (!libraryData) { return ; } if (isError) { return ; } const breadcrumbs = !componentPickerMode ? ( ` spacer. { label: '', to: '', }, ]} linkAs={Link} /> ) : ( { setCollectionId(undefined); }, }, ]} spacer={} linkAs={Link} /> ); const extraFilter = [`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`]; if (showOnlyPublished) { extraFilter.push('last_published IS NOT NULL'); } return (
{libraryData.title} | {process.env.SITE_NAME} {!componentPickerMode && (
)} } breadcrumbs={breadcrumbs} headerActions={} hideBorder /> {!componentPickerMode && }
{!!sidebarComponentInfo?.type && (
)}
); }; export default LibraryCollectionPage;