From 624f5addcfe596279929a62dca457c3e8feb7e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Ch=C3=A1vez?= Date: Tue, 19 Nov 2024 16:10:00 -0500 Subject: [PATCH] fix: Show published count component in library content picker (#1481) When using the library component picker, show the correct number on component count (published components) in collection cards. --- .../components/CollectionCard.test.tsx | 22 +++++++++++++++++-- .../components/CollectionCard.tsx | 9 +++++++- src/search-manager/data/api.ts | 2 ++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/library-authoring/components/CollectionCard.test.tsx b/src/library-authoring/components/CollectionCard.test.tsx index 6aa55cdfdf..eefbc7ba53 100644 --- a/src/library-authoring/components/CollectionCard.test.tsx +++ b/src/library-authoring/components/CollectionCard.test.tsx @@ -27,14 +27,24 @@ const CollectionHitSample: CollectionHit = { created: 1722434322294, modified: 1722434322294, numChildren: 2, + published: { + numChildren: 1, + }, tags: {}, }; let axiosMock: MockAdapter; let mockShowToast; -const render = (ui: React.ReactElement) => baseRender(ui, { - extraWrapper: ({ children }) => { children }, +const render = (ui: React.ReactElement, showOnlyPublished: boolean = false) => baseRender(ui, { + extraWrapper: ({ children }) => ( + + { children } + + ), }); describe('', () => { @@ -52,6 +62,14 @@ describe('', () => { expect(screen.queryByText('Collection (2)')).toBeInTheDocument(); }); + it('should render published content', () => { + render(, true); + + expect(screen.queryByText('Collection Display Formated Name')).toBeInTheDocument(); + expect(screen.queryByText('Collection description')).toBeInTheDocument(); + expect(screen.queryByText('Collection (1)')).toBeInTheDocument(); + }); + it('should navigate to the collection if the open menu clicked', async () => { render(); diff --git a/src/library-authoring/components/CollectionCard.tsx b/src/library-authoring/components/CollectionCard.tsx index 3908321449..c7c5164f62 100644 --- a/src/library-authoring/components/CollectionCard.tsx +++ b/src/library-authoring/components/CollectionCard.tsx @@ -111,6 +111,7 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => { const { openCollectionInfoSidebar, componentPickerMode, + showOnlyPublished, } = useLibraryContext(); const { @@ -118,7 +119,13 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => { formatted, tags, numChildren, + published, } = collectionHit; + + const numChildrenCount = showOnlyPublished ? ( + published?.numChildren || 0 + ) : numChildren; + const { displayName = '', description = '' } = formatted; return ( @@ -127,7 +134,7 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => { displayName={displayName} description={description} tags={tags} - numChildren={numChildren} + numChildren={numChildrenCount} actions={!componentPickerMode && ( diff --git a/src/search-manager/data/api.ts b/src/search-manager/data/api.ts index b9bf192ae8..0763000f55 100644 --- a/src/search-manager/data/api.ts +++ b/src/search-manager/data/api.ts @@ -143,6 +143,7 @@ export interface ContentHit extends BaseContentHit { export interface ContentPublishedData { description?: string, displayName?: string, + numChildren?: number, } /** @@ -153,6 +154,7 @@ export interface CollectionHit extends BaseContentHit { type: 'collection'; description: string; numChildren?: number; + published?: ContentPublishedData; } /**