Skip to content

Commit

Permalink
fix: Show published count component in library content picker (#1481) (
Browse files Browse the repository at this point in the history
…#1521)

When using the library component picker, show the correct number on component count (published components) in collection cards.
  • Loading branch information
ChrisChV authored Nov 21, 2024
1 parent 54888d0 commit 13bce7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/library-authoring/components/CollectionCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => <LibraryProvider libraryId="lib:Axim:TEST">{ children }</LibraryProvider>,
const render = (ui: React.ReactElement, showOnlyPublished: boolean = false) => baseRender(ui, {
extraWrapper: ({ children }) => (
<LibraryProvider
libraryId="lib:Axim:TEST"
showOnlyPublished={showOnlyPublished}
>
{ children }
</LibraryProvider>
),
});

describe('<CollectionCard />', () => {
Expand All @@ -52,6 +62,14 @@ describe('<CollectionCard />', () => {
expect(screen.queryByText('Collection (2)')).toBeInTheDocument();
});

it('should render published content', () => {
render(<CollectionCard collectionHit={CollectionHitSample} />, 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(<CollectionCard collectionHit={CollectionHitSample} />);

Expand Down
9 changes: 8 additions & 1 deletion src/library-authoring/components/CollectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,21 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
const {
openCollectionInfoSidebar,
componentPickerMode,
showOnlyPublished,
} = useLibraryContext();

const {
type: componentType,
formatted,
tags,
numChildren,
published,
} = collectionHit;

const numChildrenCount = showOnlyPublished ? (
published?.numChildren || 0
) : numChildren;

const { displayName = '', description = '' } = formatted;

return (
Expand All @@ -127,7 +134,7 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
displayName={displayName}
description={description}
tags={tags}
numChildren={numChildren}
numChildren={numChildrenCount}
actions={!componentPickerMode && (
<ActionRow>
<CollectionMenu collectionHit={collectionHit} />
Expand Down
2 changes: 2 additions & 0 deletions src/search-manager/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface ContentHit extends BaseContentHit {
export interface ContentPublishedData {
description?: string,
displayName?: string,
numChildren?: number,
}

/**
Expand All @@ -153,6 +154,7 @@ export interface CollectionHit extends BaseContentHit {
type: 'collection';
description: string;
numChildren?: number;
published?: ContentPublishedData;
}

/**
Expand Down

0 comments on commit 13bce7e

Please sign in to comment.