@devgateway/dvz-wp-commons 1.2.0 → 1.3.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 (51) hide show
  1. package/build/APIConfig.cjs +479 -0
  2. package/build/APIConfig.d.ts +12 -0
  3. package/build/APIConfig.js +367 -283
  4. package/build/APIutils.cjs +54 -0
  5. package/build/APIutils.js +7 -1
  6. package/build/Blocks.cjs +672 -0
  7. package/build/Blocks.d.ts +14 -1
  8. package/build/Blocks.js +523 -330
  9. package/build/CSVSourceConfig.cjs +99 -0
  10. package/build/CSVSourceConfig.js +63 -46
  11. package/build/ChartColors.cjs +593 -0
  12. package/build/ChartColors.d.ts +0 -1
  13. package/build/ChartColors.js +430 -366
  14. package/build/ChartLegends.cjs +157 -0
  15. package/build/ChartLegends.d.ts +0 -1
  16. package/build/ChartLegends.js +173 -54
  17. package/build/ChartMeasures.cjs +192 -0
  18. package/build/ChartMeasures.d.ts +0 -1
  19. package/build/ChartMeasures.js +197 -109
  20. package/build/Constants.cjs +21 -0
  21. package/build/Constants.js +3 -1
  22. package/build/DataFilters.cjs +176 -0
  23. package/build/DataFilters.js +100 -89
  24. package/build/Format.cjs +1038 -0
  25. package/build/Format.js +428 -378
  26. package/build/MapCSVSourceConfig.cjs +36 -0
  27. package/build/MapCSVSourceConfig.js +19 -8
  28. package/build/Measures.cjs +196 -0
  29. package/build/Measures.js +204 -108
  30. package/build/MobileConfigUtils.cjs +92 -0
  31. package/build/MobileConfigUtils.js +19 -8
  32. package/build/Tooltip.cjs +63 -0
  33. package/build/Tooltip.d.ts +1 -3
  34. package/build/Tooltip.js +27 -51
  35. package/build/Util.cjs +29 -0
  36. package/build/Util.js +7 -7
  37. package/build/hooks/index.cjs +1 -0
  38. package/build/hooks/index.js +0 -3
  39. package/build/icons/Chart.cjs +49 -0
  40. package/build/icons/Chart.d.ts +1 -2
  41. package/build/icons/Chart.js +10 -11
  42. package/build/icons/Generic.cjs +24 -0
  43. package/build/icons/Generic.d.ts +1 -2
  44. package/build/icons/Generic.js +25 -4
  45. package/build/icons/index.cjs +19 -0
  46. package/build/icons/index.js +2 -2
  47. package/build/index.cjs +225 -0
  48. package/build/index.d.ts +1 -1
  49. package/build/index.js +47 -16
  50. package/package.json +16 -7
  51. package/build/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,672 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = exports.SizeConfig = exports.ComponentWithSettings = exports.BlockEditWithFilters = exports.BlockEditWithAPIMetadata = void 0;
