@blaze-cms/plugin-google-maps-fe 0.123.0-alpha.8 → 0.123.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +243 -832
  2. package/lib/GoogleMaps/GoogleMaps.js +68 -40
  3. package/lib/GoogleMaps/GoogleMaps.js.map +1 -1
  4. package/lib/GoogleMaps/GoogleMapsFactory.js +8 -4
  5. package/lib/GoogleMaps/GoogleMapsFactory.js.map +1 -1
  6. package/lib/GoogleMaps/GoogleMapsRender.js +24 -41
  7. package/lib/GoogleMaps/GoogleMapsRender.js.map +1 -1
  8. package/lib/GoogleMaps/helpers/add-zoom-listener.js +3 -50
  9. package/lib/GoogleMaps/helpers/add-zoom-listener.js.map +1 -1
  10. package/lib/GoogleMaps/helpers/build-map-shapes.js +97 -0
  11. package/lib/GoogleMaps/helpers/build-map-shapes.js.map +1 -0
  12. package/lib/GoogleMaps/helpers/build-query.js +24 -14
  13. package/lib/GoogleMaps/helpers/build-query.js.map +1 -1
  14. package/lib/GoogleMaps/helpers/build-shapes-configs.js +196 -0
  15. package/lib/GoogleMaps/helpers/build-shapes-configs.js.map +1 -0
  16. package/lib/GoogleMaps/helpers/get-center-coordinates.js +49 -0
  17. package/lib/GoogleMaps/helpers/get-center-coordinates.js.map +1 -0
  18. package/lib/GoogleMaps/helpers/get-image-ids.js +16 -14
  19. package/lib/GoogleMaps/helpers/get-image-ids.js.map +1 -1
  20. package/lib/GoogleMaps/helpers/index.js +21 -5
  21. package/lib/GoogleMaps/helpers/index.js.map +1 -1
  22. package/lib/GoogleMaps/helpers/set-shapes.js +213 -200
  23. package/lib/GoogleMaps/helpers/set-shapes.js.map +1 -1
  24. package/lib/GoogleMaps/hooks/use-get-images.js +3 -2
  25. package/lib/GoogleMaps/hooks/use-get-images.js.map +1 -1
  26. package/lib/GoogleMaps/queries.js +22 -4
  27. package/lib/GoogleMaps/queries.js.map +1 -1
  28. package/lib-es/GoogleMaps/GoogleMaps.js +51 -25
  29. package/lib-es/GoogleMaps/GoogleMaps.js.map +1 -1
  30. package/lib-es/GoogleMaps/GoogleMapsFactory.js +10 -6
  31. package/lib-es/GoogleMaps/GoogleMapsFactory.js.map +1 -1
  32. package/lib-es/GoogleMaps/GoogleMapsRender.js +24 -32
  33. package/lib-es/GoogleMaps/GoogleMapsRender.js.map +1 -1
  34. package/lib-es/GoogleMaps/helpers/add-zoom-listener.js +3 -23
  35. package/lib-es/GoogleMaps/helpers/add-zoom-listener.js.map +1 -1
  36. package/lib-es/GoogleMaps/helpers/build-map-shapes.js +86 -0
  37. package/lib-es/GoogleMaps/helpers/build-map-shapes.js.map +1 -0
  38. package/lib-es/GoogleMaps/helpers/build-query.js +17 -8
  39. package/lib-es/GoogleMaps/helpers/build-query.js.map +1 -1
  40. package/lib-es/GoogleMaps/helpers/build-shapes-configs.js +134 -0
  41. package/lib-es/GoogleMaps/helpers/build-shapes-configs.js.map +1 -0
  42. package/lib-es/GoogleMaps/helpers/get-center-coordinates.js +31 -0
  43. package/lib-es/GoogleMaps/helpers/get-center-coordinates.js.map +1 -0
  44. package/lib-es/GoogleMaps/helpers/get-image-ids.js +9 -14
  45. package/lib-es/GoogleMaps/helpers/get-image-ids.js.map +1 -1
  46. package/lib-es/GoogleMaps/helpers/index.js +4 -2
  47. package/lib-es/GoogleMaps/helpers/index.js.map +1 -1
  48. package/lib-es/GoogleMaps/helpers/set-shapes.js +80 -125
  49. package/lib-es/GoogleMaps/helpers/set-shapes.js.map +1 -1
  50. package/lib-es/GoogleMaps/hooks/use-get-images.js +4 -3
  51. package/lib-es/GoogleMaps/hooks/use-get-images.js.map +1 -1
  52. package/lib-es/GoogleMaps/queries.js +23 -2
  53. package/lib-es/GoogleMaps/queries.js.map +1 -1
  54. package/package.json +4 -4
  55. package/src/GoogleMaps/GoogleMaps.js +40 -27
  56. package/src/GoogleMaps/GoogleMapsFactory.js +11 -4
  57. package/src/GoogleMaps/GoogleMapsRender.js +22 -21
  58. package/src/GoogleMaps/helpers/add-zoom-listener.js +3 -22
  59. package/src/GoogleMaps/helpers/build-map-shapes.js +70 -0
  60. package/src/GoogleMaps/helpers/build-query.js +25 -10
  61. package/src/GoogleMaps/helpers/build-shapes-configs.js +110 -0
  62. package/src/GoogleMaps/helpers/get-center-coordinates.js +24 -0
  63. package/src/GoogleMaps/helpers/get-image-ids.js +6 -15
  64. package/src/GoogleMaps/helpers/index.js +12 -2
  65. package/src/GoogleMaps/helpers/set-shapes.js +87 -123
  66. package/src/GoogleMaps/hooks/use-get-images.js +4 -3
  67. package/src/GoogleMaps/queries.js +30 -3
  68. package/lib/GoogleMaps/helpers/set-entity-configs.js +0 -144
  69. package/lib/GoogleMaps/helpers/set-entity-configs.js.map +0 -1
  70. package/lib-es/GoogleMaps/helpers/set-entity-configs.js +0 -94
  71. package/lib-es/GoogleMaps/helpers/set-entity-configs.js.map +0 -1
  72. package/src/GoogleMaps/helpers/set-entity-configs.js +0 -84
