Skip to content
Snippets Groups Projects
Unverified Commit 2bd3d707 authored by Ariya Hidayat's avatar Ariya Hidayat Committed by GitHub
Browse files

Fix #17975 by supporting getting MBQL field literal (#17982)

parent de39de8a
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,8 @@ export function isSameField(fieldA, fieldB, exact = false) {
*/
export function getFieldTargetId(field: FieldReference): ?FieldId {
if (isLocalField(field)) {
return typeof field[1] === "number" ? field[1] : field;
const type = typeof field[1];
return type === "number" || type === "string" ? field[1] : field;
}
console.warn("Unknown field type:", field);
}
......
......@@ -121,6 +121,17 @@ describe("Query", () => {
).toEqual({
breakout: [["field", 2, null]],
});
expect(
Query.updateBreakout(
{
breakout: [["field", "CREATED_AT", null]],
},
0,
["field", "DISCOUNT", null],
),
).toEqual({
breakout: [["field", "DISCOUNT", null]],
});
});
it("should update sort as well", () => {
expect(
......@@ -136,6 +147,23 @@ describe("Query", () => {
breakout: [["field", 3, { "temporal-unit": "year" }]],
"order-by": [["asc", ["field", 3, { "temporal-unit": "year" }]]],
});
expect(
Query.updateBreakout(
{
breakout: [["field", "CREATED_AT", { "temporal-unit": "month" }]],
"order-by": [
["asc", ["field", "CREATED_AT", { "temporal-unit": "month" }]],
],
},
0,
["field", "CREATED_AT", { "temporal-unit": "year" }],
),
).toEqual({
breakout: [["field", "CREATED_AT", { "temporal-unit": "year" }]],
"order-by": [
["asc", ["field", "CREATED_AT", { "temporal-unit": "year" }]],
],
});
});
});
......
......@@ -139,7 +139,7 @@ describe("binning related reproductions", () => {
cy.findByText("2018");
});
it.skip("should not remove order-by (sort) when changing the breakout field on an SQL saved question (metabase#17975)", () => {
it("should not remove order-by (sort) when changing the breakout field on an SQL saved question (metabase#17975)", () => {
cy.createNativeQuestion(
{
name: "17975",
......
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