Skip to content

Commit 3f76066

Browse files
committed
fix: TypeError: Cannot read property 'title' of undefined
Annotation missing for time dimension backward compatibility fix
1 parent 2783446 commit 3f76066

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

packages/cubejs-api-gateway/index.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,23 @@ const prepareAnnotation = (metaConfig, query) => {
3636
}];
3737
};
3838

39+
const dimensions = (query.dimensions || []);
3940
return {
4041
measures: R.fromPairs((query.measures || []).map(annotation('measures')).filter(a => !!a)),
41-
dimensions: R.fromPairs((query.dimensions || []).map(annotation('dimensions')).filter(a => !!a)),
42+
dimensions: R.fromPairs(dimensions.map(annotation('dimensions')).filter(a => !!a)),
4243
segments: R.fromPairs((query.segments || []).map(annotation('segments')).filter(a => !!a)),
43-
timeDimensions: R.fromPairs((query.timeDimensions || [])
44-
.filter(td => !!td.granularity)
45-
.map(td => annotation('dimensions')(`${td.dimension}.${td.granularity}`))
46-
.filter(a => !!a)),
44+
timeDimensions: R.fromPairs(
45+
R.unnest(
46+
(query.timeDimensions || [])
47+
.filter(td => !!td.granularity)
48+
.map(
49+
td => [annotation('dimensions')(`${td.dimension}.${td.granularity}`)].concat(
50+
// TODO: deprecated: backward compatibility for referencing time dimensions without granularity
51+
dimensions.indexOf(td.dimension) === -1 ? [annotation('dimensions')(td.dimension)] : []
52+
).filter(a => !!a)
53+
)
54+
)
55+
),
4756
};
4857
};
4958

@@ -55,7 +64,7 @@ const transformValue = (value, type) => {
5564
};
5665

5766

58-
const transformData = (aliasToMemberNameMap, annotation, data) => (data.map(r => R.pipe(
67+
const transformData = (aliasToMemberNameMap, annotation, data, query) => (data.map(r => R.pipe(
5968
R.toPairs,
6069
R.map(p => {
6170
const memberName = aliasToMemberNameMap[p[0]];
@@ -72,7 +81,7 @@ const transformData = (aliasToMemberNameMap, annotation, data) => (data.map(r =>
7281

7382
// TODO: deprecated: backward compatibility for referencing time dimensions without granularity
7483
const memberNameWithoutGranularity = [path[0], path[1]].join('.');
75-
if (path.length === 3 && !annotation[memberNameWithoutGranularity]) {
84+
if (path.length === 3 && (query.dimensions || []).indexOf(memberNameWithoutGranularity) === -1) {
7685
return [
7786
transformResult,
7887
[
@@ -389,7 +398,7 @@ class ApiGateway {
389398
};
390399
res({
391400
query: normalizedQuery,
392-
data: transformData(aliasToMemberNameMap, flattenAnnotation, response.data),
401+
data: transformData(aliasToMemberNameMap, flattenAnnotation, response.data, normalizedQuery),
393402
lastRefreshTime: response.lastRefreshTime && response.lastRefreshTime.toISOString(),
394403
...(process.env.NODE_ENV === 'production' ? undefined : {
395404
refreshKeyValues: response.refreshKeyValues,

0 commit comments

Comments
 (0)