Skip to content

Commit f91c9ef

Browse files
committed
feat: show published children when showing only published Unit content
1 parent 49a0bc3 commit f91c9ef

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/library-authoring/components/ContainerCard.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,25 @@ describe('<ContainerCard />', () => {
183183
expect((await screen.findAllByTitle(/lb:org1:Demo_course:html:text-*/)).length).toBe(4);
184184
expect(screen.queryByText('+2')).toBeInTheDocument();
185185
});
186+
187+
it('should render published child blocks when rendering a published card preview', async () => {
188+
const containerWithPublishedChildren = {
189+
...containerHitSample,
190+
content: {
191+
childUsageKeys: Array(6).fill('').map((_child, idx) => `lb:org1:Demo_course:html:text-${idx}`),
192+
},
193+
published: {
194+
content: {
195+
childUsageKeys: Array(2).fill('').map((_child, idx) => `lb:org1:Demo_course:html:text-${idx}`),
196+
},
197+
},
198+
} satisfies ContainerHit;
199+
render(
200+
<ContainerCard hit={containerWithPublishedChildren} />,
201+
true,
202+
);
203+
204+
expect((await screen.findAllByTitle(/lb:org1:Demo_course:html:text-*/)).length).toBe(2);
205+
expect(screen.queryByText('+2')).not.toBeInTheDocument();
206+
});
186207
});

src/library-authoring/components/ContainerCard.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ const ContainerMenu = ({ hit } : ContainerMenuProps) => {
108108
};
109109

110110
type ContainerCardPreviewProps = {
111-
hit: ContainerHit,
111+
childUsageKeys: Array<string>;
112112
showMaxChildren?: number;
113113
};
114114

115-
const ContainerCardPreview = ({ hit, showMaxChildren = 5 }: ContainerCardPreviewProps) => {
116-
const { content } = hit;
117-
const { childUsageKeys } = content ?? { childUsageKeys: [] };
115+
const ContainerCardPreview = ({ childUsageKeys, showMaxChildren = 5 }: ContainerCardPreviewProps) => {
118116
const hiddenChildren = childUsageKeys.length - showMaxChildren;
119117
return (
120118
<Stack direction="horizontal" gap={2}>
@@ -175,6 +173,7 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
175173
published,
176174
publishStatus,
177175
usageKey: unitId,
176+
content,
178177
} = hit;
179178

180179
const numChildrenCount = showOnlyPublished ? (
@@ -185,6 +184,11 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
185184
showOnlyPublished ? formatted.published?.displayName : formatted.displayName
186185
) ?? '';
187186

187+
published.content = published?.content ?? {};
188+
const childUsageKeys: Array<string> = (
189+
showOnlyPublished ? published.content?.childUsageKeys : content?.childUsageKeys
190+
) ?? [];
191+
188192
const { navigateTo } = useLibraryRoutes();
189193

190194
const openContainer = useCallback(() => {
@@ -199,7 +203,7 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
199203
<BaseCard
200204
itemType={itemType}
201205
displayName={displayName}
202-
preview={<ContainerCardPreview hit={hit} />}
206+
preview={<ContainerCardPreview childUsageKeys={childUsageKeys} />}
203207
tags={tags}
204208
numChildren={numChildrenCount}
205209
actions={(

src/search-manager/data/api.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const getContentSearchConfig = async (): Promise<{ url: string, indexName
5050
export interface ContentDetails {
5151
htmlContent?: string;
5252
capaContent?: string;
53+
childUsageKeys?: Array<string>;
5354
[k: string]: any;
5455
}
5556

@@ -151,9 +152,10 @@ export interface ContentHit extends BaseContentHit {
151152
* Defined in edx-platform/openedx/core/djangoapps/content/search/documents.py
152153
*/
153154
export interface ContentPublishedData {
154-
description?: string,
155-
displayName?: string,
156-
numChildren?: number,
155+
description?: string;
156+
displayName?: string;
157+
numChildren?: number;
158+
content?: ContentDetails;
157159
}
158160

159161
/**
@@ -172,7 +174,7 @@ export interface CollectionHit extends BaseContentHit {
172174
* Defined in edx-platform/openedx/core/djangoapps/content/search/documents.py
173175
*/
174176
interface ContainerHitContent {
175-
childUsageKeys: string[],
177+
childUsageKeys?: string[],
176178
}
177179
export interface ContainerHit extends BaseContentHit {
178180
type: 'library_container';

0 commit comments

Comments
 (0)