Skip to content
Snippets Groups Projects
Unverified Commit 2c3b5838 authored by Kamil Mielnik's avatar Kamil Mielnik Committed by GitHub
Browse files

Fix - metrics do not work with offset in custom expressions (#48188)

* Allow using metrics with offset in custom expressions

* Unskip and update repro
parent a5466e05
Branches
Tags
No related merge requests found
......@@ -1224,8 +1224,7 @@ describe("scenarios > question > offset", () => {
]);
});
// unskip once https://github.com/metabase/metabase/issues/47854 is fixed
it.skip("should work with metrics (metabase#47854)", () => {
it("should work with metrics (metabase#47854)", () => {
const metricName = "Count of orders";
const ORDERS_SCALAR_METRIC: StructuredQuestionDetails = {
name: metricName,
......@@ -1234,6 +1233,13 @@ describe("scenarios > question > offset", () => {
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
breakout: [
[
"field",
ORDERS.CREATED_AT,
{ "base-type": "type/DateTime", "temporal-unit": "month" },
],
],
},
display: "scalar",
};
......
......@@ -127,31 +127,60 @@ export function formatSegmentName(
*/
export function parseDimension(
name: string,
{
query,
stageIndex,
expressionIndex,
}: {
options: {
query: Lib.Query;
stageIndex: number;
source: string;
expressionIndex: number | undefined;
startRule: string;
},
) {
const columns = Lib.expressionableColumns(query, stageIndex, expressionIndex);
return columns.find(column => {
const displayInfo = Lib.displayInfo(query, stageIndex, column);
return getAvailableDimensions(options).find(({ info }) => {
return EDITOR_FK_SYMBOLS.symbols.some(separator => {
const displayName = getDisplayNameWithSeparator(
displayInfo.longDisplayName,
info.longDisplayName,
separator,
);
return displayName === name;
});
})?.dimension;
}
function getAvailableDimensions({
query,
stageIndex,
expressionIndex,
startRule,
}: {
query: Lib.Query;
stageIndex: number;
expressionIndex: number | undefined;
startRule: string;
}) {
const results = Lib.expressionableColumns(
query,
stageIndex,
expressionIndex,
).map(dimension => {
return {
dimension,
info: Lib.displayInfo(query, stageIndex, dimension),
};
});
if (startRule === "aggregation") {
return [
...results,
...Lib.availableMetrics(query, stageIndex).map(dimension => {
return {
dimension,
info: Lib.displayInfo(query, stageIndex, dimension),
};
}),
];
}
return results;
}
export function formatLegacyDimensionName(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment