Skip to content

Commit c95ba13

Browse files
committed
refactor: move messages related to collections in single file
1 parent b826fd1 commit c95ba13

File tree

6 files changed

+90
-80
lines changed

6 files changed

+90
-80
lines changed

src/library-authoring/LibraryLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import LibraryAuthoringPage from './LibraryAuthoringPage';
1313
import { LibraryProvider } from './common/context';
1414
import { CreateCollectionModal } from './create-collection';
1515
import { invalidateComponentData } from './data/apiHooks';
16-
import LibraryCollectionPageWrapper from './collections/LibraryCollectionPage';
16+
import LibraryCollectionPage from './collections/LibraryCollectionPage';
1717

1818
const LibraryLayout = () => {
1919
const { libraryId } = useParams();
@@ -48,7 +48,7 @@ const LibraryLayout = () => {
4848
/>
4949
<Route
5050
path="collections/:collectionId"
51-
element={<LibraryCollectionPageWrapper />}
51+
element={<LibraryCollectionPage />}
5252
/>
5353
<Route
5454
path="*"

src/library-authoring/collections/LibraryCollectionPage.tsx

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Container,
99
Icon,
1010
IconButton,
11-
Row,
1211
Stack,
1312
} from '@openedx/paragon';
1413
import { Add, InfoOutline } from '@openedx/paragon/icons';
@@ -28,7 +27,7 @@ import {
2827
} from '../../search-manager';
2928
import { useCollection, useContentLibrary } from '../data/apiHooks';
3029
import { LibraryContext } from '../common/context';
31-
import messages from '../messages';
30+
import messages from './messages';
3231
import { LibrarySidebar } from '../library-sidebar';
3332
import LibraryCollectionComponents from './LibraryCollectionComponents';
3433

@@ -91,13 +90,13 @@ const SubHeaderTitle = ({
9190
);
9291
};
9392

94-
const LibraryCollectionPage = ({
95-
libraryId,
96-
collectionId,
97-
}: {
98-
libraryId: string;
99-
collectionId: string;
100-
}) => {
93+
const LibraryCollectionPage = () => {
94+
const { libraryId, collectionId } = useParams();
95+
96+
if (!collectionId || !libraryId) {
97+
throw new Error('Rendered without collectionId or libraryId URL parameter');
98+
}
99+
101100
const intl = useIntl();
102101

103102
const {
@@ -147,30 +146,35 @@ const LibraryCollectionPage = ({
147146
isLibrary
148147
/>
149148
<Container size="xl" className="px-4 mt-4 mb-5 library-authoring-page">
150-
<SubHeader
151-
title={<SubHeaderTitle
152-
title={collectionData.title}
153-
canEditLibrary={libraryData.canEditLibrary}
154-
infoClickHandler={openCollectionInfoSidebar}
155-
/>}
156-
breadcrumbs={(
157-
<Breadcrumb
158-
ariaLabel={intl.formatMessage(messages.allCollections)}
159-
links={breadcrumbs}
160-
linkAs={Link}
161-
/>
162-
)}
163-
headerActions={<HeaderActions canEditLibrary={libraryData.canEditLibrary} />}
164-
/>
165-
<SearchKeywordsField className="w-50" />
166-
<div className="d-flex mt-3 mb-4 align-items-center">
167-
<FilterByTags />
168-
<FilterByBlockType />
169-
<ClearFiltersButton />
170-
<div className="flex-grow-1" />
171-
<SearchSortWidget />
172-
</div>
173-
<LibraryCollectionComponents libraryId={libraryId} />
149+
<SearchContextProvider
150+
extraFilter={[`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`]}
151+
fetchCollections={false}
152+
>
153+
<SubHeader
154+
title={<SubHeaderTitle
155+
title={collectionData.title}
156+
canEditLibrary={libraryData.canEditLibrary}
157+
infoClickHandler={openCollectionInfoSidebar}
158+
/>}
159+
breadcrumbs={(
160+
<Breadcrumb
161+
ariaLabel={intl.formatMessage(messages.breadcrumbsAriaLabel)}
162+
links={breadcrumbs}
163+
linkAs={Link}
164+
/>
165+
)}
166+
headerActions={<HeaderActions canEditLibrary={libraryData.canEditLibrary} />}
167+
/>
168+
<SearchKeywordsField className="w-50" placeholder={intl.formatMessage(messages.searchPlaceholder)} />
169+
<div className="d-flex mt-3 mb-4 align-items-center">
170+
<FilterByTags />
171+
<FilterByBlockType />
172+
<ClearFiltersButton />
173+
<div className="flex-grow-1" />
174+
<SearchSortWidget />
175+
</div>
176+
<LibraryCollectionComponents libraryId={libraryId} />
177+
</SearchContextProvider>
174178
</Container>
175179
<StudioFooter />
176180
</div>
@@ -183,20 +187,4 @@ const LibraryCollectionPage = ({
183187
);
184188
};
185189

186-
const LibraryCollectionPageWrapper = () => {
187-
const { libraryId, collectionId } = useParams();
188-
if (!collectionId || !libraryId) {
189-
throw new Error('Rendered without collectionId or libraryId URL parameter');
190-
}
191-
192-
return (
193-
<SearchContextProvider
194-
extraFilter={[`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`]}
195-
fetchCollections={false}
196-
>
197-
<LibraryCollectionPage libraryId={libraryId} collectionId={collectionId} />
198-
</SearchContextProvider>
199-
);
200-
}
201-
202-
export default LibraryCollectionPageWrapper;
190+
export default LibraryCollectionPage;

src/library-authoring/collections/LibraryCollections.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useSearchContext } from '../../search-manager';
66
import { NoComponents, NoSearchResults } from '../EmptyStates';
77
import CollectionCard from '../components/CollectionCard';
88
import { LIBRARY_SECTION_PREVIEW_LIMIT } from '../components/LibrarySection';
9-
import messages from '../messages';
9+
import messages from './messages';
1010
import { LibraryContext } from '../common/context';
1111

1212
type LibraryCollectionsProps = {

src/library-authoring/collections/messages.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,51 @@ const messages = defineMessages({
2626
defaultMessage: 'No matching components found in this collections.',
2727
description: 'Message displayed when no matching components are found in collection',
2828
},
29+
newContentButton: {
30+
id: 'course-authoring.library-authoring.collections.buttons.new-content.text',
31+
defaultMessage: 'New',
32+
description: 'Text of button to open "Add content drawer" in collections page',
33+
},
34+
collectionInfoButton: {
35+
id: 'course-authoring.library-authoring.buttons.collection-info.alt-text',
36+
defaultMessage: 'Collection Info',
37+
description: 'Alt text for collection info button besides the collection title',
38+
},
39+
readOnlyBadge: {
40+
id: 'course-authoring.library-authoring.collections.badge.read-only',
41+
defaultMessage: 'Read Only',
42+
description: 'Text in badge when the user has read only access in collections page',
43+
},
44+
allCollections: {
45+
id: 'course-authoring.library-authoring.all-collections.text',
46+
defaultMessage: 'All Collections',
47+
description: 'Breadcrumbs text to navigate back to all collections',
48+
},
49+
breadcrumbsAriaLabel: {
50+
id: 'course-authoring.library-authoring.breadcrumbs.label.text',
51+
defaultMessage: 'Navigation breadcrumbs',
52+
description: 'Aria label for navigation breadcrumbs',
53+
},
54+
searchPlaceholder: {
55+
id: 'course-authoring.library-authoring.search.placeholder.text',
56+
defaultMessage: 'Search Collection',
57+
description: 'Search placeholder text in collections page.',
58+
},
59+
noSearchResultsCollections: {
60+
id: 'course-authoring.library-authoring.no-search-results-collections',
61+
defaultMessage: 'No matching collections found in this library.',
62+
description: 'Message displayed when no matching collections are found',
63+
},
64+
noCollections: {
65+
id: 'course-authoring.library-authoring.no-collections',
66+
defaultMessage: 'You have not added any collection to this library yet.',
67+
description: 'Message displayed when the library has no collections',
68+
},
69+
addCollection: {
70+
id: 'course-authoring.library-authoring.add-collection',
71+
defaultMessage: 'Add collection',
72+
description: 'Button text to add a new collection',
73+
},
2974
});
3075

3176
export default messages;

src/library-authoring/messages.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ const messages = defineMessages({
66
defaultMessage: 'Content library',
77
description: 'The page heading for the library page.',
88
},
9-
allCollections: {
10-
id: 'course-authoring.library-authoring.all-collections',
11-
defaultMessage: 'All Collections',
12-
description: 'Breadcrumbs text to navigate back to all collections',
13-
},
149
headingInfoAlt: {
1510
id: 'course-authoring.library-authoring.heading-info-alt',
1611
defaultMessage: 'Info',
@@ -26,31 +21,16 @@ const messages = defineMessages({
2621
defaultMessage: 'No matching components found in this library.',
2722
description: 'Message displayed when no search results are found',
2823
},
29-
noSearchResultsCollections: {
30-
id: 'course-authoring.library-authoring.no-search-results-collections',
31-
defaultMessage: 'No matching collections found in this library.',
32-
description: 'Message displayed when no matching collections are found',
33-
},
3424
noComponents: {
3525
id: 'course-authoring.library-authoring.no-components',
3626
defaultMessage: 'You have not added any content to this library yet.',
3727
description: 'Message displayed when the library is empty',
3828
},
39-
noCollections: {
40-
id: 'course-authoring.library-authoring.no-collections',
41-
defaultMessage: 'You have not added any collection to this library yet.',
42-
description: 'Message displayed when the library has no collections',
43-
},
4429
addComponent: {
4530
id: 'course-authoring.library-authoring.add-component',
4631
defaultMessage: 'Add component',
4732
description: 'Button text to add a new component',
4833
},
49-
addCollection: {
50-
id: 'course-authoring.library-authoring.add-collection',
51-
defaultMessage: 'Add collection',
52-
description: 'Button text to add a new collection',
53-
},
5434
homeTab: {
5535
id: 'course-authoring.library-authoring.home-tab',
5636
defaultMessage: 'Home',
@@ -121,11 +101,6 @@ const messages = defineMessages({
121101
defaultMessage: 'Library Info',
122102
description: 'Text of button to open "Library Info sidebar"',
123103
},
124-
collectionInfoButton: {
125-
id: 'course-authoring.library-authoring.buttons.collection-info.alt-text',
126-
defaultMessage: 'Collection Info',
127-
description: 'Alt text for collection info button besides the collection title',
128-
},
129104
readOnlyBadge: {
130105
id: 'course-authoring.library-authoring.badge.read-only',
131106
defaultMessage: 'Read Only',

src/search-manager/SearchKeywordsField.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useSearchContext } from './SearchManager';
77
/**
88
* The "main" input field where users type in search keywords. The search happens as they type (no need to press enter).
99
*/
10-
const SearchKeywordsField: React.FC<{ className?: string }> = (props) => {
10+
const SearchKeywordsField: React.FC<{ className?: string, placeholder?: string }> = (props) => {
1111
const intl = useIntl();
1212
const { searchKeywords, setSearchKeywords } = useSearchContext();
1313

@@ -22,7 +22,9 @@ const SearchKeywordsField: React.FC<{ className?: string }> = (props) => {
2222
<SearchField.Label />
2323
<SearchField.Input
2424
autoFocus
25-
placeholder={intl.formatMessage(messages.inputPlaceholder)}
25+
placeholder={props.placeholder ? props.placeholder : intl.formatMessage(
26+
messages.inputPlaceholder
27+
)}
2628
/>
2729
<SearchField.ClearButton />
2830
<SearchField.SubmitButton />

0 commit comments

Comments
 (0)