@lightdash/common 0.1411.0 → 0.1411.1

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.
@@ -15,30 +15,69 @@ export type MetricExplorerComparisonType = {
15
15
  type: MetricExplorerComparison.PREVIOUS_PERIOD;
16
16
  } | {
17
17
  type: MetricExplorerComparison.DIFFERENT_METRIC;
18
- metricTable: string;
19
- metricName: string;
18
+ metric: {
19
+ label: string;
20
+ table: string;
21
+ name: string;
22
+ };
20
23
  };
21
24
  export declare const metricExploreDataPointWithDateValueSchema: z.ZodObject<z.objectUtil.extendShape<{
22
25
  date: z.ZodDate;
23
- metric: z.ZodNullable<z.ZodNumber>;
24
- compareMetric: z.ZodNullable<z.ZodNumber>;
26
+ metric: z.ZodObject<{
27
+ value: z.ZodNullable<z.ZodNumber>;
28
+ label: z.ZodNullable<z.ZodString>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ label: string | null;
31
+ value: number | null;
32
+ }, {
33
+ label: string | null;
34
+ value: number | null;
35
+ }>;
36
+ compareMetric: z.ZodObject<{
37
+ value: z.ZodNullable<z.ZodNumber>;
38
+ label: z.ZodNullable<z.ZodString>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ label: string | null;
41
+ value: number | null;
42
+ }, {
43
+ label: string | null;
44
+ value: number | null;
45
+ }>;
25
46
  }, {
26
47
  dateValue: z.ZodNumber;
27
48
  }>, "strip", z.ZodTypeAny, {
28
- metric: number | null;
49
+ metric: {
50
+ label: string | null;
51
+ value: number | null;
52
+ };
29
53
  date: Date;
30
- compareMetric: number | null;
54
+ compareMetric: {
55
+ label: string | null;
56
+ value: number | null;
57
+ };
31
58
  dateValue: number;
32
59
  }, {
33
- metric: number | null;
60
+ metric: {
61
+ label: string | null;
62
+ value: number | null;
63
+ };
34
64
  date: Date;
35
- compareMetric: number | null;
65
+ compareMetric: {
66
+ label: string | null;
67
+ value: number | null;
68
+ };
36
69
  dateValue: number;
37
70
  }>;
38
71
  export type MetricExploreDataPoint = {
39
72
  date: Date;
40
- metric: number | null;
41
- compareMetric: number | null;
73
+ metric: {
74
+ value: number | null;
75
+ label: string | null;
76
+ };
77
+ compareMetric: {
78
+ value: number | null;
79
+ label: string | null;
80
+ };
42
81
  };
43
82
  export type MetricExploreDataPointWithDateValue = MetricExploreDataPoint & {
44
83
  dateValue: number;
@@ -10,8 +10,14 @@ var MetricExplorerComparison;
10
10
  })(MetricExplorerComparison = exports.MetricExplorerComparison || (exports.MetricExplorerComparison = {}));
11
11
  const metricExploreDataPointSchema = zod_1.z.object({
12
12
  date: zod_1.z.date({ coerce: true }),
13
- metric: zod_1.z.number().nullable(),
14
- compareMetric: zod_1.z.number().nullable(),
13
+ metric: zod_1.z.object({
14
+ value: zod_1.z.number().nullable(),
15
+ label: zod_1.z.string().nullable(),
16
+ }),
17
+ compareMetric: zod_1.z.object({
18
+ value: zod_1.z.number().nullable(),
19
+ label: zod_1.z.string().nullable(),
20
+ }),
15
21
  });
16
22
  exports.metricExploreDataPointWithDateValueSchema = metricExploreDataPointSchema.extend({
17
23
  dateValue: zod_1.z.number(),
@@ -130,8 +130,14 @@ const getMetricExplorerDataPoints = (dimension, metric, metricRows) => {
130
130
  const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
131
131
  return Object.keys(groupByMetricRows).map((date) => ({
132
132
  date: new Date(date),
133
- metric: parseMetricValue(groupByMetricRows[date]?.[0]?.[metricId]?.value.raw),
134
- compareMetric: null,
133
+ metric: {
134
+ value: parseMetricValue(groupByMetricRows[date]?.[0]?.[metricId]?.value.raw),
135
+ label: metric.label ?? metric.name,
136
+ },
137
+ compareMetric: {
138
+ value: null,
139
+ label: null,
140
+ },
135
141
  }));
136
142
  };
137
143
  exports.getMetricExplorerDataPoints = getMetricExplorerDataPoints;
@@ -156,14 +162,28 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
156
162
  const compareMetricId = comparison.type === metricsExplorer_1.MetricExplorerComparison.PREVIOUS_PERIOD
157
163
  ? metricId
158
164
  : (0, item_1.getItemId)({
159
- table: comparison.metricTable,
160
- name: comparison.metricName,
165
+ table: comparison.metric.table,
166
+ name: comparison.metric.name,
161
167
  });
168
+ let comparisonMetricLabel = null;
169
+ if (comparison.type === metricsExplorer_1.MetricExplorerComparison.DIFFERENT_METRIC) {
170
+ comparisonMetricLabel =
171
+ comparison.metric.label ?? comparison.metric.name;
172
+ }
173
+ else if (comparison.type === metricsExplorer_1.MetricExplorerComparison.PREVIOUS_PERIOD) {
174
+ comparisonMetricLabel = 'Previous Period';
175
+ }
162
176
  return Array.from(dates).map((date) => ({
163
177
  date: new Date(date),
164
- metric: parseMetricValue(groupByMetricRows[date]?.[0]?.[metricId]?.value.raw),
165
- compareMetric: parseMetricValue(offsetGroupByCompareMetricRows[date]?.[0]?.[compareMetricId]?.value
166
- .raw),
178
+ metric: {
179
+ value: parseMetricValue(groupByMetricRows[date]?.[0]?.[metricId]?.value.raw),
180
+ label: metric.label ?? metric.name,
181
+ },
182
+ compareMetric: {
183
+ value: parseMetricValue(offsetGroupByCompareMetricRows[date]?.[0]?.[compareMetricId]
184
+ ?.value.raw),
185
+ label: comparisonMetricLabel,
186
+ },
167
187
  }));
168
188
  };
169
189
  exports.getMetricExplorerDataPointsWithCompare = getMetricExplorerDataPointsWithCompare;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.1411.0",
3
+ "version": "0.1411.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [