@devgateway/dvz-wp-commons 1.0.5 → 1.2.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/Blocks.js CHANGED
@@ -1,39 +1,32 @@
1
- import React from 'react';
2
1
  import { __ } from '@wordpress/i18n';
3
2
  import { CheckboxControl, PanelBody, PanelRow, SelectControl, TextControl } from '@wordpress/components';
4
3
  import { Component } from '@wordpress/element';
5
4
  import apiFetch from '@wordpress/api-fetch';
6
- import { togglePanel } from './Util';
7
- import { getTranslatedOptions, isSupersetAPI } from './APIutils';
8
- import { subscribe, select } from '@wordpress/data';
9
- export const SizeConfig = ({ height, setAttributes, panelStatus, initialOpen = false }) => {
10
- return (React.createElement(PanelBody, { initialOpen: panelStatus ? panelStatus["SIZE"] : initialOpen, onToggle: () => togglePanel("SIZE", panelStatus, setAttributes), title: __("Size") },
5
+ import { togglePanel } from "./Util";
6
+ import { getTranslatedOptions } from './APIutils';
7
+ import { isSupersetAPI } from "./APIutils";
8
+ 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") },
11
10
  React.createElement(PanelRow, null,
12
11
  React.createElement(TextControl, { size: 10, label: "Height", value: height, onChange: (height) => setAttributes({ height: height ? parseInt(height) : 0 }) }))));
13
12
  };
