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

View File

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

View File

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