@@ -0,0 +1,110 @@
1
+ import flatten from 'lodash.flatten';
2
+ import { IMAGE_ID, URL, ID } from '../../constants';
3
+
4
+ const getPropValues = properties =>
5
+ properties
6
+ .reduce((acc, property) => {
7
+ if (property.includes('.')) {
8
+ const [relationName, relationProp] = property.split('.');
9
+ return `${acc} ${relationName} { ${relationProp} }`;
10
+ }
11
+ return `${acc} ${property}`;
12
+ }, '')
13
+ .trim();
14
+
15
+ const getUpdatedPropsQuery = (propsQuery, entityData) => {
16
+ const { properties = {}, dynamicProperties = {} } = entityData;
17
+
18
+ const [url] = Object.keys(dynamicProperties).filter(prop => prop === URL);
19
+ const hasImage = !!Object.keys(properties).filter(prop => prop === IMAGE_ID).length;
20
+
21
+ let updatedPropsQuery = hasImage ? `${propsQuery} ${IMAGE_ID}` : propsQuery;
22
+ updatedPropsQuery = url ? `${updatedPropsQuery} ${URL}` : updatedPropsQuery;
23
+
24
+ return updatedPropsQuery;
25
+ };
26
+
27
+ const buildFilterQueryString = filter => {
28
+ const [filterKey, filterValue] = filter.split('/');
29
+ const filterKeyword = `${filterKey}.keyword`;
30
+ return { bool: { should: [{ match: { [filterKeyword]: filterValue } }] } };
31
+ };
32
+
33
+ const buildFilters = filters => {
34
+ if (!filters || !filters.length) return null;
35
+ const filterQueryProps = filters.map(buildFilterQueryString);
36
+ return { bool: { should: filterQueryProps } };
37
+ };
38
+
39
+ const buiildShapeProps = (shape, shapeKey, dataSummaries, parentId, entityData, entityGroup) => {
40
+ const { displayItems = [], filterBy } = shape;
41
+ const { latProp, lonProp, entity } = entityGroup;
42
+ const { actions } = entityData;
43
+ const action = actions ? actions.getAllPublished || actions.getAll : '';
44
+
45
+ const dataSummaryProps = dataSummaries
46
+ .reduce((acc, { propsToDisplay }) => {
47
+ const propsToDisplayValues = flatten(
48
+ propsToDisplay.map(({ propertiesToDisplay }) => propertiesToDisplay)
49
+ );
50
+ const propsToDisplayString = getPropValues(propsToDisplayValues);
51
+
52
+ return `${acc} ${propsToDisplayString}`;
53
+ }, '')
54
+ .trim();
55
+ const ids = [];
56
+ displayItems.length ? ids.push(displayItems[0]) : ids.push(parentId);
57
+
58
+ const filtersObject = buildFilters(filterBy);
59
+ let propsQuery = dataSummaryProps ? `${dataSummaryProps}` : '';
60
+ propsQuery = getUpdatedPropsQuery(propsQuery, entityData);
61
+ if (latProp && lonProp) {
62
+ propsQuery = `${propsQuery} ${formatProp(latProp)} ${formatProp(lonProp)}`;
63
+ }
64
+ if (ids.length && !propsQuery.includes(ID)) propsQuery = `${propsQuery.trim()} ${ID}`;
65
+
66
+ return {
67
+ shapeKey,
68
+ entity,
69
+ propsQuery,
70
+ ids,
71
+ action,
72
+ filtersObject
73
+ };
74
+ };
75
+
76
+ const formatProp = prop => {
77
+ if (!prop.includes('.')) return prop;
78
+
79
+ const [mainProp, nestedProp] = prop.split('.');
80
+ return `${mainProp}{${nestedProp}}`;
81
+ };
82
+
83
+ const buildShapesConfig = (schemas, entityGroups, parent) => {
84
+ if (!schemas || !entityGroups) return [];
85
+ const { itemId, itemEntity } = parent;
86
+ const shapeGroups = [];
87
+ entityGroups.forEach((entityGroup, i) => {
88
+ const { entity, shapes, dataSummaries = [] } = entityGroup;
89
+ const parentId = entity === itemEntity && itemId;
90
+ if (!entity) return null;
91
+ const entityData = schemas[entity] || {};
92
+
93
+ shapes.filter(Boolean).forEach((shape, shapeIndex) => {
94
+ const shapeKey = `shape${i}${shapeIndex}`;
95
+ const shapeValues = buiildShapeProps(
96
+ shape,
97
+ shapeKey,
98
+ dataSummaries,
99
+ parentId,
100
+ entityData,
101
+ entityGroup
102
+ );
103
+ shapeGroups.push({ ...shapeValues, shapeOptions: shape, entityOptions: entityGroup });
104
+ });
105
+ });
106
+
107
+ return shapeGroups;
108
+ };
109
+
110
+ export default buildShapesConfig;
@@ -0,0 +1,24 @@
1
+ import isNumber from 'lodash.isnumber';
2
+
3
+ const getCenterCoordinates = (mapShapes, otherProps) => {
4
+ const centerCoordinates = [];
5
+
6
+ const { centerLatitude, centerLongitude } = otherProps;
7
+ const useDefaultCenter =
8
+ centerLatitude !== 0 &&
9
+ centerLongitude !== 0 &&
10
+ isNumber(centerLatitude) &&
11
+ isNumber(centerLongitude);
12
+
13
+ if (useDefaultCenter) return [{ latitude: centerLatitude, longitude: centerLongitude }];
14
+
15
+ const useAsCenterShapes = mapShapes.filter(({ useAsCenter }) => useAsCenter);
16
+ const shapesForCenter = useAsCenterShapes.length ? useAsCenterShapes : mapShapes;
17
+ shapesForCenter.forEach(({ latitude, longitude }) => {
18
+ if (isNumber(latitude) && isNumber(longitude)) centerCoordinates.push({ latitude, longitude });
19
+ });
20
+
21
+ return centerCoordinates;
22
+ };
23
+
24
+ export default getCenterCoordinates;
@@ -1,19 +1,10 @@
1
- const getImageIds = (entityConfigs, entityData) => {
2
- const images = [];
3
-
4
- Object.keys(entityConfigs).forEach(entityConfig => {
5
- const { imageIds } = entityConfigs[entityConfig];
6
-
7
- images.push(...imageIds);
8
-
9
- if (entityData[entityConfig] && entityData[entityConfig].length) {
10
- entityData[entityConfig].forEach(entity => {
11
- if (entity.imageId) images.push(entity.imageId);
12
- });
13
- }
1
+ const getImageIds = mapShapes => {
2
+ const ids = [];
3
+ mapShapes.forEach(({ shapeData, imageId }) => {
4
+ if (imageId) ids.push(imageId);
5
+ if (shapeData.imageId) ids.push(shapeData.imageId);
14
6
  });
15
-
16
- return images;
7
+ return [...new Set(ids)];
17
8
  };
18
9
 
19
10
  export default getImageIds;
@@ -1,7 +1,17 @@
1
1
  import addZoomListener from './add-zoom-listener';
2
2
  import buildQuery from './build-query';
3
3
  import getImageIds from './get-image-ids';
4
- import setEntityConfigs from './set-entity-configs';
4
+ import buildShapesConfig from './build-shapes-configs';
5
5
  import setMapOptions from './set-map-options';
6
+ import getCenterCoordinates from './get-center-coordinates';
7
+ import buildMapShapes from './build-map-shapes';
6
8
 
7
- export { addZoomListener, buildQuery, getImageIds, setEntityConfigs, setMapOptions };
9
+ export {
10
+ addZoomListener,
11
+ buildQuery,
12
+ getImageIds,
13
+ buildShapesConfig,
14
+ setMapOptions,
15
+ getCenterCoordinates,
16
+ buildMapShapes
17
+ };
@@ -37,20 +37,18 @@ const closeInfoWindows = () => {
37
37
  }
38
38
  };
39
39
 
40
- const addShapeListeners = (map, router, shape, entityData, imageData, shapeInstance) => {
41
- const { displayItems, entity, enableInfoPane = false, dataSummaries = [] } = shape;
42
-
43
- const url = getEntityUrl(displayItems, entity, entityData);
40
+ const addShapeListeners = (map, router, shape, imageData, shapeInstance) => {
41
+ const { enableInfoPane = false, dataSummaries = [], url, shapeData } = shape;
44
42
 
45
43
  if (enableInfoPane) {
46
44
  const infoWindow = new window.google.maps.InfoWindow({
47
45
  content: ''
48
46
  });
49
47
 
50
- shapeInstance.addListener(CLICK, event => {
48
+ shapeInstance.addListener(CLICK, async event => {
51
49
  closeInfoWindows();
52
50
  const content = ReactDOMServer.renderToString(
53
- InfoWindowContent(entityData, imageData, displayItems, dataSummaries, url)
51
+ await infoWindowContent(imageData, dataSummaries, url, shapeData)
54
52
  );
55
53
  infoWindow.setContent(content);
56
54
  infoWindow.setPosition(event.latLng);
@@ -83,73 +81,46 @@ const areRectangleBoundsNumbers = bounds => bounds.every(bound => isNumber(bound
83
81
 
84
82
  const isPositionCorrect = (lat, lng) => isNumber(lat) && isNumber(lng);
85
83
 
86
- const getEntityUrl = (displayItems, entity, entityData) => {
87
- let url = '';
84
+ const getIconUrl = (imageId, imageData) => {
85
+ if (!imageId) return '';
86
+ const image = imageData.find(({ id }) => id === imageId);
87
+ if (!image || !image.url) return '';
88
88
 
89
- if (entity && displayItems) {
90
- const [entityId] = displayItems;
91
- const [entityRecord] = entityData.filter(({ id }) => id === entityId);
92
- if (entityRecord) {
93
- ({ url = '' } = entityRecord);
94
- }
95
- }
96
-
97
- return url;
89
+ return image.url;
98
90
  };
99
91
 
100
- const getImageUrl = (imageData, imageId) => {
101
- const [image] = imageData.getFiles.filter(({ id }) => id === imageId);
102
- if (image) return image.url;
103
-
104
- return '';
105
- };
106
-
107
- const getIconUrl = (shape, imageData) => {
108
- const { imageId } = shape;
109
-
110
- if (!imageData.getFiles) return '';
111
-
112
- return imageId ? getImageUrl(imageData, imageId) : '';
113
- };
114
-
115
- const InfoWindowContent = (entityData, imageData, displayItems, dataSummaries, url) => {
116
- const [entityId] = displayItems;
117
- const [entityRecordData] = entityData.filter(({ id }) => id === entityId);
118
-
119
- const summariesWithContent = dataSummaries.map(dataSummary => {
120
- const { elementTitle, type, propsToDisplay, ...otherProps } = dataSummary;
121
- const isTypeHeading = type === HEADING_LARGE;
122
- const summaryPropsWithContent = buildPropsToDisplayWithContent(
123
- entityRecordData,
124
- propsToDisplay
125
- );
126
- const modifier = getClassModifiers(LIST, otherProps);
127
- const SummaryComponent = summaryComponents[type];
128
- if (!summaryPropsWithContent.length) {
129
- return null;
130
- }
131
-
132
- const getDataSummaryComponent = () => {
133
- const component = (
134
- <SummaryComponent
135
- key={type}
136
- modifier={modifier}
137
- elementTitle={elementTitle}
138
- summaryPropsWithContent={summaryPropsWithContent}
139
- />
140
- );
141
-
142
- if (isTypeHeading && url) return <Link href={url}>{component}</Link>;
143
-
144
- return component;
145
- };
146
-
147
- return getDataSummaryComponent();
148
- });
149
-
150
- let image = {};
151
- const { imageId } = entityRecordData || {};
152
- if (imageId) [image] = imageData.getFiles.filter(({ id }) => id === imageId);
92
+ const infoWindowContent = async (imageData, dataSummaries, url, shapeData) => {
93
+ const summariesWithContent = await Promise.all(
94
+ dataSummaries.map(async dataSummary => {
95
+ const { elementTitle, type, propsToDisplay, ...otherProps } = dataSummary;
96
+ const isTypeHeading = type === HEADING_LARGE;
97
+ const summaryPropsWithContent = buildPropsToDisplayWithContent(shapeData, propsToDisplay);
98
+ const modifier = getClassModifiers(LIST, otherProps);
99
+ const SummaryComponent = summaryComponents[type];
100
+ await SummaryComponent.render.preload(); // preload dynamic nextjs component
101
+
102
+ if (!summaryPropsWithContent.length) return null;
103
+
104
+ const getDataSummaryComponent = () => {
105
+ const component = (
106
+ <SummaryComponent
107
+ key={type}
108
+ modifier={modifier}
109
+ elementTitle={elementTitle}
110
+ summaryPropsWithContent={summaryPropsWithContent}
111
+ />
112
+ );
113
+
114
+ if (isTypeHeading && url) return <Link href={url}>{component}</Link>;
115
+
116
+ return component;
117
+ };
118
+
119
+ return getDataSummaryComponent();
120
+ })
121
+ );
122
+ const { imageId } = shapeData || {};
123
+ const image = imageData.find(({ id }) => id === imageId);
153
124
  const shouldShowImage = image && image.url;
154
125
 
155
126
  const getImageElement = () => {
@@ -171,12 +142,11 @@ const InfoWindowContent = (entityData, imageData, displayItems, dataSummaries, u
171
142
  );
172
143
  };
173
144
 
174
- const setMarker = (map, router, shape, data, imageData) => {
175
- const { latitude, longitude, entity, label = '', markerWidth = 50, markerHeight = 50 } = shape;
176
- if (isPositionCorrect(latitude, longitude)) {
177
- const entityData = entity ? data[entity] || [] : [];
145
+ const setMarker = (map, router, shape, imageData) => {
146
+ const { label = '', markerWidth = 50, markerHeight = 50, latitude, longitude, imageId } = shape;
178
147
 
179
- const iconUrl = getIconUrl(shape, imageData);
148
+ if (isPositionCorrect(latitude, longitude)) {
149
+ const iconUrl = getIconUrl(imageId, imageData);
180
150
 
181
151
  const icon = iconUrl
182
152
  ? {
@@ -192,7 +162,7 @@ const setMarker = (map, router, shape, data, imageData) => {
192
162
  title: label || ''
193
163
  });
194
164
 
195
- addShapeListeners(map, router, shape, entityData, imageData, marker);
165
+ addShapeListeners(map, router, shape, imageData, marker);
196
166
 
197
167
  shapesArray.push(marker);
198
168
 
@@ -200,19 +170,18 @@ const setMarker = (map, router, shape, data, imageData) => {
200
170
  }
201
171
  };
202
172
 
203
- const setPolyline = (map, router, shape, data, imageData) => {
204
- const { paths, entity } = shape;
173
+ const setPolyline = (map, router, shape, imageData) => {
174
+ const { paths } = shape;
205
175
  const path = getPath(paths);
206
176
 
207
177
  if (path.length) {
208
- const entityData = entity ? data[entity] || [] : [];
209
178
  const polyline = new window.google.maps.Polyline({
210
179
  path,
211
180
  geodesic: true,
212
181
  ...setStyleOptions(shape)
213
182
  });
214
183
 
215
- addShapeListeners(map, router, shape, entityData, imageData, polyline);
184
+ addShapeListeners(map, router, shape, imageData, polyline);
216
185
 
217
186
  shapesArray.push(polyline);
218
187
 
@@ -220,18 +189,17 @@ const setPolyline = (map, router, shape, data, imageData) => {
220
189
  }
221
190
  };
222
191
 
223
- const setPolygon = (map, router, shape, data, imageData) => {
224
- const { paths: unParsedPaths, entity } = shape;
192
+ const setPolygon = (map, router, shape, imageData) => {
193
+ const { paths: unParsedPaths } = shape;
225
194
  const paths = getPath(unParsedPaths);
226
195
 
227
196
  if (paths.length) {
228
- const entityData = entity ? data[entity] || [] : [];
229
197
  const polygon = new window.google.maps.Polygon({
230
198
  paths,
231
199
  ...setStyleOptions(shape)
232
200
  });
233
201
 
234
- addShapeListeners(map, router, shape, entityData, imageData, polygon);
202
+ addShapeListeners(map, router, shape, imageData, polygon);
235
203
 
236
204
  shapesArray.push(polygon);
237
205
 
@@ -239,10 +207,9 @@ const setPolygon = (map, router, shape, data, imageData) => {
239
207
  }
240
208
  };
241
209
 
242
- const setRectangle = (map, router, shape, data, imageData) => {
243
- const { northBound, southBound, eastBound, westBound, entity } = shape;
210
+ const setRectangle = (map, router, shape, imageData) => {
211
+ const { northBound, southBound, eastBound, westBound } = shape;
244
212
  if (areRectangleBoundsNumbers([northBound, southBound, eastBound, westBound])) {
245
- const entityData = entity ? data[entity] || [] : [];
246
213
  const rectangle = new window.google.maps.Rectangle({
247
214
  ...setStyleOptions(shape),
248
215
  map,
@@ -254,7 +221,7 @@ const setRectangle = (map, router, shape, data, imageData) => {
254
221
  }
255
222
  });
256
223
 
257
- addShapeListeners(map, router, shape, entityData, imageData, rectangle);
224
+ addShapeListeners(map, router, shape, imageData, rectangle);
258
225
 
259
226
  shapesArray.push(rectangle);
260
227
 
@@ -262,10 +229,9 @@ const setRectangle = (map, router, shape, data, imageData) => {
262
229
  }
263
230
  };
264
231
 
265
- const setCircle = (map, router, shape, data, imageData) => {
266
- const { latitude, longitude, radius, entity } = shape;
232
+ const setCircle = (map, router, shape, imageData) => {
233
+ const { latitude, longitude, radius } = shape;
267
234
  if (isPositionCorrect(latitude, longitude) && isNumber(radius)) {
268
- const entityData = entity ? data[entity] || [] : [];
269
235
  const circle = new window.google.maps.Circle({
270
236
  ...setStyleOptions(shape),
271
237
  map,
@@ -273,7 +239,7 @@ const setCircle = (map, router, shape, data, imageData) => {
273
239
  radius
274
240
  });
275
241
 
276
- addShapeListeners(map, router, shape, entityData, imageData, circle);
242
+ addShapeListeners(map, router, shape, imageData, circle);
277
243
 
278
244
  shapesArray.push(circle);
279
245
 
@@ -281,42 +247,40 @@ const setCircle = (map, router, shape, data, imageData) => {
281
247
  }
282
248
  };
283
249
 
284
- const setShapes = (map, router, shapes, data, imageData) => {
250
+ const setShapes = (map, router, shapes, imageData) => {
285
251
  const mapZoom = map.getZoom();
286
252
  clearShapes();
287
253
 
288
- if (shapes.length) {
289
- shapes.forEach(shape => {
290
- const { type: shapeType, minZoom, maxZoom } = shape;
291
-
292
- if (mapZoom >= minZoom && mapZoom <= maxZoom) {
293
- switch (shapeType) {
294
- case MARKER: {
295
- setMarker(map, router, shape, data, imageData);
296
- break;
297
- }
298
- case POLYLINE: {
299
- setPolyline(map, router, shape, data, imageData);
300
- break;
301
- }
302
- case POLYGON: {
303
- setPolygon(map, router, shape, data, imageData);
304
- break;
305
- }
306
- case RECTANGLE: {
307
- setRectangle(map, router, shape, data, imageData);
308
- break;
309
- }
310
- case CIRCLE: {
311
- setCircle(map, router, shape, data, imageData);
312
- break;
313
- }
314
- default:
315
- break;
254
+ shapes.forEach(shape => {
255
+ const { type, minZoom, maxZoom } = shape;
256
+
257
+ if (mapZoom >= minZoom && mapZoom <= maxZoom) {
258
+ switch (type) {
259
+ case MARKER: {
260
+ setMarker(map, router, shape, imageData);
261
+ break;
316
262
  }
263
+ case POLYLINE: {
264
+ setPolyline(map, router, shape, imageData);
265
+ break;
266
+ }
267
+ case POLYGON: {
268
+ setPolygon(map, router, shape, imageData);
269
+ break;
270
+ }
271
+ case RECTANGLE: {
272
+ setRectangle(map, router, shape, imageData);
273
+ break;
274
+ }
275
+ case CIRCLE: {
276
+ setCircle(map, router, shape, imageData);
277
+ break;
278
+ }
279
+ default:
280
+ break;
317
281
  }
318
- });
319
- }
282
+ }
283
+ });
320
284
  };
321
285
 
322
286
  export default setShapes;
@@ -1,11 +1,12 @@
1
1
  import { useQuery } from '@apollo/client';
2
- import { generateQuery, generateQueryString } from '../queries';
2
+ import { generateWhereQuery, generateQueryString } from '../queries';
3
3
 
4
4
  const useGetImages = imageIds => {
5
5
  const queryName = 'getFiles';
6
- const action = generateQuery(generateQueryString(queryName, queryName, 'id url data'));
6
+ const action = generateWhereQuery(generateQueryString(queryName, queryName, 'id url data'));
7
7
  const { data = {}, loading, error } = useQuery(action, {
8
- variables: { where: { id: { _in: imageIds } } }
8
+ variables: { where: { id: { _in: imageIds } } },
9
+ skip: !imageIds || !imageIds.length
9
10
  });
10
11
  return { data, loading, error };
11
12
  };
@@ -12,16 +12,43 @@ const GET_ENTITY_SCHEMAS = gql`
12
12
  `;
13
13
 
14
14
  const generateQuery = queryString => gql`
15
- query getEntityData($where: JSON){
15
+ query getEntityData {
16
16
  ${queryString}
17
17
  }
18
18
  `;
19
19
 
20
+ const generateWhereQuery = queryString => gql`
21
+ query getEntityData($where: JSON){
22
+ ${queryString}
23
+ }
24
+ `;
20
25
  const generateQueryString = (action, query, props) => `
21
26
  ${query}: ${action}(where: $where){
22
27
  ${props}
23
- __typename
24
28
  }
25
29
  `;
26
30
 
27
- export { GET_ENTITY_SCHEMAS, generateQuery, generateQueryString };
31
+ const generateIdsQuery = (query, props, action, ids) => `
32
+ ${query}: ${action}(where: { id: { _in: ${JSON.stringify(ids)} } }){
33
+ ${props}
34
+ }
35
+ `;
36
+
37
+ const generateFiltersQuery = (query, props, rawQUery, filterQueryKey) => `
38
+ ${query}: searchPublishedContent(rawQueryStringified: ${JSON.stringify(rawQUery)}){
39
+ results {
40
+ ...on ${filterQueryKey} {
41
+ ${props}
42
+ }
43
+ }
44
+ }
45
+ `;
46
+
47
+ export {
48
+ GET_ENTITY_SCHEMAS,
49
+ generateQuery,
50
+ generateQueryString,
51
+ generateIdsQuery,
52
+ generateFiltersQuery,
53
+ generateWhereQuery
54
+ };