Skip to content

Commit

Permalink
Fix in and not in filter in UI (impacts Python)
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Oct 27, 2023
1 parent 3bba225 commit 5b9392a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ impl Component for ConfigSelector {
let mut tokens = current.split(',').collect::<Vec<_>>();
tokens.pop();
tokens.push(&input);
filter[index].2 = FilterTerm::Scalar(Scalar::String(tokens.join(",")));
filter[index].2 = FilterTerm::Array(
tokens
.iter()
.map(|x| Scalar::String(x.trim().to_owned()))
.collect(),
);

let filter = Some(filter);
ViewConfigUpdate {
filter,
Expand Down
58 changes: 58 additions & 0 deletions rust/perspective-viewer/test/js/regressions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,64 @@ test.describe("Regression tests", () => {
]);
});

test("in filter generates correct array-encoded config", async ({
page,
}) => {
await page.evaluate(async () => {
const viewer = document.querySelector("perspective-viewer");
await viewer.restore({
group_by: ["State"],
columns: ["Sales"],
settings: true,
filter: [["State", "in", []]],
});

const filter = viewer.shadowRoot.querySelector(
".pivot-column input[type=text]"
);
filter.value = "C";
const event = new Event("input", {
bubbles: true,
cancelable: true,
});

filter.dispatchEvent(event);
});

const elem = await page.waitForSelector("perspective-dropdown");
await page.evaluate((elem) => {
let node = elem.shadowRoot.querySelector("span:first-of-type");
var clickEvent = document.createEvent("MouseEvents");
clickEvent.initEvent("mousedown", true, true);
node.dispatchEvent(clickEvent);
}, elem);

const config = await page.evaluate(async () => {
const viewer = document.querySelector("perspective-viewer");
return await viewer.save();
});

expect(config).toEqual({
aggregates: {},
columns: ["Sales"],
expressions: [],
filter: [["State", "in", ["California"]]],
group_by: ["State"],
plugin: "Debug",
plugin_config: {},
settings: true,
sort: [],
split_by: [],
theme: "Pro Light",
title: null,
});

const contents = await get_contents(page);
await compareContentsToSnapshot(contents, [
"regressions-in-filter-generates-correct-config.txt",
]);
});

test("Numeric filter input does not trigger render on trailing zeroes", async ({
page,
}) => {
Expand Down
Binary file modified tools/perspective-test/results.tar.gz
Binary file not shown.

0 comments on commit 5b9392a

Please sign in to comment.