Skip to content
Snippets Groups Projects
Unverified Commit 77af6de5 authored by Dalton's avatar Dalton Committed by GitHub
Browse files

Revert to old template tag validation logic (#20750)


* Handle legacy Field filter parameters that did not specify `:widget-type`

* Fix indentation

* Test fix

* Revert to old template tag validation logic

* Update e2e test

Co-authored-by: default avatarCam Saul <github@camsaul.com>
parent 26f671e5
No related branches found
No related tags found
No related merge requests found
......@@ -286,18 +286,10 @@ export default class NativeQuery extends AtomicQuery {
}
allTemplateTagsAreValid() {
return this.templateTags().every(t => {
if (["text", "number", "date", "card", "snippet"].includes(t.type)) {
return true;
}
const isDimensionType = t.type === "dimension";
const hasDefinedWidgetType =
t["widget-type"] && t["widget-type"] !== "none";
const hasDefinedDimension = t.dimension != null;
return isDimensionType && hasDefinedWidgetType && hasDefinedDimension;
});
return this.templateTags().every(
// field filters require a field
t => !(t.type === "dimension" && t.dimension == null),
);
}
setTemplateTag(name, tag) {
......
......@@ -193,49 +193,6 @@ describe("NativeQuery", () => {
expect(q.canRun()).toBe(true);
});
it("bad type", () => {
q = q.setDatasetQuery(
assocIn(
q.datasetQuery(),
["native", "template-tags", "foo", "type"],
"type-that-does-not-exist",
),
);
expect(q.canRun()).toBe(false);
q = q.setDatasetQuery(
assocIn(
q.datasetQuery(),
["native", "template-tags", "foo", "type"],
"text",
),
);
expect(q.canRun()).toBe(true);
});
it("dimension type without a widget-type", () => {
q = q.setDatasetQuery(
assocIn(q.datasetQuery(), ["native", "template-tags", "foo"], {
type: "dimension",
dimension: ["field", 123, null],
}),
);
expect(q.canRun()).toBe(false);
});
it("dimension type with a widget-type of none", () => {
q = q.setDatasetQuery(
assocIn(q.datasetQuery(), ["native", "template-tags", "foo"], {
type: "dimension",
"widget-type": "none",
dimension: ["field", 123, null],
}),
);
expect(q.canRun()).toBe(false);
});
it("dimension type without a dimension", () => {
q = q.setDatasetQuery(
assocIn(q.datasetQuery(), ["native", "template-tags", "foo"], {
......
......@@ -30,9 +30,13 @@ describe("scenarios > filters > sql filters > field filter > None", () => {
filterWidget().should("not.exist");
});
it("should disallow the running of the query and the saving of the question", () => {
cy.get(".RunButton").should("be.disabled");
cy.findByText("Save").should("have.attr", "aria-disabled", "true");
it("should be runnable with the None filter being ignored (metabase#20643)", () => {
cy.get(".RunButton")
.first()
.click();
cy.wait("@dataset");
cy.findByText("Hudson Borer");
});
it("should let you change the field filter type to something else and restore the filter widget (metabase#13825)", () => {
......
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