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