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

selectedServer.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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