Completed
Pull Request — master (#227)
by Alejandro
06:25
created

src/servers/helpers/withSelectedServer.js   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 36
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 2
eloc 30
mnd 2
bc 2
fnc 0
dl 0
loc 36
ccs 12
cts 14
cp 0.8571
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import React, { useEffect } from 'react';
2
import PropTypes from 'prop-types';
3
import Message from '../../utils/Message';
4
import { serverType } from '../prop-types';
5
6 1
const propTypes = {
7
  selectServer: PropTypes.func,
8
  selectedServer: serverType,
9
  match: PropTypes.object,
10
};
11
12 1
export const withSelectedServer = (WrappedComponent, ServerError) => {
13 2
  const Component = (props) => {
14 2
    const { selectServer, selectedServer, match } = props;
15 2
    const { params: { serverId } } = match;
16
17 2
    useEffect(() => {
18 2
      selectServer(serverId);
19
    }, [ serverId ]);
20
21 2
    if (!selectedServer) {
22
      return <Message loading />;
23
    }
24
25 2
    if (selectedServer.serverNotFound) {
26
      return <ServerError type="not-found" />;
27
    }
28
29 2
    return <WrappedComponent {...props} />;
30
  };
31
32 2
  Component.propTypes = propTypes;
33
34 2
  return Component;
35
};
36