Skip to content
Snippets Groups Projects
Unverified Commit 05af7885 authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Fix #45877: Duplicated boolean options in a filter dropdown menu (#45880)

* Fix duplicated boolean options in a dropdown filter

* Add repro for 45877
parent 66afb0d7
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,8 @@ import {
resetTestTable,
resyncDatabase,
openPeopleTable,
createNativeQuestion,
POPOVER_ELEMENT,
} from "e2e/support/helpers";
const {
......@@ -41,6 +43,7 @@ const {
REVIEWS_ID,
PEOPLE,
PEOPLE_ID,
INVOICES,
} = SAMPLE_DATABASE;
describe("issue 9339", () => {
......@@ -1342,3 +1345,59 @@ describe.skip("issue 44435", () => {
});
});
});
// This reproduction can possibly be replaced with the unit test for the `ListField` component in the future
describe("issue 45877", () => {
beforeEach(() => {
restore("setup");
cy.signInAsAdmin();
});
it("should not render selected boolean option twice in a filter dropdown (metabase#45877)", () => {
const questionDetails = {
name: "45877",
native: {
query: "SELECT * FROM INVOICES [[ where {{ expected_invoice }} ]]",
"template-tags": {
expected_invoice: {
id: "3cfb3686-0d13-48db-ab5b-100481a3a830",
dimension: ["field", INVOICES.EXPECTED_INVOICE, null],
name: "expected_invoice",
"display-name": "Expected Invoice",
type: "dimension",
"widget-type": "string/=",
},
},
},
};
createNativeQuestion(questionDetails, { visitQuestion: true });
cy.get("fieldset").should("contain", "Expected Invoice").click();
popover().within(() => {
cy.findByPlaceholderText("Search the list").should("exist");
cy.get("input[type='checkbox']")
.should("have.length", 2)
.each($checkbox => {
cy.wrap($checkbox).should("not.be.checked");
});
cy.findAllByTestId("true-filter-value").should("have.length", 1);
cy.findAllByTestId("false-filter-value").should("have.length", 1).click();
cy.button("Add filter").click();
});
// We don't even have to run the query to reproduce this issue
// so let's not waste time and resources doing so.
cy.get(POPOVER_ELEMENT).should("not.exist");
cy.get("fieldset").should("contain", "false").click();
popover().within(() => {
cy.findAllByTestId("true-filter-value").should("have.length", 1);
cy.findAllByTestId("false-filter-value")
.should("have.length", 1)
.find('input[type="checkbox"]')
.should("be.checked");
});
});
});
......@@ -25,10 +25,8 @@ function createOptionsFromValuesWithoutOptions(
values: RowValue[],
options: Option[],
): Option {
const optionsMap = _.indexBy(options, "0");
return values
.filter(value => typeof value !== "string" || !optionsMap[value])
.map(value => [value]);
const optionsMap = new Map(options.map(option => [option[0], option]));
return values.filter(value => !optionsMap.has(value)).map(value => [value]);
}
export const ListField = ({
......
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