increasing test coverage to 20 percent
[aai/sparky-fe.git] / src / app / configurableViews / ConfigurableViewActions.js
1 import {
2   GET,
3   POST_HEADER
4 } from 'app/networking/NetworkConstants.js';
5 import {
6   GET_LAYOUTS_URL,
7   configurableViewsActionTypes
8 } from './ConfigurableViewConstants.js';
9
10 function createConfigReceivedEvent(config) {
11   return {
12     type: configurableViewsActionTypes.CONFIGURABLE_VIEWS_CONFIG_RECEIVED,
13     data: config
14   };
15 }
16
17 export function newCustomComponentsEvent(components) {
18   return {
19     type: configurableViewsActionTypes.CUSTOM_COMPONENTS_RECEIVED,
20     data: components
21   };
22 }
23
24 export function setCustomRoutes(routes) {
25   return {
26     type: configurableViewsActionTypes.CUSTOM_ROUTES,
27     data: routes
28   };
29 }
30
31 export function getConfigurableViewConfigs() {
32   return dispatch => {
33     return fetch(GET_LAYOUTS_URL, {
34       method: GET,
35       headers: POST_HEADER
36     }).then(
37       (response) => response.json()
38     ).then(
39       (responseJson) => {
40         dispatch(createConfigReceivedEvent(responseJson));
41       }
42     ).catch(
43       (err) => {
44         console.log(`problems fetching configurable view configs: ${err}`);
45       }
46     );
47   };
48 }