From 06c668d4f962aec61df902c28cb22f6ed3801e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cintia=20S=C3=A1nchez=20Garc=C3=ADa?= Date: Wed, 17 Apr 2024 17:53:46 +0200 Subject: [PATCH] Add Helm charts values schema badge (#3772) Signed-off-by: Cintia Sanchez Garcia --- web/src/layout/common/PackageCard.tsx | 7 + .../__snapshots__/PackageCard.test.tsx.snap | 157 ++++++++++++++++++ web/src/layout/common/badges/ValuesSchema.tsx | 42 +++++ .../package/__snapshots__/index.test.tsx.snap | 157 ++++++++++++++++++ web/src/layout/package/index.tsx | 8 + widget/public/index.html | 2 +- widget/src/layout/Group.tsx | 8 +- widget/src/layout/Widget.tsx | 7 +- .../layout/__snapshots__/Group.test.tsx.snap | 6 +- .../layout/__snapshots__/Widget.test.tsx.snap | 4 +- widget/src/layout/common/Label.test.tsx | 5 + widget/src/layout/common/Label.tsx | 4 + widget/src/layout/common/SVGIcons.tsx | 14 ++ widget/src/types.ts | 1 + 14 files changed, 413 insertions(+), 9 deletions(-) create mode 100644 web/src/layout/common/badges/ValuesSchema.tsx diff --git a/web/src/layout/common/PackageCard.tsx b/web/src/layout/common/PackageCard.tsx index 2ef62a707..d98490d0f 100644 --- a/web/src/layout/common/PackageCard.tsx +++ b/web/src/layout/common/PackageCard.tsx @@ -21,6 +21,7 @@ import CNCF from './badges/CNCF'; import Deprecated from './badges/Deprecated'; import Official from './badges/Official'; import Signed from './badges/Signed'; +import ValuesSchemaBadge from './badges/ValuesSchema'; import VerifiedPublisher from './badges/VerifiedPublisher'; import styles from './PackageCard.module.css'; import PackageCategoryLabel from './PackageCategoryLabel'; @@ -273,6 +274,12 @@ const PackageCard = (props: Props) => {
{props.package.deprecated && } {(props.package.cncf || props.package.repository.cncf) && } + {props.package.repository.kind === RepositoryKind.Helm && ( + + )} +
+
+
+ +
+
+
+
+ + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+ +
+
diff --git a/web/src/layout/common/badges/ValuesSchema.tsx b/web/src/layout/common/badges/ValuesSchema.tsx new file mode 100644 index 000000000..3a743bb08 --- /dev/null +++ b/web/src/layout/common/badges/ValuesSchema.tsx @@ -0,0 +1,42 @@ +import { isNull, isUndefined } from 'lodash'; +import { CgListTree } from 'react-icons/cg'; + +import Badge from './Badge'; + +interface Props { + hasValuesSchema: boolean; + className?: string; + dropdownAlignment?: 'start' | 'end'; + noDropdown?: boolean; + smallSize?: boolean; +} + +const ValuesSchemaBadge = (props: Props) => { + const hasValuesSchema = + !isNull(props.hasValuesSchema) && !isUndefined(props.hasValuesSchema) && props.hasValuesSchema; + + return ( + } + active={hasValuesSchema} + className={props.className} + dropdownAlignment={props.dropdownAlignment} + noDropdown={props.noDropdown} + smallSize={props.smallSize} + popoverContent={ + <> +
Values schema
+ +

+ This chart {hasValuesSchema ? 'provides' : 'does not provide'} a{' '} + values schema. +

+ + } + /> + ); +}; + +export default ValuesSchemaBadge; diff --git a/web/src/layout/package/__snapshots__/index.test.tsx.snap b/web/src/layout/package/__snapshots__/index.test.tsx.snap index 59f468bd4..d65b6a07d 100644 --- a/web/src/layout/package/__snapshots__/index.test.tsx.snap +++ b/web/src/layout/package/__snapshots__/index.test.tsx.snap @@ -499,6 +499,163 @@ exports[`Package index creates snapshot 1`] = `
+
+
+
+ +
+
+
+
+ + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+ +
+
diff --git a/web/src/layout/package/index.tsx b/web/src/layout/package/index.tsx index 3c9af7596..1a7b6f2d4 100644 --- a/web/src/layout/package/index.tsx +++ b/web/src/layout/package/index.tsx @@ -44,6 +44,7 @@ import CNCF from '../common/badges/CNCF'; import Deprecated from '../common/badges/Deprecated'; import Official from '../common/badges/Official'; import Signed from '../common/badges/Signed'; +import ValuesSchemaBagde from '../common/badges/ValuesSchema'; import VerifiedPublisher from '../common/badges/VerifiedPublisher'; import BlockCodeButtons from '../common/BlockCodeButtons'; import ContentDefaultModal from '../common/ContentDefaultModal'; @@ -931,6 +932,13 @@ const PackageView = () => {
{detail.deprecated && } {(detail.cncf || detail.repository.cncf) && } + {detail.repository.kind === RepositoryKind.Helm && ( + + )} -
+
diff --git a/widget/src/layout/Group.tsx b/widget/src/layout/Group.tsx index b89377ce8..a8848b975 100644 --- a/widget/src/layout/Group.tsx +++ b/widget/src/layout/Group.tsx @@ -3,7 +3,7 @@ import { Fragment, useEffect, useState } from 'react'; import styled from 'styled-components'; import API from '../api'; -import { PackageSummary } from '../types'; +import { PackageSummary, RepositoryKind } from '../types'; import Loading from './common/Loading'; import Widget from './Widget'; @@ -52,7 +52,11 @@ const hasBadges = (packages: PackageSummary[] | null): boolean => { if (packages) { return some( packages, - (pkg: PackageSummary) => pkg.official || pkg.repository.official || pkg.repository.verifiedPublisher + (pkg: PackageSummary) => + pkg.official || + pkg.repository.official || + pkg.repository.verifiedPublisher || + (pkg.repository.kind === RepositoryKind.Helm && pkg.hasValuesSchema) ); } diff --git a/widget/src/layout/Widget.tsx b/widget/src/layout/Widget.tsx index 4636b7b55..8f4e07af2 100644 --- a/widget/src/layout/Widget.tsx +++ b/widget/src/layout/Widget.tsx @@ -466,12 +466,17 @@ export default function Widget(props: Props) { {(packageSummary.official || packageSummary.repository.official || - packageSummary.repository.verifiedPublisher) && ( + packageSummary.repository.verifiedPublisher || + (packageSummary.repository.kind === RepositoryKind.Helm && packageSummary.hasValuesSchema)) && ( {packageSummary.deprecated &&