Skip to content
Snippets Groups Projects
Commit b3f4d08f authored by Tom Robinson's avatar Tom Robinson Committed by GitHub
Browse files

Merge pull request #4092 from metabase/fix-named-aggregations

Fix named aggregation formatting / saving. 
parents 64395b75 84041ec1
No related merge requests found
......@@ -487,11 +487,15 @@ var Query = {
getAggregationDescription(tableMetadata, query, options) {
return conjunctList(Query.getAggregations(query).map(aggregation => {
if (NamedClause.isNamed(aggregation)) {
return [NamedClause.getName(aggregation)];
}
if (AggregationClause.isMetric(aggregation)) {
let metric = _.findWhere(tableMetadata.metrics, { id: AggregationClause.getMetric(aggregation) });
let name = metric ? metric.name : "[Unknown Metric]";
return [options.jsx ? <span className="text-green text-bold">{name}</span> : name];
}
switch (aggregation[0]) {
case "METRIC":
let metric = _.findWhere(tableMetadata.metrics, { id: aggregation[1] });
let name = metric ? metric.name : "[Unknown Metric]";
return [options.jsx ? <span className="text-green text-bold">{name}</span> : name];
case "rows": return ["Raw data"];
case "count": return ["Count"];
case "cum_count": return ["Cumulative count"];
......
import Query from "metabase/lib/query";
import { createQuery, AggregationClause, BreakoutClause } from "metabase/lib/query";
const mockTableMetadata = {
display_name: "Order",
fields: [
{ id: 1, display_name: "Total" }
]
}
describe('Query', () => {
describe('createQuery', () => {
......@@ -284,6 +290,20 @@ describe('Query', () => {
})
});
describe("generateQueryDescription", () => {
it("should work with multiple aggregations", () => {
expect(Query.generateQueryDescription(mockTableMetadata, {
source_table: 1,
aggregation: [["count"], ["sum", ["field-id", 1]]]
})).toEqual("Orders, Count and Sum of Total")
})
it("should work with named aggregations", () => {
expect(Query.generateQueryDescription(mockTableMetadata, {
source_table: 1,
aggregation: [["named", ["sum", ["field-id", 1]], "Revenue"]]
})).toEqual("Orders, Revenue")
})
})
describe('AggregationClause', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment