Skip to content

Commit

Permalink
refactor: move messages related to collections in single file
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Sep 16, 2024
1 parent b826fd1 commit c95ba13
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/library-authoring/LibraryLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import LibraryAuthoringPage from './LibraryAuthoringPage';
import { LibraryProvider } from './common/context';
import { CreateCollectionModal } from './create-collection';
import { invalidateComponentData } from './data/apiHooks';
import LibraryCollectionPageWrapper from './collections/LibraryCollectionPage';
import LibraryCollectionPage from './collections/LibraryCollectionPage';

const LibraryLayout = () => {
const { libraryId } = useParams();
Expand Down Expand Up @@ -48,7 +48,7 @@ const LibraryLayout = () => {
/>
<Route
path="collections/:collectionId"
element={<LibraryCollectionPageWrapper />}
element={<LibraryCollectionPage />}
/>
<Route
path="*"
Expand Down
88 changes: 38 additions & 50 deletions src/library-authoring/collections/LibraryCollectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Container,
Icon,
IconButton,
Row,
Stack,
} from '@openedx/paragon';
import { Add, InfoOutline } from '@openedx/paragon/icons';
Expand All @@ -28,7 +27,7 @@ import {
} from '../../search-manager';
import { useCollection, useContentLibrary } from '../data/apiHooks';
import { LibraryContext } from '../common/context';
import messages from '../messages';
import messages from './messages';
import { LibrarySidebar } from '../library-sidebar';
import LibraryCollectionComponents from './LibraryCollectionComponents';

Expand Down Expand Up @@ -91,13 +90,13 @@ const SubHeaderTitle = ({
);
};

const LibraryCollectionPage = ({
libraryId,
collectionId,
}: {
libraryId: string;
collectionId: string;
}) => {
const LibraryCollectionPage = () => {
const { libraryId, collectionId } = useParams();

if (!collectionId || !libraryId) {
throw new Error('Rendered without collectionId or libraryId URL parameter');
}

const intl = useIntl();

const {
Expand Down Expand Up @@ -147,30 +146,35 @@ const LibraryCollectionPage = ({
isLibrary
/>
<Container size="xl" className="px-4 mt-4 mb-5 library-authoring-page">
<SubHeader
title={<SubHeaderTitle
title={collectionData.title}
canEditLibrary={libraryData.canEditLibrary}
infoClickHandler={openCollectionInfoSidebar}
/>}
breadcrumbs={(
<Breadcrumb
ariaLabel={intl.formatMessage(messages.allCollections)}
links={breadcrumbs}
linkAs={Link}
/>
)}
headerActions={<HeaderActions canEditLibrary={libraryData.canEditLibrary} />}
/>
<SearchKeywordsField className="w-50" />
<div className="d-flex mt-3 mb-4 align-items-center">
<FilterByTags />
<FilterByBlockType />
<ClearFiltersButton />
<div className="flex-grow-1" />
<SearchSortWidget />
</div>
<LibraryCollectionComponents libraryId={libraryId} />
<SearchContextProvider
extraFilter={[`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`]}
fetchCollections={false}
>
<SubHeader
title={<SubHeaderTitle
title={collectionData.title}
canEditLibrary={libraryData.canEditLibrary}
infoClickHandler={openCollectionInfoSidebar}
/>}
breadcrumbs={(
<Breadcrumb
ariaLabel={intl.formatMessage(messages.breadcrumbsAriaLabel)}
links={breadcrumbs}
linkAs={Link}
/>
)}
headerActions={<HeaderActions canEditLibrary={libraryData.canEditLibrary} />}
/>
<SearchKeywordsField className="w-50" placeholder={intl.formatMessage(messages.searchPlaceholder)} />
<div className="d-flex mt-3 mb-4 align-items-center">
<FilterByTags />
<FilterByBlockType />
<ClearFiltersButton />
<div className="flex-grow-1" />
<SearchSortWidget />
</div>
<LibraryCollectionComponents libraryId={libraryId} />
</SearchContextProvider>
</Container>
<StudioFooter />
</div>
Expand All @@ -183,20 +187,4 @@ const LibraryCollectionPage = ({
);
};

const LibraryCollectionPageWrapper = () => {
const { libraryId, collectionId } = useParams();
if (!collectionId || !libraryId) {
throw new Error('Rendered without collectionId or libraryId URL parameter');
}

return (
<SearchContextProvider
extraFilter={[`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`]}
fetchCollections={false}
>
<LibraryCollectionPage libraryId={libraryId} collectionId={collectionId} />
</SearchContextProvider>
);
}

export default LibraryCollectionPageWrapper;
export default LibraryCollectionPage;
2 changes: 1 addition & 1 deletion src/library-authoring/collections/LibraryCollections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSearchContext } from '../../search-manager';
import { NoComponents, NoSearchResults } from '../EmptyStates';
import CollectionCard from '../components/CollectionCard';
import { LIBRARY_SECTION_PREVIEW_LIMIT } from '../components/LibrarySection';
import messages from '../messages';
import messages from './messages';
import { LibraryContext } from '../common/context';

type LibraryCollectionsProps = {
Expand Down
45 changes: 45 additions & 0 deletions src/library-authoring/collections/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,51 @@ const messages = defineMessages({
defaultMessage: 'No matching components found in this collections.',
description: 'Message displayed when no matching components are found in collection',
},
newContentButton: {
id: 'course-authoring.library-authoring.collections.buttons.new-content.text',
defaultMessage: 'New',
description: 'Text of button to open "Add content drawer" in collections page',
},
collectionInfoButton: {
id: 'course-authoring.library-authoring.buttons.collection-info.alt-text',
defaultMessage: 'Collection Info',
description: 'Alt text for collection info button besides the collection title',
},
readOnlyBadge: {
id: 'course-authoring.library-authoring.collections.badge.read-only',
defaultMessage: 'Read Only',
description: 'Text in badge when the user has read only access in collections page',
},
allCollections: {
id: 'course-authoring.library-authoring.all-collections.text',
defaultMessage: 'All Collections',
description: 'Breadcrumbs text to navigate back to all collections',
},
breadcrumbsAriaLabel: {
id: 'course-authoring.library-authoring.breadcrumbs.label.text',
defaultMessage: 'Navigation breadcrumbs',
description: 'Aria label for navigation breadcrumbs',
},
searchPlaceholder: {
id: 'course-authoring.library-authoring.search.placeholder.text',
defaultMessage: 'Search Collection',
description: 'Search placeholder text in collections page.',
},
noSearchResultsCollections: {
id: 'course-authoring.library-authoring.no-search-results-collections',
defaultMessage: 'No matching collections found in this library.',
description: 'Message displayed when no matching collections are found',
},
noCollections: {
id: 'course-authoring.library-authoring.no-collections',
defaultMessage: 'You have not added any collection to this library yet.',
description: 'Message displayed when the library has no collections',
},
addCollection: {
id: 'course-authoring.library-authoring.add-collection',
defaultMessage: 'Add collection',
description: 'Button text to add a new collection',
},
});

export default messages;
25 changes: 0 additions & 25 deletions src/library-authoring/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const messages = defineMessages({
defaultMessage: 'Content library',
description: 'The page heading for the library page.',
},
allCollections: {
id: 'course-authoring.library-authoring.all-collections',
defaultMessage: 'All Collections',
description: 'Breadcrumbs text to navigate back to all collections',
},
headingInfoAlt: {
id: 'course-authoring.library-authoring.heading-info-alt',
defaultMessage: 'Info',
Expand All @@ -26,31 +21,16 @@ const messages = defineMessages({
defaultMessage: 'No matching components found in this library.',
description: 'Message displayed when no search results are found',
},
noSearchResultsCollections: {
id: 'course-authoring.library-authoring.no-search-results-collections',
defaultMessage: 'No matching collections found in this library.',
description: 'Message displayed when no matching collections are found',
},
noComponents: {
id: 'course-authoring.library-authoring.no-components',
defaultMessage: 'You have not added any content to this library yet.',
description: 'Message displayed when the library is empty',
},
noCollections: {
id: 'course-authoring.library-authoring.no-collections',
defaultMessage: 'You have not added any collection to this library yet.',
description: 'Message displayed when the library has no collections',
},
addComponent: {
id: 'course-authoring.library-authoring.add-component',
defaultMessage: 'Add component',
description: 'Button text to add a new component',
},
addCollection: {
id: 'course-authoring.library-authoring.add-collection',
defaultMessage: 'Add collection',
description: 'Button text to add a new collection',
},
homeTab: {
id: 'course-authoring.library-authoring.home-tab',
defaultMessage: 'Home',
Expand Down Expand Up @@ -121,11 +101,6 @@ const messages = defineMessages({
defaultMessage: 'Library Info',
description: 'Text of button to open "Library Info sidebar"',
},
collectionInfoButton: {
id: 'course-authoring.library-authoring.buttons.collection-info.alt-text',
defaultMessage: 'Collection Info',
description: 'Alt text for collection info button besides the collection title',
},
readOnlyBadge: {
id: 'course-authoring.library-authoring.badge.read-only',
defaultMessage: 'Read Only',
Expand Down
6 changes: 4 additions & 2 deletions src/search-manager/SearchKeywordsField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useSearchContext } from './SearchManager';
/**
* The "main" input field where users type in search keywords. The search happens as they type (no need to press enter).
*/
const SearchKeywordsField: React.FC<{ className?: string }> = (props) => {
const SearchKeywordsField: React.FC<{ className?: string, placeholder?: string }> = (props) => {
const intl = useIntl();
const { searchKeywords, setSearchKeywords } = useSearchContext();

Expand All @@ -22,7 +22,9 @@ const SearchKeywordsField: React.FC<{ className?: string }> = (props) => {
<SearchField.Label />
<SearchField.Input
autoFocus
placeholder={intl.formatMessage(messages.inputPlaceholder)}
placeholder={props.placeholder ? props.placeholder : intl.formatMessage(
messages.inputPlaceholder
)}
/>
<SearchField.ClearButton />
<SearchField.SubmitButton />
Expand Down

0 comments on commit c95ba13

Please sign in to comment.