1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use category as prop in CatalogCategoryLabel

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2022-04-06 14:46:08 +03:00
parent d34551fe8c
commit b5d841eb4e
3 changed files with 11 additions and 8 deletions

View File

@ -37,7 +37,7 @@ describe("CatalogCategoryLabel", () => {
it("renders without a badge", async () => { it("renders without a badge", async () => {
const category = new CatalogCategoryWithoutBadge(); const category = new CatalogCategoryWithoutBadge();
render(<CatalogCategoryLabel label={category.metadata.name} badge={category.getBadge()}/>); render(<CatalogCategoryLabel category={category}/>);
expect(await screen.findByText("Test Category")).toBeInTheDocument(); expect(await screen.findByText("Test Category")).toBeInTheDocument();
}); });
@ -45,7 +45,7 @@ describe("CatalogCategoryLabel", () => {
it("renders with a badge", async () => { it("renders with a badge", async () => {
const category = new CatalogCategoryWithBadge(); const category = new CatalogCategoryWithBadge();
render(<CatalogCategoryLabel label={category.metadata.name} badge={category.getBadge()}/>); render(<CatalogCategoryLabel category={category}/>);
expect(await screen.findByText("Test Category")).toBeInTheDocument(); expect(await screen.findByText("Test Category")).toBeInTheDocument();
expect(await screen.findByText("Test Badge")).toBeInTheDocument(); expect(await screen.findByText("Test Badge")).toBeInTheDocument();

View File

@ -3,19 +3,22 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import React from "react"; import React from "react";
import type { CatalogCategory } from "../../../common/catalog/catalog-entity";
interface CatalogCategoryLabelProps { interface CatalogCategoryLabelProps {
label: string | React.ReactNode; category: CatalogCategory;
badge?: React.ReactNode;
} }
/** /**
* Display label for Catalog Category for the Catalog menu * Display label for Catalog Category for the Catalog menu
*/ */
export const CatalogCategoryLabel = ({ label, badge }: CatalogCategoryLabelProps) => export const CatalogCategoryLabel = ({ category }: CatalogCategoryLabelProps) => {
( const badge = category.getBadge();
return (
<div className="flex"> <div className="flex">
<div>{label}</div> <div>{category.metadata.name}</div>
{badge ? (<div className="flex items-center">{badge}</div>) : null} {badge ? (<div className="flex items-center">{badge}</div>) : null}
</div> </div>
); );
};

View File

@ -67,7 +67,7 @@ export const CatalogMenu = observer((props: CatalogMenuProps) => {
icon={getCategoryIcon(category)} icon={getCategoryIcon(category)}
key={category.getId()} key={category.getId()}
nodeId={category.getId()} nodeId={category.getId()}
label={<CatalogCategoryLabel label={category.metadata.name} badge={category.getBadge()} />} label={<CatalogCategoryLabel category={category}/>}
data-testid={`${category.getId()}-tab`} data-testid={`${category.getId()}-tab`}
onClick={() => props.onItemClick(category.getId())} onClick={() => props.onItemClick(category.getId())}
/> />