Completed
Pull Request — master (#81)
by Alejandro
03:28
created

src/servers/reducers/selectedServer.js   A

Complexity

Total Complexity 8
Complexity/F 1.6

Size

Lines of Code 32
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 19
nc 1
dl 0
loc 32
ccs 12
cts 12
cp 1
crap 0
rs 10
c 1
b 0
f 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 { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
2
3
/* eslint-disable padding-line-between-statements, newline-after-var */
4 1
export const SELECT_SERVER = 'shlink/selectedServer/SELECT_SERVER';
5 1
export const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
6
/* eslint-enable padding-line-between-statements, newline-after-var */
7
8 1
const defaultState = null;
9
10
export default function reducer(state = defaultState, action) {
11 3
  switch (action.type) {
12
    case SELECT_SERVER:
13 1
      return action.selectedServer;
14
    case RESET_SELECTED_SERVER:
15 1
      return defaultState;
16
    default:
17 1
      return state;
18
  }
19
}
20
21 1
export const resetSelectedServer = () => ({ type: RESET_SELECTED_SERVER });
22
23 2
export const selectServer = (serversService) => (serverId) => (dispatch) => {
24 2
  dispatch(resetShortUrlParams());
25
26 2
  const selectedServer = serversService.findServerById(serverId);
27
28 2
  dispatch({
29
    type: SELECT_SERVER,
30
    selectedServer,
31
  });
32
};
33