@lightdash/common 0.1404.1 → 0.1404.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -97,13 +97,21 @@ const getMetricExplorerDateRangeFilters = (exploreName, dimensionName, dateRange
97
97
  ];
98
98
  };
99
99
  exports.getMetricExplorerDateRangeFilters = getMetricExplorerDateRangeFilters;
100
+ // TODO: Should we just use the formatted value instead?
101
+ // Parse the metric value to a number, returning null if it's not a number
102
+ const parseMetricValue = (value) => {
103
+ if (value === null || value === undefined)
104
+ return null;
105
+ const parsed = Number(value);
106
+ return Number.isNaN(parsed) ? null : parsed;
107
+ };
100
108
  const getMetricExplorerDataPoints = (dimension, metric, metricRows) => {
101
109
  const dimensionId = (0, item_1.getItemId)(dimension);
102
110
  const metricId = (0, item_1.getItemId)(metric);
103
111
  const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
104
112
  return Object.keys(groupByMetricRows).map((date) => ({
105
113
  date: new Date(date),
106
- metric: groupByMetricRows[date]?.[0]?.[metricId]?.value.raw ?? null,
114
+ metric: parseMetricValue(groupByMetricRows[date]?.[0]?.[metricId]?.value.raw),
107
115
  compareMetric: null,
108
116
  }));
109
117
  };
@@ -132,9 +140,9 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
132
140
  });
133
141
  return Array.from(dates).map((date) => ({
134
142
  date: new Date(date),
135
- metric: groupByMetricRows[date]?.[0]?.[metricId]?.value.raw ?? null,
136
- compareMetric: offsetGroupByCompareMetricRows[date]?.[0]?.[compareMetricId]?.value
137
- .raw ?? null,
143
+ metric: parseMetricValue(groupByMetricRows[date]?.[0]?.[metricId]?.value.raw),
144
+ compareMetric: parseMetricValue(offsetGroupByCompareMetricRows[date]?.[0]?.[compareMetricId]?.value
145
+ .raw),
138
146
  }));
139
147
  };
140
148
  exports.getMetricExplorerDataPointsWithCompare = getMetricExplorerDataPointsWithCompare;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.1404.1",
3
+ "version": "0.1404.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [