Passed
Pull Request — master (#81)
by Alejandro
06:45
created

src/servers/reducers/selectedServer.js   A

Complexity

Total Complexity 8
Complexity/F 1.6

Size

Lines of Code 35
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 21
c 1
b 0
f 0
nc 1
dl 0
loc 35
rs 10
ccs 13
cts 13
cp 1
crap 0
wmc 8
mnd 1
bc 2
fnc 5
bpm 0.4
cpm 1.6
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A selectedServer.js ➔ reducer 0 10 4
A selectedServer.js ➔ ??? 0 1 1
1
import serversService from '../../servers/services/ServersService';
2
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
3
4
/* eslint-disable padding-line-between-statements, newline-after-var */
5
export const SELECT_SERVER = 'shlink/selectedServer/SELECT_SERVER';
6
export const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
7 5
/* eslint-enable padding-line-between-statements, newline-after-var */
8 5
9
const defaultState = null;
10
11 5
export default function reducer(state = defaultState, action) {
12
  switch (action.type) {
13
    case SELECT_SERVER:
14 3
      return action.selectedServer;
15
    case RESET_SELECTED_SERVER:
16 1
      return defaultState;
17
    default:
18 1
      return state;
19
  }
20 1
}
21
22
export const resetSelectedServer = () => ({ type: RESET_SELECTED_SERVER });
23
24 5
export const _selectServer = (serversService) => (serverId) => (dispatch) => {
25
  dispatch(resetShortUrlParams());
26 5
27 2
  const selectedServer = serversService.findServerById(serverId);
28
29 2
  dispatch({
30
    type: SELECT_SERVER,
31 2
    selectedServer,
32
  });
33 2
};
34
35
export const selectServer = _selectServer(serversService);
36