Skip to content

Commit 31d298a

Browse files
samuelreichertgjulivan
authored andcommitted
fix(custom-chart-web): fix data and layout parsing to merge sample when attribute is empty
1 parent da218d7 commit 31d298a

File tree

1 file changed

+10
-16
lines changed
  • packages/pluggableWidgets/custom-chart-web/src/utils

1 file changed

+10
-16
lines changed

packages/pluggableWidgets/custom-chart-web/src/utils/utils.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ export function parseData(staticData?: string, attributeData?: string, sampleDat
33
let finalData: Data[] = [];
44

55
try {
6-
if (staticData) {
7-
finalData = [...finalData, ...JSON.parse(staticData)];
8-
}
9-
if (attributeData) {
10-
finalData = [...finalData, ...JSON.parse(attributeData)];
11-
}
12-
if (!finalData.length && sampleData) {
13-
finalData = [...finalData, ...JSON.parse(sampleData)];
6+
const dataAttribute = attributeData ? JSON.parse(attributeData) : [];
7+
finalData = [...finalData, ...(staticData ? JSON.parse(staticData) : []), ...dataAttribute];
8+
9+
if (dataAttribute.length === 0) {
10+
finalData = [...finalData, ...(sampleData ? JSON.parse(sampleData) : [])];
1411
}
1512
} catch (error) {
1613
console.error("Error parsing chart data:", error);
@@ -23,14 +20,11 @@ export function parseLayout(staticLayout?: string, attributeLayout?: string, sam
2320
let finalLayout: Partial<Layout> = {};
2421

2522
try {
26-
if (staticLayout) {
27-
finalLayout = { ...finalLayout, ...JSON.parse(staticLayout) };
28-
}
29-
if (attributeLayout) {
30-
finalLayout = { ...finalLayout, ...JSON.parse(attributeLayout) };
31-
}
32-
if (Object.keys(finalLayout).length === 0 && sampleLayout) {
33-
finalLayout = { ...finalLayout, ...JSON.parse(sampleLayout) };
23+
const layoutAttribute = attributeLayout ? JSON.parse(attributeLayout) : {};
24+
finalLayout = { ...finalLayout, ...(staticLayout ? JSON.parse(staticLayout) : {}), ...layoutAttribute };
25+
26+
if (Object.keys(layoutAttribute).length === 0) {
27+
finalLayout = { ...finalLayout, ...(sampleLayout ? JSON.parse(sampleLayout) : {}) };
3428
}
3529
} catch (error) {
3630
console.error("Error parsing chart layout:", error);

0 commit comments

Comments
 (0)