/
actions.js
51 lines (40 loc) · 1.79 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { createAction, createThunkAction } from 'redux-tools';
// services
import { fetchFields } from 'services/fields';
// utils
import { getFieldUrl } from 'utils/fields';
export const setCurrentInteractions = createAction('LAYER-INTERACTIONS__SET_CURRENT_INTERACTIONS');
export const setAvailabletInteractions = createAction('LAYER-INTERACTIONS__SET_AVAILABLE_INTERACTIONS');
export const setLoading = createAction('LAYER-INTERACTIONS__SET-LOADING');
export const resetInteractions = createAction('LAYER-INTERACTIONS__RESET_INTERACTIONS');
export const getCurrentLayerInteractions = createThunkAction('LAYER-INTERACTIONS__GET-CURRENT-LAYER-INTERACTIONS', props => (dispatch) => {
const { layer } = props;
const { interactionConfig: { output } } = layer;
if (output) dispatch(setCurrentInteractions(output));
});
export const getAvailableLayerInteractions = createThunkAction('LAYER-INTERACTIONS__GET-AVAILABLE-LAYER-INTERACTIONS', props => (dispatch) => {
const { layer } = props;
dispatch(setLoading(true));
if (layer && layer.provider !== 'wms') {
const url = getFieldUrl({ id: layer.dataset });
return fetchFields(url)
.then((response) => {
const rawFields = response.fields;
const parsedFields = ((rawFields && Object.keys(rawFields)) || []).map((fKey) => {
const { type } = rawFields[fKey] || null;
return { label: fKey || '', value: fKey || '', type };
});
dispatch(setAvailabletInteractions(parsedFields));
dispatch(setLoading(false));
});
}
return new Promise((reject) => { reject('Layer provider not supported for getting fields'); });
});
export default {
setCurrentInteractions,
setAvailabletInteractions,
setLoading,
resetInteractions,
getCurrentLayerInteractions,
getAvailableLayerInteractions
};