7
+ var _i18n = require("@wordpress/i18n");
8
+ var _components = require("@wordpress/components");
9
+ var _element = require("@wordpress/element");
10
+ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
11
+ var _Util = require("./Util.cjs");
12
+ var _APIutils = require("./APIutils.cjs");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const SizeConfig = ({
15
+ height,
16
+ setAttributes,
17
+ panelStatus,
18
+ initialOpen
19
+ }) => {
20
+ return /* @__PURE__ */React.createElement(_components.PanelBody, {
21
+ initialOpen: panelStatus ? panelStatus["SIZE"] : initialOpen,
22
+ onToggle: e => (0, _Util.togglePanel)("SIZE", panelStatus, setAttributes),
23
+ title: (0, _i18n.__)("Size")
24
+ }, /* @__PURE__ */React.createElement(_components.PanelRow, null, /* @__PURE__ */React.createElement(_components.TextControl, {
25
+ size: 10,
26
+ label: "Height",
27
+ value: height,
28
+ onChange: height2 => setAttributes({
29
+ height: height2 ? parseInt(height2) : 0
30
+ })
31
+ })));
32
+ };
33
+ exports.SizeConfig = SizeConfig;
34
+ class ComponentWithSettings extends _element.Component {
35
+ constructor(props) {
36
+ super(props);
37
+ this.state = {
38
+ react_ui_url: ""
39
+ };
40
+ window.addEventListener("message", event => {
41
+ if (event.data.type === "componentReady" && event.data.value === true) {
42
+ if (this.iframe.current) {
43
+ console.log("-----------Sending message -----------");
44
+ this.iframe.current.contentWindow.postMessage({
45
+ messageType: "component-attributes",
46
+ ...this.props.attributes
47
+ }, "*");
48
+ }
49
+ }
50
+ }, false);
51
+ this.iframe = React.createRef();
52
+ this.unsubscribe = wp.data.subscribe(() => {
53
+ const newPreviewMode = wp.data.select("core/editor").getDeviceType();
54
+ if (newPreviewMode !== this.state.previewMode) {
55
+ this.setState({
56
+ previewMode: newPreviewMode
57
+ });
58
+ }
59
+ });
60
+ }
61
+ componentDidUpdate(prevProps, prevState, snapshot) {
62
+ if (this.iframe.current?.contentWindow) {
63
+ this.iframe.current.contentWindow.postMessage({
64
+ messageType: "component-attributes",
65
+ ...this.props.attributes
66
+ }, "*");
67
+ }
68
+ }
69
+ componentDidMount() {
70
+ (0, _apiFetch.default)({
71
+ path: "/dg/v1/settings"
72
+ }).then(data => {
73
+ this.setState({
74
+ react_ui_url: data["react_ui_url"] + "/" + window._page_locale,
75
+ react_api_url: data["react_api_url"],
76
+ apache_superset_url: data["apache_superset_url"],
77
+ site_language: data["site_language"],
78
+ current_language: new URLSearchParams(document.location.search).get("edit_lang")
79
+ });
80
+ });
81
+ }
82
+ componentWillUnmount() {
83
+ if (this.unsubscribe) {
84
+ this.unsubscribe();
85
+ }
86
+ }
87
+ }
88
+ exports.ComponentWithSettings = ComponentWithSettings;
89
+ class BlockEditWithFilters extends ComponentWithSettings {
90
+ constructor(props) {
91
+ super(props);
92
+ this.state = {
93
+ taxonomyValues: [],
94
+ sortingTaxonomyValues: [],
95
+ types: null,
96
+ taxonomies: null,
97
+ loading: false,
98
+ defaultValues: [],
99
+ defaultValuesSearchTerm: ""
100
+ };
101
+ this.onTypeChanged = this.onTypeChanged.bind(this);
102
+ this.onTaxonomyChanged = this.onTaxonomyChanged.bind(this);
103
+ this.onSortingTaxonomyChanged = this.onSortingTaxonomyChanged.bind(this);
104
+ this.getTaxonomyValues = this.getTaxonomyValues.bind(this);
105
+ this.onCategoryChanged = this.onCategoryChanged.bind(this);
106
+ this.getSortingTaxonomyValues = this.getSortingTaxonomyValues.bind(this);
107
+ this.onDefaultCategoryChanged = this.onDefaultCategoryChanged.bind(this);
108
+ }
109
+ componentDidUpdate(prevProps, prevState, snapshot) {
110
+ const {
111
+ setAttributes,
112
+ attributes: {
113
+ type,
114
+ taxonomy,
115
+ count,
116
+ sortingTaxonomy
117
+ }
118
+ } = this.props;
119
+ super.componentDidUpdate(prevProps, prevState, snapshot);
120
+ if (prevProps.attributes) {
121
+ if (type !== prevProps.attributes.type) {}
122
+ if (taxonomy !== prevProps.attributes.taxonomy) {
123
+ this.getTaxonomyValues();
124
+ }
125
+ if (sortingTaxonomy !== prevProps.attributes.sortingTaxonomy) {
126
+ this.getSortingTaxonomyValues();
127
+ }
128
+ }
129
+ }
130
+ componentDidMount() {
131
+ super.componentDidMount();
132
+ this.getTypes();
133
+ this.getTaxonomies();
134
+ const {
135
+ setAttributes,
136
+ attributes: {
137
+ type,
138
+ taxonomy,
139
+ count,
140
+ sortingTaxonomy
141
+ }
142
+ } = this.props;
143
+ if (taxonomy !== "none" || taxonomy !== null) {
144
+ this.getTaxonomyValues();
145
+ }
146
+ if (sortingTaxonomy !== "none" || sortingTaxonomy !== null) {
147
+ this.getSortingTaxonomyValues();
148
+ }
149
+ }
150
+ onTypeChanged(value) {
151
+ const {
152
+ setAttributes
153
+ } = this.props;
154
+ setAttributes({
155
+ categories: []
156
+ });
157
+ setAttributes({
158
+ taxonomy: "none"
159
+ });
160
+ setAttributes({
161
+ type: value
162
+ });
163
+ }
164
+ onTaxonomyChanged(value) {
165
+ const {
166
+ setAttributes
167
+ } = this.props;
168
+ setAttributes({
169
+ categories: []
170
+ });
171
+ setAttributes({
172
+ taxonomy: value
173
+ });
174
+ }
175
+ onSortingTaxonomyChanged(value) {
176
+ const {
177
+ setAttributes
178
+ } = this.props;
179
+ setAttributes({
180
+ sortFirstBy: "none"
181
+ });
182
+ setAttributes({
183
+ sortingTaxonomy: value
184
+ });
185
+ }
186
+ onDefaultValuesChanged(value, filterType = "multi-select") {
187
+ const {
188
+ setAttributes
189
+ } = this.props;
190
+ if (filterType === "multi-select") {
191
+ setAttributes({
192
+ defaultValues: value
193
+ });
194
+ } else {
195
+ setAttributes({
196
+ defaultValues: [value]
197
+ });
198
+ }
199
+ }
200
+ onCategoryChanged(checked, value) {
201
+ const {
202
+ setAttributes,
203
+ attributes: {
204
+ categories
205
+ }
206
+ } = this.props;
207
+ if (!checked) {
208
+ setAttributes({
209
+ categories: categories.filter(i => i != value)
210
+ });
211
+ } else {
212
+ let newCate = [...categories];
213
+ newCate.push(value);
214
+ setAttributes({
215
+ categories: newCate
216
+ });
217
+ }
218
+ }
219
+ onDefaultCategoryChanged(value, filterType = "multi-select", checked) {
220
+ const {
221
+ setAttributes,
222
+ attributes: {
223
+ defaultValues
224
+ }
225
+ } = this.props;
226
+ if (filterType === "multi-select") {
227
+ if (!checked) {
228
+ setAttributes({
229
+ defaultValues: defaultValues.filter(i => i !== value)
230
+ });
231
+ } else {
232
+ setAttributes({
233
+ defaultValues: [...defaultValues, value]
234
+ });
235
+ }
236
+ } else {
237
+ setAttributes({
238
+ defaultValues: [value]
239
+ });
240
+ }
241
+ }
242
+ getTaxonomyValues() {
243
+ const {
244
+ setAttributes,
245
+ attributes: {
246
+ taxonomy
247
+ }
248
+ } = this.props;
249
+ this.setState({
250
+ loading: true
251
+ });
252
+ wp.apiFetch({
253
+ path: "/wp/v2/" + taxonomy + "?per_page=100"
254
+ }).then(data => {
255
+ this.setState({
256
+ loading: false
257
+ });
258
+ this.setState({
259
+ taxonomyValues: data
260
+ });
261
+ });
262
+ }
263
+ getSortingTaxonomyValues() {
264
+ const {
265
+ setAttributes,
266
+ attributes: {
267
+ sortingTaxonomy
268
+ }
269
+ } = this.props;
270
+ wp.apiFetch({
271
+ path: "/wp/v2/" + sortingTaxonomy + "?per_page=100"
272
+ }).then(data => {
273
+ this.setState({
274
+ sortingTaxonomyValues: data
275
+ });
276
+ });
277
+ }
278
+ getTaxonomies() {
279
+ wp.apiFetch({
280
+ path: "/wp/v2/taxonomies?per_page=100"
281
+ }).then(data => {
282
+ this.setState({
283
+ taxonomies: data
284
+ });
285
+ });
286
+ }
287
+ getTypes() {
288
+ wp.apiFetch({
289
+ path: "/wp/v2/types?per_page=100"
290
+ }).then(data => {
291
+ const types = data;
292
+ this.setState({
293
+ types: data,
294
+ loading: false
295
+ });
296
+ });
297
+ }
298
+ typeOptions() {
299
+ const {
300
+ setAttributes,
301
+ attributes: {
302
+ count,
303
+ type,
304
+ taxonomy,
305
+ category
306
+ }
307
+ } = this.props;
308
+ const {
309
+ types,
310
+ taxonomies,
311
+ taxonomyValues
312
+ } = this.state;
313
+ const typeOptions = types ? Object.keys(types).filter(k => ["page", "attachment", "wp_block"].indexOf(k) === -1).map(k => ({
314
+ slug: types[k].slug,
315
+ label: types[k].name,
316
+ value: types[k].rest_base
317
+ })) : [];
318
+ return typeOptions;
319
+ }
320
+ taxonomyOptions() {
321
+ const {
322
+ attributes: {
323
+ type
324
+ }
325
+ } = this.props;
326
+ const {
327
+ types,
328
+ taxonomies,
329
+ taxonomyValues
330
+ } = this.state;
331
+ let slug;
332
+ if (types) {
333
+ slug = this.typeOptions().filter(t => t.value == type)[0]?.slug;
334
+ const taxonomyOptions = types && taxonomies ? Object.keys(taxonomies).filter(i => taxonomies[i].types.indexOf(slug) > -1).map(k => ({
335
+ label: types[slug].name + " -> " + taxonomies[k].name,
336
+ value: taxonomies[k].rest_base
337
+ })) : [];
338
+ return [{
339
+ label: "None",
340
+ value: "none"
341
+ }, ...taxonomyOptions];
342
+ } else {
343
+ return [];
344
+ }
345
+ }
346
+ categoriesOptions() {
347
+ const {
348
+ types,
349
+ taxonomies,
350
+ taxonomyValues
351
+ } = this.state;
352
+ const taxonomyValuesOptions = taxonomyValues && taxonomyValues.map(t => ({
353
+ label: t.name,
354
+ value: t.id
355
+ }));
356
+ return taxonomyValuesOptions;
357
+ }
358
+ sortingCategoriesOptions() {
359
+ const {
360
+ sortingTaxonomyValues
361
+ } = this.state;
362
+ const taxonomyValuesOptions = sortingTaxonomyValues && sortingTaxonomyValues.map(t => ({
363
+ label: t.name,
364
+ value: t.id
365
+ }));
366
+ return taxonomyValuesOptions;
367
+ }
368
+ renderFilters(title) {
369
+ const {
370
+ setAttributes,
371
+ attributes: {
372
+ type,
373
+ taxonomy,
374
+ categories,
375
+ isCountryFilter
376
+ }
377
+ } = this.props;
378
+ return /* @__PURE__ */React.createElement(_components.PanelBody, {
379
+ title: (0, _i18n.__)(title || "Filter")
380
+ }, /* @__PURE__ */React.createElement(_components.PanelRow, null, /* @__PURE__ */React.createElement(_components.SelectControl, {
381
+ label: (0, _i18n.__)("Post Type"),
382
+ options: this.typeOptions(),
383
+ value: type,
384
+ onChange: this.onTypeChanged
385
+ })), /* @__PURE__ */React.createElement(_components.PanelRow, null, /* @__PURE__ */React.createElement(_components.SelectControl, {
386
+ label: isCountryFilter ? (0, _i18n.__)("Select Taxonomy with Countries") : (0, _i18n.__)("Use a taxonomy filter "),
387
+ options: this.taxonomyOptions(),
388
+ value: taxonomy,
389
+ help: isCountryFilter ? (0, _i18n.__)("Select a taxonomy that contains countries") : null,
390
+ onChange: this.onTaxonomyChanged
391
+ })), this.state.loading && taxonomy && taxonomy !== "none" ? /* @__PURE__ */React.createElement(_components.PanelRow, null, /* @__PURE__ */React.createElement(_components.Spinner, null)) : taxonomy && taxonomy !== "none" && this.categoriesOptions().map(o => {
392
+ return /* @__PURE__ */React.createElement(_components.PanelRow, null, /* @__PURE__ */React.createElement(_components.CheckboxControl, {
393
+ label: o.label,
394
+ onChange: checked => this.onCategoryChanged(checked, o.value),
395
+ checked: categories.indexOf(o.value) > -1
396
+ }));
397
+ }));
398
+ }
399
+ renderSorting(showTaxonomy = true) {
400
+ const {
401
+ setAttributes,
402
+ attributes: {
403
+ sortingTaxonomy,
404
+ sortFirstBy
405
+ }
406
+ } = this.props;
407
+ return /* @__PURE__ */React.createElement(_components.PanelBody, {
408
+ title: (0, _i18n.__)("Sorting Configuration")
409
+ }, showTaxonomy && /* @__PURE__ */React.createElement(_components.PanelRow, null, /* @__PURE__ */React.createElement(_components.SelectControl, {
410
+ label: (0, _i18n.__)("Select Taxonomy with the sorting"),
411
+ options: this.taxonomyOptions(),
412
+ value: sortingTaxonomy,
413
+ help: (0, _i18n.__)("Select a taxonomy that contains the sorting"),
414
+ onChange: this.onSortingTaxonomyChanged
415
+ })), /* @__PURE__ */React.createElement(_components.PanelRow, null, (sortingTaxonomy !== "none" || sortingTaxonomy !== null) && /* @__PURE__ */React.createElement(_components.SelectControl, {
416
+ label: (0, _i18n.__)("Sort First By"),
417
+ options: [{
418
+ label: "None",
419
+ value: "none"
420
+ }, ...this.sortingCategoriesOptions()],
421
+ value: sortFirstBy,
422
+ onChange: value => {
423
+ setAttributes({
424
+ sortFirstBy: value
425
+ });
426
+ }
427
+ })));
428
+ }
429
+ renderSelectDefaultValues(filterType = "multi-select") {
430
+ const {
431
+ setAttributes,
432
+ attributes: {
433
+ defaultValues,
434
+ taxonomy
435
+ }
436
+ } = this.props;
437
+ return /* @__PURE__ */React.createElement(React.Fragment, null, filterType === "multi-select" ? /* @__PURE__ */React.createElement(_components.PanelBody, {
438
+ title: (0, _i18n.__)("Default Values")
439
+ }, /* @__PURE__ */React.createElement(_components.__experimentalText, {
440
+ style: {
441
+ marginBottom: 20
442
+ }
443
+ }, (0, _i18n.__)("Select the default values for the filter")), /* @__PURE__ */React.createElement(_components.SearchControl, {
444
+ __nextHasNoMarginBottom: true,
445
+ style: {
446
+ marginTop: 20
447
+ },
448
+ label: (0, _i18n.__)("Search categories"),
449
+ value: this.state.defaultValuesSearchTerm,
450
+ onChange: searchTerm => this.setState({
451
+ defaultValuesSearchTerm: searchTerm
452
+ }),
453
+ placeholder: (0, _i18n.__)("Search...")
454
+ }), /* @__PURE__ */React.createElement(_components.__experimentalScrollable, {
455
+ style: {
456
+ maxHeight: 200,
457
+ width: "100%",
458
+ marginTop: 10
459
+ }
460
+ }, taxonomy && taxonomy !== "none" && this.categoriesOptions().filter(o => o.label.toLowerCase().includes(this.state.defaultValuesSearchTerm.toLowerCase())).map(o => {
461
+ return /* @__PURE__ */React.createElement(_components.PanelRow, {
462
+ key: o.value
463
+ }, /* @__PURE__ */React.createElement(_components.CheckboxControl, {
464
+ label: o.label,
465
+ onChange: checked => this.onDefaultCategoryChanged(o.value, filterType, checked),
466
+ checked: defaultValues.indexOf(o.value) > -1
467
+ }));
468
+ }))) : /* @__PURE__ */React.createElement(_components.PanelBody, {
469
+ title: (0, _i18n.__)("Default Value")
470
+ }, /* @__PURE__ */React.createElement(_components.__experimentalText, {
471
+ style: {
472
+ marginBottom: 20
473
+ }
474
+ }, (0, _i18n.__)("Select the default value for the filter")), /* @__PURE__ */React.createElement(_components.SelectControl, {
475
+ options: [{
476
+ label: "None",
477
+ value: "none"
478
+ }, ...this.categoriesOptions()],
479
+ value: defaultValues[0],
480
+ onChange: value => {
481
+ this.onDefaultCategoryChanged(value, filterType);
482
+ }
483
+ })));
484
+ }
485
+ }
486
+ exports.BlockEditWithFilters = BlockEditWithFilters;
487
+ class BlockEditWithAPIMetadata extends ComponentWithSettings {
488
+ constructor(props) {
489
+ super(props);
490
+ }
491
+ componentDidMount() {
492
+ (0, _apiFetch.default)({
493
+ path: "/dg/v1/settings"
494
+ }).then(settingsData => {
495
+ fetch(`/api/registry/eureka/apps`, {
496
+ headers: {
497
+ "Accept": "application/json"
498
+ }
499
+ }).then(response => response.json()).then(data => {
500
+ const apps = data.applications ? [...data.applications.application.filter(a => a.instance[0].metadata.type === "data").map(a => ({
501
+ label: a.name,
502
+ value: a.instance[0].vipAddress,
503
+ settings: a.instance[0]
504
+ })), {
505
+ label: "CSV",
506
+ value: "csv"
507
+ }] : [{
508
+ label: "CSV",
509
+ value: "csv"
510
+ }];
511
+ this.setState({
512
+ react_ui_url: settingsData["react_ui_url"] + "/" + window._page_locale,
513
+ react_api_url: settingsData["react_api_url"],
514
+ apache_superset_url: settingsData["apache_superset_url"],
515
+ site_language: settingsData["site_language"],
516
+ current_language: new URLSearchParams(document.location.search).get("edit_lang"),
517
+ apps
518
+ }, () => {
519
+ const {
520
+ app,
521
+ dvzProxyDatasetId
522
+ } = this.props.attributes;
523
+ if ((0, _APIutils.isSupersetAPI)(app, this.state.apps)) {
524
+ this.loadDatasets(app);
525
+ }
526
+ if (app && app != "none") {
527
+ this.loadMetadata(app, dvzProxyDatasetId);
528
+ }
529
+ });
530
+ }).catch(() => {
531
+ console.log("Error when loading apps");
532
+ });
533
+ });
534
+ }
535
+ componentDidUpdate(prevProps) {
536
+ super.componentDidUpdate(prevProps);
537
+ const {
538
+ attributes: {
539
+ app,
540
+ dvzProxyDatasetId
541
+ }
542
+ } = this.props;
543
+ const {
544
+ attributes: {
545
+ dvzProxyDatasetId: prevDvzProxyDatasetId,
546
+ app: prevAPP
547
+ }
548
+ } = prevProps;
549
+ if (app != prevAPP) {
550
+ if ((0, _APIutils.isSupersetAPI)(app, this.state.apps)) {
551
+ this.loadDatasets(app);
552
+ if (dvzProxyDatasetId) {
553
+ this.loadMetadata(app, dvzProxyDatasetId);
554
+ }
555
+ } else {
556
+ this.loadMetadata(app);
557
+ }
558
+ } else {
559
+ if (dvzProxyDatasetId != prevDvzProxyDatasetId) {
560
+ this.loadMetadata(app, dvzProxyDatasetId);
561
+ }
562
+ }
563
+ }
564
+ evictSuperSetCache() {
565
+ const {
566
+ app,
567
+ dvzProxyDatasetId
568
+ } = this.props.attributes;
569
+ fetch(`/api/${app}/cacheEvict?dvzProxyDatasetId=${dvzProxyDatasetId}`).then(() => {
570
+ this.loadMetadata(app, dvzProxyDatasetId);
571
+ });
572
+ }
573
+ loadDatasets(app) {
574
+ fetch(`/api/${app}/datasets`).then(response => {
575
+ if (!response.ok) {
576
+ throw new Error("HTTP status " + response.status);
577
+ }
578
+ return response.json();
579
+ }).then(data => {
580
+ this.setState({
581
+ datasets: data
582
+ });
583
+ }).catch(() => {
584
+ console.log("Error when loading datasets");
585
+ });
586
+ }
587
+ loadMetadata(app, dvzProxyDatasetId) {
588
+ if (app == "csv") {
589
+ return;
590
+ }
591
+ const dimensionsUrl = `/api/${app}/dimensions${dvzProxyDatasetId ? `?dvzProxyDatasetId=${dvzProxyDatasetId}` : ""}`;
592
+ const measuresUrl = `/api/${app}/measures${dvzProxyDatasetId ? `?dvzProxyDatasetId=${dvzProxyDatasetId}` : ""}`;
593
+ const filtersUrl = `/api/${app}/filters${dvzProxyDatasetId ? `?dvzProxyDatasetId=${dvzProxyDatasetId}` : ""}`;
594
+ const categoriesUrl = `/api/${app}/categories${dvzProxyDatasetId ? `?dvzProxyDatasetId=${dvzProxyDatasetId}` : ""}`;
595
+ if (app != "csv") {
596
+ fetch(dimensionsUrl).then(response => {
597
+ if (!response.ok) {
598
+ throw new Error("HTTP status " + response.status);
599
+ } else {
600
+ return response.json();
601
+ }
602
+ }).then(data => {
603
+ this.setState({
604
+ dimensions: [{
605
+ "label": (0, _i18n.__)("None"),
606
+ "value": "none"
607
+ }, ...(0, _APIutils.getTranslatedOptions)(data)]
608
+ });
609
+ }).catch(function (response) {
610
+ console.log("Error when loading dimensions");
611
+ });
612
+ fetch(filtersUrl).then(response => {
613
+ if (!response.ok) {
614
+ throw new Error("HTTP status " + response.status);
615
+ }
616
+ return response.json();
617
+ }).then(data => {
618
+ const options = data.map(f => ({
619
+ ...f,
620
+ value: f.param
621
+ }));
622
+ this.setState({
623
+ filters: options
624
+ });
625
+ }).catch(function (response) {
626
+ console.log("Error when loading filters", response);
627
+ });
628
+ fetch(measuresUrl).then(response => {
629
+ if (!response.ok) {
630
+ throw new Error("HTTP status " + response.status);
631
+ }
632
+ return response.json();
633
+ }).then(data => {
634
+ sessionStorage.setItem(`measures_${app}`, JSON.stringify((0, _APIutils.getTranslatedOptions)(data)));
635
+ this.setState({
636
+ measures: (0, _APIutils.getTranslatedOptions)(data)
637
+ });
638
+ }).catch(function (response) {
639
+ console.log("Error when loading measures");
640
+ });
641
+ fetch(categoriesUrl).then(response => {
642
+ if (!response.ok) {
643
+ throw new Error("HTTP status " + response.status);
644
+ }
645
+ return response.json();
646
+ }).then(data => {
647
+ sessionStorage.setItem(`categories_${app}`, JSON.stringify(data));
648
+ this.setState({
649
+ categories: (0, _APIutils.getTranslatedOptions)(data)
650
+ });
651
+ }).catch(function (response) {
652
+ console.log("Error when getting categories", response);
653
+ });
654
+ }
655
+ }
656
+ fetchData(url, stateKey, transformData) {
657
+ fetch(url).then(response => {
658
+ if (!response.ok) {
659
+ throw new Error("HTTP status " + response.status);
660
+ }
661
+ return response.json();
662
+ }).then(data => {
663
+ this.setState({
664
+ [stateKey]: transformData(data)
665
+ });
666
+ }).catch(() => {
667
+ console.log(`Error when loading ${stateKey}`);
668
+ });
669
+ }
670
+ }
671
+ exports.BlockEditWithAPIMetadata = BlockEditWithAPIMetadata;
672
+ module.exports = SizeConfig;
package/build/Blocks.d.ts CHANGED
@@ -18,14 +18,21 @@ export class ComponentWithSettings extends Component<any, any, any> {
18
18
  export class BlockEditWithFilters extends ComponentWithSettings {
19
19
  state: {
20
20
  taxonomyValues: never[];
21
+ sortingTaxonomyValues: never[];
21
22
  types: null;
22
23
  taxonomies: null;
23
24
  loading: boolean;
25
+ defaultValues: never[];
26
+ defaultValuesSearchTerm: string;
24
27
  };
25
28
  onTypeChanged(value: any): void;
26
29
  onTaxonomyChanged(value: any): void;
30
+ onSortingTaxonomyChanged(value: any): void;
27
31
  getTaxonomyValues(): void;
28
32
  onCategoryChanged(checked: any, value: any): void;
33
+ getSortingTaxonomyValues(): void;
34
+ onDefaultCategoryChanged(value: any, filterType: string | undefined, checked: any): void;
35
+ onDefaultValuesChanged(value: any, filterType?: string): void;
29
36
  getTaxonomies(): void;
30
37
  getTypes(): void;
31
38
  typeOptions(): {
@@ -41,7 +48,13 @@ export class BlockEditWithFilters extends ComponentWithSettings {
41
48
  label: any;
42
49
  value: any;
43
50
  }[];
44
- renderFilters(): import("react").JSX.Element;
51
+ sortingCategoriesOptions(): {
52
+ label: any;
53
+ value: any;
54
+ }[];
55
+ renderFilters(title: any): import("react").JSX.Element;
56
+ renderSorting(showTaxonomy?: boolean): import("react").JSX.Element;
57
+ renderSelectDefaultValues(filterType?: string): import("react").JSX.Element;
45
58
  }
46
59
  export class BlockEditWithAPIMetadata extends ComponentWithSettings {
47
60
  componentDidUpdate(prevProps: any): void;