import React from 'react';
import PropTypes from 'prop-types';
import ContentConfig from '../Content/ContentConfig';
const AdditionalCapsuleContent = ({ counts }) => {
const {
deb: debPackageCount = 0,
docker_manifest: dockerManifestCount = 0,
docker_tag: dockerTagCount = 0,
file: fileCount = 0,
erratum: errataCount = 0,
package_group: packageGroup = 0,
'rpm.modulemd': moduleStreamCount = 0,
} = counts;
const contentConfigTypes = ContentConfig.filter(({ names: { capsuleCountLabel } }) =>
!!counts[`${capsuleCountLabel}`])
.map(({
names: {
capsuleCountLabel, pluralLowercase,
},
}) => {
const countParam = `${capsuleCountLabel}`;
const count = counts[countParam];
return {
pluralLowercase,
count,
};
});
return (
<>
{errataCount > 0 &&
<>
{`${errataCount} Errata`}
>
}
{moduleStreamCount > 0 &&
<>
{`${moduleStreamCount} Module streams`}
>
}
{packageGroup > 0 &&
<>
{`${packageGroup} Package groups`}
>
}
{dockerTagCount > 0 &&
<>
{`${dockerTagCount} Container tags`}
>
}
{dockerManifestCount > 0 &&
<>
{`${dockerManifestCount} Container manifests`}
>
}
{fileCount > 0 &&
<>
{`${fileCount} Files`}
>
}
{debPackageCount > 0 &&
<>
{`${debPackageCount} Debian packages`}
>}
{contentConfigTypes?.length > 0 &&
contentConfigTypes.map(({ count, pluralLowercase }) => (
{`${count} ${pluralLowercase}`}
))
}
>
);
};
AdditionalCapsuleContent.propTypes = {
counts: PropTypes.shape({
deb: PropTypes.number,
docker_manifest: PropTypes.number,
docker_tag: PropTypes.number,
file: PropTypes.number,
erratum: PropTypes.number,
package_group: PropTypes.number,
'rpm.modulemd': PropTypes.number,
}),
};
AdditionalCapsuleContent.defaultProps = {
counts: {},
};
export default AdditionalCapsuleContent;