@devgateway/dvz-wp-commons 1.1.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.
- package/build/APIConfig.cjs +479 -0
- package/build/APIConfig.d.ts +31 -42
- package/build/APIConfig.js +366 -277
- package/build/APIutils.cjs +54 -0
- package/build/APIutils.d.ts +3 -3
- package/build/APIutils.js +11 -1
- package/build/Blocks.cjs +672 -0
- package/build/Blocks.d.ts +42 -65
- package/build/Blocks.js +524 -346
- package/build/CSVSourceConfig.cjs +99 -0
- package/build/CSVSourceConfig.d.ts +2 -3
- package/build/CSVSourceConfig.js +63 -41
- package/build/ChartColors.cjs +593 -0
- package/build/ChartColors.d.ts +4 -46
- package/build/ChartColors.js +431 -380
- package/build/ChartLegends.cjs +157 -0
- package/build/ChartLegends.d.ts +1 -33
- package/build/ChartLegends.js +173 -69
- package/build/ChartMeasures.cjs +192 -0
- package/build/ChartMeasures.d.ts +1 -23
- package/build/ChartMeasures.js +195 -108
- package/build/Constants.cjs +21 -0
- package/build/Constants.d.ts +18 -15
- package/build/Constants.js +3 -1
- package/build/DataFilters.cjs +176 -0
- package/build/DataFilters.d.ts +1 -12
- package/build/DataFilters.js +100 -93
- package/build/Format.cjs +1038 -0
- package/build/Format.d.ts +8 -10
- package/build/Format.js +428 -379
- package/build/MapCSVSourceConfig.cjs +36 -0
- package/build/MapCSVSourceConfig.d.ts +7 -9
- package/build/MapCSVSourceConfig.js +19 -9
- package/build/Measures.cjs +196 -0
- package/build/Measures.d.ts +1 -24
- package/build/Measures.js +208 -119
- package/build/MobileConfigUtils.cjs +92 -0
- package/build/MobileConfigUtils.d.ts +6 -6
- package/build/MobileConfigUtils.js +39 -32
- package/build/Tooltip.cjs +63 -0
- package/build/Tooltip.d.ts +1 -3
- package/build/Tooltip.js +27 -51
- package/build/Util.cjs +29 -0
- package/build/Util.d.ts +5 -6
- package/build/Util.js +9 -9
- package/build/hooks/index.cjs +1 -0
- package/build/hooks/index.js +0 -3
- package/build/icons/Chart.cjs +49 -0
- package/build/icons/Chart.d.ts +1 -2
- package/build/icons/Chart.js +10 -11
- package/build/icons/Generic.cjs +24 -0
- package/build/icons/Generic.d.ts +1 -2
- package/build/icons/Generic.js +25 -4
- package/build/icons/index.cjs +19 -0
- package/build/icons/index.d.ts +2 -2
- package/build/icons/index.js +2 -2
- package/build/index.cjs +225 -0
- package/build/index.d.ts +16 -18
- package/build/index.js +47 -19
- package/package.json +39 -30
- package/build/post-type.d.ts +0 -193
- package/build/post-type.js +0 -12
- package/build/tsconfig.tsbuildinfo +0 -1
- package/build/types.d.ts +0 -349
- package/build/types.js +0 -33
package/build/Blocks.js
CHANGED
|
@@ -1,374 +1,552 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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";
|
|
18
|
+
export const SizeConfig = ({ height, setAttributes, panelStatus, initialOpen }) => {
|
|
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
|
+
);
|
|
13
36
|
};
|
|
14
37
|
export class ComponentWithSettings extends Component {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
window.addEventListener("message", (event) => {
|
|
27
|
-
if (event.data.type === 'componentReady' && event.data.value === true) {
|
|
28
|
-
if (this.iframe.current) {
|
|
29
|
-
console.log("-----------Sending message -----------");
|
|
30
|
-
this.iframe.current.contentWindow?.postMessage(({ messageType: 'component-attributes', ...this.props.attributes }), "*");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}, false);
|
|
34
|
-
this.iframe = React.createRef();
|
|
35
|
-
this.unsubscribe = subscribe(() => {
|
|
36
|
-
const newPreviewMode = select("core/editor").getDeviceType();
|
|
37
|
-
if (newPreviewMode !== this.state.previewMode) {
|
|
38
|
-
this.setState({ previewMode: newPreviewMode });
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
43
|
-
if (this.iframe.current?.contentWindow) {
|
|
44
|
-
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 }, "*");
|
|
45
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 }, "*");
|
|
46
62
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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();
|
|
62
78
|
}
|
|
79
|
+
}
|
|
63
80
|
}
|
|
64
81
|
export class BlockEditWithFilters extends ComponentWithSettings {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
}
|
|
82
121
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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();
|
|
93
138
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.getTypes();
|
|
97
|
-
this.getTaxonomies();
|
|
98
|
-
const { attributes: { taxonomy }, } = this.props;
|
|
99
|
-
if (taxonomy != 'none') {
|
|
100
|
-
this.getTaxonomyValues();
|
|
101
|
-
}
|
|
139
|
+
if (sortingTaxonomy !== "none" || sortingTaxonomy !== null) {
|
|
140
|
+
this.getSortingTaxonomyValues();
|
|
102
141
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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] });
|
|
108
165
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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 });
|
|
113
175
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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] });
|
|
124
187
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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 [];
|
|
159
272
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
171
318
|
}
|
|
172
|
-
|
|
173
|
-
|
|
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 });
|
|
174
347
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
+
}
|
|
193
383
|
}
|
|
194
384
|
export class BlockEditWithAPIMetadata extends ComponentWithSettings {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
},
|
|
206
|
-
})
|
|
207
|
-
.then((response) => response.json())
|
|
208
|
-
.then(data => {
|
|
209
|
-
const apps = data.applications ? [...data.applications.application
|
|
210
|
-
.filter(a => a.instance[0].metadata.type === 'data')
|
|
211
|
-
.map(a => ({
|
|
212
|
-
label: a.name, value: a.instance[0].vipAddress, settings: a.instance[0]
|
|
213
|
-
})), {
|
|
214
|
-
label: 'CSV', value: 'csv'
|
|
215
|
-
}] : [{
|
|
216
|
-
label: 'CSV', value: 'csv'
|
|
217
|
-
}];
|
|
218
|
-
this.setState({
|
|
219
|
-
react_ui_url: settingsData["react_ui_url"] + '/' + window._page_locale,
|
|
220
|
-
react_api_url: settingsData["react_api_url"],
|
|
221
|
-
apache_superset_url: settingsData["apache_superset_url"],
|
|
222
|
-
site_language: settingsData["site_language"],
|
|
223
|
-
current_language: new URLSearchParams(document.location.search).get("edit_lang") || "",
|
|
224
|
-
apps
|
|
225
|
-
}, () => {
|
|
226
|
-
const { app, dvzProxyDatasetId } = this.props.attributes;
|
|
227
|
-
if (isSupersetAPI(app, this.state.apps)) {
|
|
228
|
-
this.loadDatasets(app);
|
|
229
|
-
}
|
|
230
|
-
if (app && app != 'none') {
|
|
231
|
-
this.loadMetadata(app, dvzProxyDatasetId);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
})
|
|
235
|
-
.catch(() => {
|
|
236
|
-
console.log("Error when loading apps");
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
241
|
-
super.componentDidUpdate(prevProps, prevState, snapshot);
|
|
242
|
-
const { attributes: { app, dvzProxyDatasetId } } = this.props;
|
|
243
|
-
const { attributes: { dvzProxyDatasetId: prevDvzProxyDatasetId, app: prevAPP } } = prevProps;
|
|
244
|
-
if (app != prevAPP) { //if app changes we shoudl reload metadta
|
|
245
|
-
if (isSupersetAPI(app, this.state.apps)) { //if app is superset proxy an additional step is added
|
|
246
|
-
this.loadDatasets(app);
|
|
247
|
-
if (dvzProxyDatasetId) {
|
|
248
|
-
this.loadMetadata(app, dvzProxyDatasetId);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
this.loadMetadata(app, dvzProxyDatasetId);
|
|
253
|
-
}
|
|
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"
|
|
254
395
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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") {
|
|
264
421
|
this.loadMetadata(app, dvzProxyDatasetId);
|
|
422
|
+
}
|
|
265
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
|
+
}
|
|
266
456
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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;
|
|
283
481
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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();
|
|
287
492
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const categoriesUrl = `/api/${app}/categories${dvzProxyDatasetId ? `?dvzProxyDatasetId=${dvzProxyDatasetId}` : ''}`;
|
|
292
|
-
if (app != "csv") {
|
|
293
|
-
fetch(dimensionsUrl)
|
|
294
|
-
.then(response => {
|
|
295
|
-
if (!response.ok) {
|
|
296
|
-
throw new Error("HTTP status " + response.status);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
return response.json();
|
|
300
|
-
}
|
|
301
|
-
})
|
|
302
|
-
.then(data => {
|
|
303
|
-
this.setState({
|
|
304
|
-
dimensions: [{ "label": __("None"), "value": "none" }, ...getTranslatedOptions(data)]
|
|
305
|
-
});
|
|
306
|
-
})
|
|
307
|
-
.catch(function () {
|
|
308
|
-
console.log("Error when loading dimensions");
|
|
309
|
-
});
|
|
310
|
-
fetch(filtersUrl)
|
|
311
|
-
.then(response => {
|
|
312
|
-
if (!response.ok) {
|
|
313
|
-
throw new Error("HTTP status " + response.status);
|
|
314
|
-
}
|
|
315
|
-
return response.json();
|
|
316
|
-
})
|
|
317
|
-
.then(data => {
|
|
318
|
-
const options = data.map(f => ({ ...f, value: f.param }));
|
|
319
|
-
this.setState({ filters: options });
|
|
320
|
-
})
|
|
321
|
-
.catch(function (response) {
|
|
322
|
-
console.log("Error when loading filters", response);
|
|
323
|
-
});
|
|
324
|
-
fetch(measuresUrl)
|
|
325
|
-
.then(response => {
|
|
326
|
-
if (!response.ok) {
|
|
327
|
-
throw new Error("HTTP status " + response.status);
|
|
328
|
-
}
|
|
329
|
-
return response.json();
|
|
330
|
-
})
|
|
331
|
-
.then(data => {
|
|
332
|
-
sessionStorage.setItem(`measures_${app}`, JSON.stringify(getTranslatedOptions(data)));
|
|
333
|
-
this.setState({ measures: getTranslatedOptions(data) });
|
|
334
|
-
})
|
|
335
|
-
.catch(function () {
|
|
336
|
-
console.log("Error when loading measures");
|
|
337
|
-
});
|
|
338
|
-
fetch(categoriesUrl)
|
|
339
|
-
.then(response => {
|
|
340
|
-
if (!response.ok) {
|
|
341
|
-
throw new Error("HTTP status " + response.status);
|
|
342
|
-
}
|
|
343
|
-
return response.json();
|
|
344
|
-
})
|
|
345
|
-
.then(data => {
|
|
346
|
-
sessionStorage.setItem(`categories_${app}`, JSON.stringify(data));
|
|
347
|
-
this.setState({ categories: getTranslatedOptions(data) });
|
|
348
|
-
})
|
|
349
|
-
.catch(function (response) {
|
|
350
|
-
console.log("Error when getting categories", response);
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
fetchData(url, stateKey, transformData) {
|
|
355
|
-
fetch(url)
|
|
356
|
-
.then(response => {
|
|
357
|
-
if (!response.ok) {
|
|
358
|
-
throw new Error("HTTP status " + response.status);
|
|
359
|
-
}
|
|
360
|
-
return response.json();
|
|
361
|
-
})
|
|
362
|
-
.then(data => {
|
|
363
|
-
// TODO: Check if the data is an array
|
|
364
|
-
// @ts-ignore
|
|
365
|
-
this.setState({
|
|
366
|
-
[stateKey]: transformData(data)
|
|
367
|
-
});
|
|
368
|
-
})
|
|
369
|
-
.catch(() => {
|
|
370
|
-
console.log(`Error when loading ${stateKey}`);
|
|
493
|
+
}).then((data) => {
|
|
494
|
+
this.setState({
|
|
495
|
+
dimensions: [{ "label": __("None"), "value": "none" }, ...getTranslatedOptions(data)]
|
|
371
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
|
+
});
|
|
372
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
|
+
}
|
|
373
551
|
}
|
|
374
552
|
export default SizeConfig;
|