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

Don't render badge container if there is no badge. Change CatalogCategoryLabel interface.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2022-04-01 10:36:09 +03:00
parent 799670ef31
commit 024278a0af
3 changed files with 8 additions and 8 deletions

View File

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

View File

@ -3,19 +3,19 @@
* 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 {
category: CatalogCategory;
label: string | React.ReactNode;
badge?: React.ReactNode;
}
/**
* Display label for Catalog Category for the Catalog menu
*/
export const CatalogCategoryLabel = ({ category }: CatalogCategoryLabelProps) =>
export const CatalogCategoryLabel = ({ label, badge }: CatalogCategoryLabelProps) =>
(
<div className="flex">
<div>{category.metadata.name}</div>
<div className="flex items-center">{category.getBadge()}</div>
<div>{label}</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 category={category} />}
label={<CatalogCategoryLabel label={category.metadata.name} badge={category.getBadge()} />}
data-testid={`${category.getId()}-tab`}
onClick={() => props.onItemClick(category.getId())}
/>