PluginProbe
ElasticPress / 4.7.1
ElasticPress v4.7.1
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / assets / js / blocks / store.js

store.js in ElasticPress 4.7.1, at assets/js/blocks/store.js

143 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies.
3 */
4 import apiFetch from '@wordpress/api-fetch';
5
6 const initialState = {
7 metaKeys: [],
8 metaRanges: {},
9 taxonomies: {},
10 };
11
12 const reducer = (state, action) => {
13 switch (action.type) {
14 case 'SET_META_KEYS': {
15 return {
16 ...state,
17 metaKeys: action.metaKeys,
18 };
19 }
20 case 'SET_TAXONOMIES': {
21 return {
22 ...state,
23 taxonomies: action.taxonomies,
24 };
25 }
26 case 'SET_META_RANGE': {
27 return {
28 ...state,
29 metaRanges: {
30 ...state.metaRanges,
31 [action.key]: action.metaRange,
32 },
33 };
34 }
35 default: {
36 return state;
37 }
38 }
39 };
40
41 const actions = {
42 setMetaKeys(metaKeys) {
43 return {
44 type: 'SET_META_KEYS',
45 metaKeys,
46 };
47 },
48 getMetaKeys() {
49 return {
50 type: 'GET_META_KEYS',
51 };
52 },
53 setTaxonomies(taxonomies) {
54 return {
55 type: 'SET_TAXONOMIES',
56 taxonomies,
57 };
58 },
59 getTaxonomies() {
60 return {
61 type: 'GET_TAXONOMIES',
62 };
63 },
64 setMetaRange(key, metaRange) {
65 return {
66 type: 'SET_META_RANGE',
67 key,
68 metaRange,
69 };
70 },
71 getMetaRange(key) {
72 return {
73 type: 'GET_META_RANGE',
74 key,
75 };
76 },
77 };
78
79 const selectors = {
80 getMetaKeys(state) {
81 const { metaKeys } = state;
82
83 return metaKeys;
84 },
85 getTaxonomies(state) {
86 const { taxonomies } = state;
87
88 return taxonomies;
89 },
90 getMetaRange(state, key) {
91 const {
92 metaRanges: { [key]: rangePreview },
93 } = state;
94
95 return rangePreview;
96 },
97 };
98
99 const controls = {
100 GET_META_KEYS() {
101 return apiFetch({ path: 'elasticpress/v1/facets/meta/keys' });
102 },
103 GET_TAXONOMIES() {
104 return apiFetch({ path: 'elasticpress/v1/facets/taxonomies' });
105 },
106 GET_META_RANGE({ key }) {
107 const params = new URLSearchParams({ facet: key });
108
109 return apiFetch({
110 path: `/elasticpress/v1/facets/meta-range/block-preview?${params}`,
111 });
112 },
113 };
114
115 const resolvers = {
116 *getMetaKeys() {
117 const metaKeys = yield actions.getMetaKeys();
118
119 return actions.setMetaKeys(metaKeys);
120 },
121 *getTaxonomies() {
122 const taxonomies = yield actions.getTaxonomies();
123
124 return actions.setTaxonomies(taxonomies);
125 },
126 *getMetaRange(key) {
127 const { data: { min = false, max = false } = {} } = yield actions.getMetaRange(key);
128
129 return actions.setMetaRange(key, { min, max });
130 },
131 };
132
133 const store = {
134 reducer,
135 controls,
136 selectors,
137 resolvers,
138 actions,
139 initialState,
140 };
141
142 export default store;
143