Skip to content
Snippets Groups Projects
Unverified Commit 1a1265c0 authored by Paul Rosenzweig's avatar Paul Rosenzweig Committed by GitHub
Browse files

Fix query param date bug (#12239)


* Add Cypress test for #12228 (#12235)

* fix logic to check if we'll use fieldValueWidget while parsing query params

Co-authored-by: default avatarDamon P. Cortesi <d.lifehacker@gmail.com>
parent 3f96c477
No related branches found
No related tags found
No related merge requests found
......@@ -71,10 +71,14 @@ export default class Parameters extends Component {
const queryParam = query && query[parameter.slug];
if (queryParam != null || parameter.default != null) {
let value = queryParam != null ? queryParam : parameter.default;
if (parameter.hasOnlyFieldTargets && value && !Array.isArray(value)) {
// FieldValuesWidget always produces an array. If this param has
// only field targets we'll use that widget, so we should start with
// an array to match.
// ParameterValueWidget uses FieldValuesWidget if there's no available
// date widget and all targets are fields. This matches that logic.
const willUseFieldValuesWidget =
parameter.hasOnlyFieldTargets && !/^date\//.test(parameter.type);
if (willUseFieldValuesWidget && value && !Array.isArray(value)) {
// FieldValuesWidget always produces an array. If we'll use that
// widget, we should start with an array to match.
value = [value];
}
const fieldIds = parameter.field_ids || [];
......
import { signInAsNormalUser, restore, popover } from "__support__/cypress";
import {
signInAsNormalUser,
restore,
popover,
modal,
} from "__support__/cypress";
describe("scenarios > question > native", () => {
before(restore);
......@@ -150,4 +155,39 @@ describe("scenarios > question > native", () => {
cy.get(".NativeQueryEditor .Icon-play").click();
cy.contains("18,760");
});
it("can load a question with a date filter (from issue metabase#12228)", () => {
cy.request("POST", "/api/card", {
name: "Test Question",
dataset_query: {
type: "native",
native: {
query: "select count(*) from orders where {{created_at}}",
"template-tags": {
created_at: {
id: "6b8b10ef-0104-1047-1e1b-2492d5954322",
name: "created_at",
"display-name": "Created at",
type: "dimension",
dimension: ["field-id", 15],
"widget-type": "date/month-year",
},
},
},
database: 1,
},
display: "scalar",
description: null,
visualization_settings: {},
collection_id: null,
result_metadata: null,
metadata_checksum: null,
}).then(response => {
cy.visit(`/question/${response.body.id}?created_at=2020-01`);
modal()
.contains("Okay")
.click();
cy.contains("580");
});
});
});
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