Passed
Pull Request — master (#195)
by Alejandro
06:13
created

src/servers/helpers/ForServerVersion.js   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 32
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 27
mnd 2
bc 2
fnc 0
dl 0
loc 32
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
ccs 11
cts 11
cp 1
rs 10
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