| Total Complexity | 5 |
| Complexity/F | 1 |
| Lines of Code | 27 |
| Function Count | 5 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | import { createAction, handleActions } from 'redux-actions'; |
||
| 2 | import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams'; |
||
| 3 | |||
| 4 | /* eslint-disable padding-line-between-statements */ |
||
| 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 */ |
||
| 8 | |||
| 9 | 1 | const initialState = null; |
|
| 10 | |||
| 11 | 1 | export const resetSelectedServer = createAction(RESET_SELECTED_SERVER); |
|
| 12 | |||
| 13 | 2 | export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serverId) => async (dispatch) => { |
|
| 14 | 2 | dispatch(resetShortUrlParams()); |
|
| 15 | |||
| 16 | 2 | const selectedServer = findServerById(serverId); |
|
| 17 | 2 | const { health } = await buildShlinkApiClient(selectedServer); |
|
| 18 | 1 | const { version } = await health(); |
|
| 19 | |||
| 20 | 1 | dispatch({ |
|
| 21 | type: SELECT_SERVER, |
||
| 22 | selectedServer: { |
||
| 23 | ...selectedServer, |
||
| 24 | version, |
||
| 25 | }, |
||
| 26 | }); |
||
| 27 | }; |
||
| 28 | |||
| 33 |