diff --git a/src/components/VersionBadge/index.js b/src/components/VersionBadge/index.js index 1c8f71ee..793902d4 100644 --- a/src/components/VersionBadge/index.js +++ b/src/components/VersionBadge/index.js @@ -1,15 +1,29 @@ import React from 'react'; +import PropTypes from 'prop-types'; import Admonition from '@theme/Admonition'; import styles from './version-badge.module.css'; -const VersionBadge = ({ version, vclusterVersion }) => { +const VersionBadge = ({ platformVersion, vclusterVersion }) => { + // Validation check - at least one version must be provided + if (!platformVersion && !vclusterVersion) { + console.error('VersionBadge: Either platformVersion or vclusterVersion must be provided'); + return null; + } + return ( - This feature is available from version - {version} + {platformVersion && ( + <> + This feature is available from the platform version + {platformVersion} + + )} + {platformVersion && vclusterVersion && and } {vclusterVersion && ( <> - and was introduced in vCluster version + + {!platformVersion && 'This feature '}was introduced in vCluster version{' '} + {vclusterVersion} )} @@ -17,4 +31,22 @@ const VersionBadge = ({ version, vclusterVersion }) => { ); }; +// Prop validation +VersionBadge.propTypes = { + platformVersion: function(props, propName, componentName) { + if (!props.platformVersion && !props.vclusterVersion) { + return new Error( + `Either 'platformVersion' or 'vclusterVersion' must be provided in '${componentName}'` + ); + } + }, + vclusterVersion: function(props, propName, componentName) { + if (!props.platformVersion && !props.vclusterVersion) { + return new Error( + `Either 'platformVersion' or 'vclusterVersion' must be provided in '${componentName}'` + ); + } + } +}; + export default VersionBadge; \ No newline at end of file