14
13
  export class ComponentWithSettings extends Component {
15
- iframe;
16
- unsubscribe;
17
14
  constructor(props) {
18
15
  super(props);
19
16
  this.state = {
20
- react_ui_url: '',
21
- react_api_url: null,
22
- apache_superset_url: null,
23
- site_language: '',
24
- current_language: '',
17
+ react_ui_url: ''
25
18
  };
26
19
  window.addEventListener("message", (event) => {
27
20
  if (event.data.type === 'componentReady' && event.data.value === true) {
28
21
  if (this.iframe.current) {
29
22
  console.log("-----------Sending message -----------");
30
- this.iframe.current.contentWindow?.postMessage(({ messageType: 'component-attributes', ...this.props.attributes }), "*");
23
+ this.iframe.current.contentWindow.postMessage(({ messageType: 'component-attributes', ...this.props.attributes }), "*");
31
24
  }
32
25
  }
33
26
  }, false);
34
27
  this.iframe = React.createRef();
35
- this.unsubscribe = subscribe(() => {
36
- const newPreviewMode = select("core/editor").getDeviceType();
28
+ this.unsubscribe = wp.data.subscribe(() => {
29
+ const newPreviewMode = wp.data.select("core/editor").getDeviceType();
37
30
  if (newPreviewMode !== this.state.previewMode) {
38
31
  this.setState({ previewMode: newPreviewMode });
39
32
  }
@@ -51,7 +44,7 @@ export class ComponentWithSettings extends Component {
51
44
  react_api_url: data["react_api_url"],
52
45
  apache_superset_url: data["apache_superset_url"],
53
46
  site_language: data["site_language"],
54
- current_language: new URLSearchParams(document.location.search).get("edit_lang") || ''
47
+ current_language: new URLSearchParams(document.location.search).get("edit_lang")
55
48
  });
56
49
  });
57
50
  }
@@ -65,15 +58,7 @@ export class BlockEditWithFilters extends ComponentWithSettings {
65
58
  constructor(props) {
66
59
  super(props);
67
60
  this.state = {
68
- react_ui_url: '',
69
- react_api_url: null,
70
- apache_superset_url: null,
71
- site_language: '',
72
- current_language: '',
73
- taxonomyValues: [],
74
- types: null,
75
- taxonomies: null,
76
- loading: true
61
+ taxonomyValues: [], types: null, taxonomies: null, loading: true
77
62
  };
78
63
  this.onTypeChanged = this.onTypeChanged.bind(this);
79
64
  this.onTaxonomyChanged = this.onTaxonomyChanged.bind(this);
@@ -81,7 +66,7 @@ export class BlockEditWithFilters extends ComponentWithSettings {
81
66
  this.onCategoryChanged = this.onCategoryChanged.bind(this);
82
67
  }
83
68
  componentDidUpdate(prevProps, prevState, snapshot) {
84
- const { attributes: { type, taxonomy }, } = this.props;
69
+ const { setAttributes, attributes: { type, taxonomy, count }, } = this.props;
85
70
  super.componentDidUpdate(prevProps, prevState, snapshot);
86
71
  if (prevProps.attributes) {
87
72
  if (type != prevProps.attributes.type) {
@@ -95,7 +80,7 @@ export class BlockEditWithFilters extends ComponentWithSettings {
95
80
  super.componentDidMount();
96
81
  this.getTypes();
97
82
  this.getTaxonomies();
98
- const { attributes: { taxonomy }, } = this.props;
83
+ const { setAttributes, attributes: { type, taxonomy, count }, } = this.props;
99
84
  if (taxonomy != 'none') {
100
85
  this.getTaxonomyValues();
101
86
  }
@@ -123,15 +108,15 @@ export class BlockEditWithFilters extends ComponentWithSettings {
123
108
  }
124
109
  }
125
110
  getTaxonomyValues() {
126
- const { attributes: { taxonomy }, } = this.props;
127
- apiFetch({
128
- path: '/wp/v2/taxonomies/' + taxonomy + '?per_page=100',
111
+ const { setAttributes, attributes: { type, taxonomy, count }, } = this.props;
112
+ wp.apiFetch({
113
+ path: '/wp/v2/' + taxonomy + '?per_page=100',
129
114
  }).then(data => {
130
115
  this.setState({ taxonomyValues: data });
131
116
  });
132
117
  }
133
118
  getTaxonomies() {
134
- apiFetch({
119
+ wp.apiFetch({
135
120
  path: '/wp/v2/taxonomies?per_page=100',
136
121
  }).then(data => {
137
122
  this.setState({
@@ -140,16 +125,18 @@ export class BlockEditWithFilters extends ComponentWithSettings {
140
125
  });
141
126
  }
142
127
  getTypes() {
143
- apiFetch({
128
+ wp.apiFetch({
144
129
  path: '/wp/v2/types?per_page=100',
145
130
  }).then(data => {
131
+ const types = data;
146
132
  this.setState({
147
133
  types: data, loading: false
148
134
  });
149
135
  });
150
136
  }
151
137
  typeOptions() {
152
- const { types } = this.state;
138
+ const { setAttributes, attributes: { count, type, taxonomy, category }, } = this.props;
139
+ const { types, taxonomies, taxonomyValues } = this.state;
153
140
  const typeOptions = types ? Object.keys(types)
154
141
  .filter(k => ['page', 'attachment', 'wp_block']
155
142
  .indexOf(k) == -1).map(k => ({
@@ -159,7 +146,7 @@ export class BlockEditWithFilters extends ComponentWithSettings {
159
146
  }
160
147
  taxonomyOptions() {
161
148
  const { attributes: { type, }, } = this.props;
162
- const { types, taxonomies } = this.state;
149
+ const { types, taxonomies, taxonomyValues } = this.state;
163
150
  let slug;
164
151
  if (types) {
165
152
  slug = this.typeOptions().filter(t => t.value == type)[0].slug;
@@ -174,9 +161,9 @@ export class BlockEditWithFilters extends ComponentWithSettings {
174
161
  }
175
162
  }
176
163
  categoriesOptions() {
177
- const { taxonomyValues } = this.state;
164
+ const { types, taxonomies, taxonomyValues } = this.state;
178
165
  const taxonomyValuesOptions = taxonomyValues && taxonomyValues.map(t => ({ label: t.name, value: t.id }));
179
- return taxonomyValuesOptions || [];
166
+ return taxonomyValuesOptions;
180
167
  }
181
168
  renderFilters() {
182
169
  const { attributes: { type, taxonomy, categories, } } = this.props;
@@ -185,7 +172,7 @@ export class BlockEditWithFilters extends ComponentWithSettings {
185
172
  React.createElement(SelectControl, { label: __("Post Type"), options: this.typeOptions(), value: type, onChange: this.onTypeChanged })),
186
173
  React.createElement(PanelRow, null,
187
174
  React.createElement(SelectControl, { label: __("Use a taxonomy filter "), options: this.taxonomyOptions(), value: taxonomy, onChange: this.onTaxonomyChanged })),
188
- (taxonomy != 'none' && this.categoriesOptions().length > 0) && this.categoriesOptions().map(o => {
175
+ taxonomy != 'none' && this.categoriesOptions().map(o => {
189
176
  return React.createElement(PanelRow, null,
190
177
  React.createElement(CheckboxControl, { label: o.label, onChange: (checked) => this.onCategoryChanged(checked, o.value), checked: categories.indexOf(o.value) > -1 }));
191
178
  })));
@@ -204,7 +191,7 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
204
191
  'Accept': 'application/json',
205
192
  },
206
193
  })
207
- .then((response) => response.json())
194
+ .then(response => response.json())
208
195
  .then(data => {
209
196
  const apps = data.applications ? [...data.applications.application
210
197
  .filter(a => a.instance[0].metadata.type === 'data')
@@ -220,7 +207,7 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
220
207
  react_api_url: settingsData["react_api_url"],
221
208
  apache_superset_url: settingsData["apache_superset_url"],
222
209
  site_language: settingsData["site_language"],
223
- current_language: new URLSearchParams(document.location.search).get("edit_lang") || "",
210
+ current_language: new URLSearchParams(document.location.search).get("edit_lang"),
224
211
  apps
225
212
  }, () => {
226
213
  const { app, dvzProxyDatasetId } = this.props.attributes;
@@ -237,8 +224,8 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
237
224
  });
238
225
  });
239
226
  }
240
- componentDidUpdate(prevProps, prevState, snapshot) {
241
- super.componentDidUpdate(prevProps, prevState, snapshot);
227
+ componentDidUpdate(prevProps) {
228
+ super.componentDidUpdate(prevProps);
242
229
  const { attributes: { app, dvzProxyDatasetId } } = this.props;
243
230
  const { attributes: { dvzProxyDatasetId: prevDvzProxyDatasetId, app: prevAPP } } = prevProps;
244
231
  if (app != prevAPP) { //if app changes we shoudl reload metadta
@@ -249,7 +236,7 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
249
236
  }
250
237
  }
251
238
  else {
252
- this.loadMetadata(app, dvzProxyDatasetId);
239
+ this.loadMetadata(app);
253
240
  }
254
241
  }
255
242
  else { //app wasn't changed
@@ -304,7 +291,7 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
304
291
  dimensions: [{ "label": __("None"), "value": "none" }, ...getTranslatedOptions(data)]
305
292
  });
306
293
  })
307
- .catch(function () {
294
+ .catch(function (response) {
308
295
  console.log("Error when loading dimensions");
309
296
  });
310
297
  fetch(filtersUrl)
@@ -332,7 +319,7 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
332
319
  sessionStorage.setItem(`measures_${app}`, JSON.stringify(getTranslatedOptions(data)));
333
320
  this.setState({ measures: getTranslatedOptions(data) });
334
321
  })
335
- .catch(function () {
322
+ .catch(function (response) {
336
323
  console.log("Error when loading measures");
337
324
  });
338
325
  fetch(categoriesUrl)
@@ -360,8 +347,6 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
360
347
  return response.json();
361
348
  })
362
349
  .then(data => {
363
- // TODO: Check if the data is an array
364
- // @ts-ignore
365
350
  this.setState({
366
351
  [stateKey]: transformData(data)
367
352
  });
@@ -1,5 +1,4 @@
1
- import React from 'react';
2
- export declare const CSVConfig: ({ attributes: { csv, panelStatus, measures, type }, setAttributes }: {
1
+ export function CSVConfig({ attributes: { csv, panelStatus, measures, type }, setAttributes }: {
3
2
  attributes: {
4
3
  csv: any;
5
4
  panelStatus: any;
@@ -7,5 +6,5 @@ export declare const CSVConfig: ({ attributes: { csv, panelStatus, measures, typ
7
6
  type: any;
8
7
  };
9
8
  setAttributes: any;
10
- }) => React.JSX.Element[];
9
+ }): import("react").JSX.Element[];
11
10
  export default CSVConfig;
@@ -1,20 +1,21 @@
1
- import React from 'react';
2
1
  import { PanelBody, PanelRow, TextareaControl } from '@wordpress/components';
3
2
  import { __ } from '@wordpress/i18n';
4
3
  import Format from "./Format";
5
4
  import { togglePanel } from "./Util";
6
5
  const defaultFormat = {
7
- "style": "percent",
8
- "minimumFractionDigits": 1,
9
- "maximumFractionDigits": 1,
10
- "currency": "USD"
6
+ "style": "percent", "minimumFractionDigits": 1, "maximumFractionDigits": 1, "currency": "USD"
11
7
  };
12
8
  export const CSVConfig = ({ attributes: { csv, panelStatus, measures, type }, setAttributes }) => {
13
9
  const onFormatChange = (format, field) => {
14
10
  const app = "csv";
15
11
  const uMs = measures ? JSON.parse(JSON.stringify(measures)) : {};
16
12
  if (!uMs[app]) {
17
- uMs[app] = { allowSelection: false, format: Object.assign({}, defaultFormat), customFormat: Object.assign({}, { ...defaultFormat }), selected: false };
13
+ uMs[app] = {
14
+ allowSelection: false,
15
+ format: Object.assign({}, defaultFormat),
16
+ customFormat: Object.assign({}, { ...defaultFormat }),
17
+ selected: false
18
+ };
18
19
  }
19
20
  uMs[app][field] = format;
20
21
  setAttributes({ measures: uMs });
@@ -30,7 +31,12 @@ export const CSVConfig = ({ attributes: { csv, panelStatus, measures, type }, se
30
31
  setAttributes({ measures: uMs });
31
32
  }
32
33
  else {
33
- uMs[app] = { allowSelection: false, format: Object.assign({}, { ...defaultFormat }), customFormat: Object.assign({}, { ...defaultFormat }), selected: false };
34
+ uMs[app] = {
35
+ allowSelection: false,
36
+ format: Object.assign({}, { ...defaultFormat }),
37
+ customFormat: Object.assign({}, { ...defaultFormat }),
38
+ selected: false
39
+ };
34
40
  uMs[app].useCustomAxisFormat = value;
35
41
  setAttributes({ measures: uMs });
36
42
  }
@@ -42,7 +48,6 @@ export const CSVConfig = ({ attributes: { csv, panelStatus, measures, type }, se
42
48
  onFormatChange(newFormat, field);
43
49
  }, onUseCustomAxisFormatChange: value => {
44
50
  onUseCustomAxisFormatChange(value);
45
- } }))
46
- ]);
51
+ } }))]);
47
52
  };
48
53
  export default CSVConfig;
@@ -1,55 +1,14 @@
1
- import React from "react";
2
- import { Categories, Dimension, Filter, Measure } from "./types";
3
- export declare const categorical: {
1
+ export const categorical: {
4
2
  value: string;
5
3
  label: string;
6
4
  }[];
7
- export declare const sequential: {
5
+ export const sequential: {
8
6
  value: string;
9
7
  label: string;
10
8
  }[];
11
- export declare const diverging: {
9
+ export const diverging: {
12
10
  value: string;
13
11
  label: string;
14
12
  }[];
15
- export type ChartColorsProps = {
16
- allDimensions?: Dimension[];
17
- allFilters?: Filter[];
18
- allMeasures?: Measure[];
19
- allCategories?: Categories;
20
- allApps?: any[];
21
- setAttributes: (attributes: {
22
- swap: boolean;
23
- measures: Record<string, {
24
- selected: boolean;
25
- }>;
26
- manualColors?: Record<string, Record<string, string>>;
27
- scheme: string;
28
- colorBy: string;
29
- dimension1: string;
30
- dimension2: string;
31
- barColor: string | null;
32
- type: string;
33
- app: string;
34
- csv: string;
35
- includeOverall: boolean;
36
- }) => void;
37
- attributes: {
38
- swap: boolean;
39
- measures: Record<string, {
40
- selected: boolean;
41
- }>;
42
- manualColors: Record<string, Record<string, string>>;
43
- scheme: string;
44
- colorBy: string;
45
- dimension1: string;
46
- dimension2: string;
47
- barColor: string;
48
- type: string;
49
- app: string;
50
- csv: string;
51
- includeOverall: boolean;
52
- };
53
- };
54
- export declare const ChartColors: (props: ChartColorsProps) => (string | number | boolean | React.JSX.Element | Iterable<React.ReactNode> | null | undefined)[] | null;
13
+ export function ChartColors(props: any): (false | import("react").JSX.Element)[] | null;
55
14
  export default ChartColors;
@@ -1,10 +1,10 @@
1
- import React, { useEffect } from "react";
2
1
  import { PanelBody, PanelRow, SelectControl } from '@wordpress/components';
2
+ import { PanelColorSettings } from '@wordpress/block-editor';
3
3
  import { __ } from '@wordpress/i18n';
4
+ import { useEffect } from "react";
4
5
  import Papa from 'papaparse';
5
6
  import { useRef, useState } from "@wordpress/element";
6
7
  import { getTranslation } from "./APIutils";
7
- import { PanelColorSettings } from "@wordpress/block-editor";
8
8
  const OVERALL = 'Overall';
9
9
  const system = [{ value: "system", label: 'System Colors' }, { value: "manual", label: 'Manual Colors' }];
10
10
  export const categorical = [{ value: "nivo", label: 'nivo' }, {
@@ -41,11 +41,10 @@ export const diverging = [{ value: "brown_blueGreen", label: 'brown_blueGreen' }
41
41
  ];
42
42
  const plainColor = { value: "plain_color", label: 'Use Plain color' };
43
43
  export const ChartColors = (props) => {
44
- const { allDimensions, allFilters, allMeasures, allCategories, allApps, setAttributes, attributes } = props;
45
- const { swap, measures, manualColors, scheme, colorBy, dimension1, dimension2, barColor, type, app, csv, includeOverall } = attributes;
46
- let l1Label = null;
47
- let d2Label = null;
48
- let d3Label = null;
44
+ const { allDimensions, allFilters, allMeasures, allCategories, allApps, setAttributes, attributes: { swap, measures, manualColors, scheme, colorBy, dimension1, dimension2, barColor, type, app, csv, includeOverall } } = props;
45
+ let l1Label;
46
+ let d2Label;
47
+ let d3Label;
49
48
  const selectedMeasures = measures[app] ? Object.keys(measures[app]).map(k => measures[app][k]).filter(m => m.selected) : [];
50
49
  let colorOptions = [];
51
50
  if (app !== "csv") {
@@ -64,23 +63,19 @@ export const ChartColors = (props) => {
64
63
  else {
65
64
  //CSV Color Options
66
65
  const data = Papa.parse(csv, { header: true, dynamicTyping: true });
67
- l1Label = data.meta.fields && data.meta.fields.length > 0 ? '1st Column Values ' : null;
66
+ l1Label = data.meta.fields.length > 0 ? '1st Column Values ' : null;
68
67
  d2Label = __("Measure Columns Labels");
69
68
  d3Label = __("Measure Columns Values");
70
69
  }
71
- if (type == 'bar') {
70
+ if (type == 'bar' || type == 'line') {
72
71
  if (swap && dimension2 == "none" && selectedMeasures.length > 0) {
73
72
  colorOptions = [];
74
73
  if (l1Label) {
75
74
  colorOptions.push({ label: l1Label, value: 'id' });
76
- if (d2Label) {
77
- colorOptions.push({ label: d2Label, value: 'index' });
78
- }
75
+ colorOptions.push({ label: d2Label, value: 'index' });
79
76
  }
80
77
  else {
81
- if (d2Label) {
82
- colorOptions.push({ label: d2Label, value: 'id' });
83
- }
78
+ colorOptions.push({ label: d2Label, value: 'id' });
84
79
  colorOptions.push({ label: "Measure Values", value: 'values' });
85
80
  }
86
81
  }
@@ -99,11 +94,11 @@ export const ChartColors = (props) => {
99
94
  }
100
95
  if (type == 'pie') {
101
96
  if (dimension1 != 'none' && dimension2 == 'none' && colorBy != 'index') {
102
- setAttributes({ ...attributes, colorBy: 'index' });
97
+ setAttributes({ colorBy: 'index' });
103
98
  return null;
104
99
  }
105
100
  if (dimension1 != 'none' && dimension2 != 'none' && colorBy != 'id') {
106
- setAttributes({ ...attributes, colorBy: 'id' });
101
+ setAttributes({ colorBy: 'id' });
107
102
  return null;
108
103
  }
109
104
  }
@@ -128,7 +123,6 @@ export const ChartColors = (props) => {
128
123
  if (app != "csv") {
129
124
  // All conditions for coloring by measures
130
125
  if ((dimension2 == "none" && colorBy === "index" && swap) ||
131
- (type == 'line') ||
132
126
  (dimension1 == "none" && dimension2 == "none")) { //Multi measure colored by first dimension but swapped (Colored by Measure) or dimensionless bar charts
133
127
  nextUseColors = "measure";
134
128
  }
@@ -159,34 +153,34 @@ export const ChartColors = (props) => {
159
153
  }
160
154
  else {
161
155
  if (!manualColors["csv"]) {
162
- setAttributes({ ...attributes, manualColors: { "csv": {} }, colorBy: colorBy || "" });
156
+ setAttributes({ manualColors: { "csv": {} } });
163
157
  }
164
158
  }
165
- prevStatus.current = { scheme, colorBy: colorBy || "", dimension1, dimension2, useColors, app };
159
+ prevStatus.current = { scheme, colorBy, dimension1, dimension2, useColors, app };
166
160
  }, [scheme, dimension1, dimension2, colorBy, swap, app, type]);
167
- const prevStatus = useRef(undefined);
161
+ const prevStatus = useRef();
168
162
  const updateColor = (value, color) => {
169
163
  const newColors = Object.assign({}, manualColors);
170
164
  newColors[app][value] = color;
171
- setAttributes({ ...attributes, manualColors: newColors, colorBy: colorBy || "" });
165
+ setAttributes({ manualColors: newColors });
172
166
  };
173
167
  const initColors = (dimension) => {
174
- const ds = allDimensions?.filter(d => d.value == dimension);
168
+ const ds = allDimensions.filter(d => d.value == dimension);
175
169
  const newColors = Object.assign({}, manualColors);
176
170
  if (!newColors[app]) {
177
171
  newColors[app] = {};
178
172
  }
179
- if (ds && ds.length > 0) {
173
+ if (ds.length > 0) {
180
174
  const { type } = ds[0];
181
- const cat = allCategories?.filter(a => a.type === type);
182
- if (cat && cat.length > 0) {
175
+ const cat = allCategories.filter(a => a.type === type);
176
+ if (cat.length > 0) {
183
177
  cat[0].items.forEach(item => {
184
178
  if (!newColors[app][item.code]) {
185
179
  newColors[app][item.code] = item.categoryStyle ? item.categoryStyle.color : "#eeeeee";
186
180
  }
187
181
  });
188
182
  }
189
- setAttributes({ ...attributes, manualColors: newColors });
183
+ setAttributes({ manualColors: newColors });
190
184
  }
191
185
  };
192
186
  const initMeasuresColors = () => {
@@ -203,20 +197,20 @@ export const ChartColors = (props) => {
203
197
  }
204
198
  });
205
199
  }
206
- setAttributes({ ...attributes, manualColors: newColors });
200
+ setAttributes({ manualColors: newColors });
207
201
  };
208
202
  const combinedCatColors = (dimension1, dimension2) => {
209
203
  if (manualColors[app]) {
210
- const ds1 = allDimensions?.filter(d => d.value == dimension1);
211
- const ds2 = allDimensions?.filter(d => d.value == dimension2);
212
- if (ds1 && ds1.length > 0 && ds2 && ds2.length > 0) {
204
+ const ds1 = allDimensions.filter(d => d.value == dimension1);
205
+ const ds2 = allDimensions.filter(d => d.value == dimension2);
206
+ if (ds1.length > 0 && ds2.length > 0) {
213
207
  const { type } = ds1[0];
214
208
  const { type: type2 } = ds2[0];
215
- const cat = allCategories?.filter(a => a.type === type);
216
- const cat2 = allCategories?.filter(a => a.type === type2);
209
+ const cat = allCategories.filter(a => a.type === type);
210
+ const cat2 = allCategories.filter(a => a.type === type2);
217
211
  const list = [];
218
- cat?.[0].items.sort((a, b) => (a.position ?? 0) - (b.position ?? 0)).forEach(c1 => {
219
- cat2?.[0].items.sort((a, b) => (a.position ?? 0) - (b.position ?? 0)).forEach(c2 => {
212
+ cat[0].items.sort((a, b) => a.position - b.position).forEach(c1 => {
213
+ cat2[0].items.sort((a, b) => a.position - b.position).forEach(c2 => {
220
214
  list.push(React.createElement(PanelColorSettings, { colorSettings: [{
221
215
  value: manualColors[app][c1.value + ' - ' + c2.value],
222
216
  onChange: (color) => {
@@ -238,12 +232,12 @@ export const ChartColors = (props) => {
238
232
  };
239
233
  const catColors = (dimension) => {
240
234
  if (manualColors[app]) {
241
- const ds = allDimensions?.filter(d => d.value == dimension);
242
- if (ds && ds.length > 0) {
235
+ const ds = allDimensions.filter(d => d.value == dimension);
236
+ if (ds.length > 0) {
243
237
  const { type } = ds[0];
244
- const cat = allCategories?.filter(a => a.type === type);
238
+ const cat = allCategories.filter(a => a.type === type);
245
239
  if (cat && cat.length > 0) {
246
- const list = cat[0].items.sort((a, b) => (b.position ?? 0) - (a.position ?? 0)).map(item => {
240
+ const list = cat[0].items.filter(c => c.code !== null && c.code !== undefined && c.code !== "").sort((a, b) => b.position - a.position).map(item => {
247
241
  return React.createElement(PanelColorSettings, { colorSettings: [{
248
242
  value: manualColors[app][item.code],
249
243
  onChange: (color) => {
@@ -258,7 +252,7 @@ export const ChartColors = (props) => {
258
252
  });
259
253
  const dimensions = [dimension1, dimension2].filter(f => f != '' && f != "none");
260
254
  let selectedMeasures = [];
261
- allMeasures?.forEach(m => {
255
+ allMeasures.forEach(m => {
262
256
  if (measures[app] && measures[app][m.value] && measures[app][m.value].selected) {
263
257
  selectedMeasures.push(m.value);
264
258
  }
@@ -319,22 +313,15 @@ export const ChartColors = (props) => {
319
313
  }
320
314
  return null;
321
315
  };
322
- const csvColors = (colorBy) => {
316
+ const csvColors = () => {
323
317
  const data = Papa.parse(csv, { header: true, dynamicTyping: true });
324
318
  const values = [];
325
319
  if (colorBy === "index" && type != 'line') {
326
- const field = data.meta?.fields?.[0];
327
- if (field) {
328
- values.push(...data.data.map((d) => d[field]));
329
- }
320
+ const field = data.meta.fields[0];
321
+ values.push(...data.data.map(d => d[field]));
330
322
  }
331
323
  if (colorBy === "id" || type == 'line') {
332
- const fields = data.meta?.fields?.slice(1);
333
- if (fields) {
334
- // Convert string fields to numbers before pushing to values array
335
- const numericFields = fields.map(field => Number(field));
336
- values.push(...numericFields);
337
- }
324
+ values.push(...data.meta.fields.slice(1));
338
325
  }
339
326
  if (colorBy === "values") {
340
327
  values.push(0, 100);
@@ -345,41 +332,41 @@ export const ChartColors = (props) => {
345
332
  value: manualColors[app][v],
346
333
  onChange: (color) => {
347
334
  if (color) {
348
- updateColor(v.toString(), color);
335
+ updateColor(v, color);
349
336
  }
350
- }, label: __(v.toString())
337
+ }, label: __(v)
351
338
  }] });
352
339
  });
353
340
  }
354
341
  return null;
355
342
  };
356
343
  const elements = [];
357
- if (type == 'bar') {
344
+ if (type == 'bar' || type == 'line') {
358
345
  elements.push(React.createElement(PanelRow, null,
359
- React.createElement(SelectControl, { multiple: false, label: __('Color By'), value: colorBy, onChange: (colorBy) => {
360
- setAttributes({ ...attributes, colorBy });
346
+ React.createElement(SelectControl, { label: __('Color By'), value: [colorBy], onChange: (colorBy) => {
347
+ setAttributes({ colorBy });
361
348
  if (colorBy === 'index' || colorBy === 'id') {
362
- setAttributes({ ...attributes, colorBy });
349
+ setAttributes({ colorBy });
363
350
  }
364
351
  if (colorBy === 'values') {
365
- setAttributes({ ...attributes, scheme: "blues", colorBy });
352
+ setAttributes({ scheme: "blues", colorBy });
366
353
  }
367
354
  }, options: colorOptions })));
368
355
  }
369
356
  return [
370
357
  ...elements,
371
358
  React.createElement(PanelRow, null,
372
- React.createElement(SelectControl, { multiple: false, label: __('Color Scheme'), value: scheme, onChange: (value) => {
373
- setAttributes({ ...attributes, scheme: value });
359
+ React.createElement(SelectControl, { label: __('Color Scheme'), value: [scheme], onChange: (value) => {
360
+ setAttributes({ scheme: value });
374
361
  }, options: options })),
375
362
  (scheme == "plain_color") && React.createElement(PanelRow, null,
376
363
  React.createElement(PanelColorSettings, { title: __('Color settings'), colorSettings: [{
377
364
  value: decodeURIComponent(barColor), onChange: (color) => {
378
365
  if (color) {
379
- setAttributes({ ...attributes, barColor: encodeURIComponent(color) });
366
+ setAttributes({ barColor: encodeURIComponent(color) });
380
367
  }
381
368
  else {
382
- setAttributes({ ...attributes, barColor: null });
369
+ setAttributes({ barColor: null });
383
370
  }
384
371
  }, label: __('Plain color')
385
372
  }] })),
@@ -1,33 +1,2 @@
1
- import React from 'react';
2
- export type LegendPosition = 'left' | 'top' | 'right' | 'bottom';
3
- export type LegendProps = {
4
- legendPosition?: LegendPosition;
5
- setAttributes: (attributes: {
6
- showLegends: boolean;
7
- legendPosition: LegendPosition;
8
- marginLeft: number;
9
- marginRight: number;
10
- marginBottom: number;
11
- marginTop: number;
12
- legendLabel: string;
13
- useLabelBackground: boolean;
14
- useCheckBoxBackground: boolean;
15
- legendLabelColor: string | null;
16
- reverseLegend: boolean;
17
- }) => void;
18
- attributes: {
19
- showLegends: boolean;
20
- legendPosition: LegendPosition;
21
- marginLeft: number;
22
- marginRight: number;
23
- marginBottom: number;
24
- marginTop: number;
25
- legendLabel: string;
26
- useLabelBackground: boolean;
27
- useCheckBoxBackground: boolean;
28
- legendLabelColor: string;
29
- reverseLegend: boolean;
30
- };
31
- };
32
- export declare const ChartLegends: (props: LegendProps) => React.JSX.Element[];
1
+ export function ChartLegends(props: any): import("react").JSX.Element[];
33
2
  export default ChartLegends;