| Total Complexity | 2 |
| Complexity/F | 0 |
| Lines of Code | 32 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | import React from 'react'; |
||
| 2 | import PropTypes from 'prop-types'; |
||
| 3 | import { compareVersions } from '../../utils/utils'; |
||
| 4 | import { serverType } from '../prop-types'; |
||
| 5 | |||
| 6 | 1 | const propTypes = { |
|
| 7 | minVersion: PropTypes.string, |
||
| 8 | maxVersion: PropTypes.string, |
||
| 9 | selectedServer: serverType, |
||
| 10 | children: PropTypes.node.isRequired, |
||
| 11 | }; |
||
| 12 | |||
| 13 | 1 | const ForServerVersion = ({ minVersion, maxVersion, selectedServer, children }) => { |
|
| 14 | 9 | if (!selectedServer) { |
|
| 15 | 1 | return null; |
|
| 16 | } |
||
| 17 | |||
| 18 | 8 | const { version } = selectedServer; |
|
| 19 | 8 | const matchesMinVersion = !minVersion || compareVersions(version, '>=', minVersion); |
|
| 20 | 8 | const matchesMaxVersion = !maxVersion || compareVersions(version, '<=', maxVersion); |
|
| 21 | |||
| 22 | 8 | if (!matchesMinVersion || !matchesMaxVersion) { |
|
| 23 | 3 | return null; |
|
| 24 | } |
||
| 25 | |||
| 26 | 5 | return <React.Fragment>{children}</React.Fragment>; |
|
| 27 | }; |
||
| 28 | |||
| 29 | 1 | ForServerVersion.propTypes = propTypes; |
|
| 30 | |||
| 31 | export default ForServerVersion; |
||
| 32 |