Skip to content

Commit f7cc290

Browse files
authored
Merge pull request #2957 from nburlett/master
Fix date filters in perspective-{select,click} events
2 parents 50245e8 + 41bbc5a commit f7cc290

File tree

6 files changed

+131
-3
lines changed

6 files changed

+131
-3
lines changed

cpp/perspective/src/cpp/server.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,10 @@ ProtoServer::_handle_request(std::uint32_t client_id, Request&& req) {
21412141
std::stringstream ss;
21422142
ss << std::setfill('0') << std::setw(4) << tm.year()
21432143
<< "-" << std::setfill('0') << std::setw(2)
2144-
<< tm.month() << "-" << std::setfill('0')
2144+
// Increment month by 1, as date::month is [1-12] but
2145+
// t_date::month() is [0-11]
2146+
<< tm.month() + 1
2147+
<< "-" << std::setfill('0')
21452148
<< std::setw(2) << tm.day();
21462149
s->set_string(ss.str());
21472150
break;

packages/perspective-viewer-datagrid/test/js/superstore.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { test } from "@finos/perspective-test";
1414
import {
1515
compareContentsToSnapshot,
1616
run_standard_tests,
17+
runPerspectiveEventClickTest,
1718
} from "@finos/perspective-test";
1819

1920
async function getDatagridContents(page) {
@@ -89,3 +90,27 @@ test.describe("Datagrid with superstore data set", () => {
8990
);
9091
});
9192
});
93+
94+
test.describe("Datagrid with superstore arrow data set", () => {
95+
test.beforeEach(async ({ page }) => {
96+
await page.goto(
97+
"/tools/perspective-test/src/html/all-types-small-multi-arrow-test.html"
98+
);
99+
await page.evaluate(async () => {
100+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
101+
await new Promise((x) => setTimeout(x, 10));
102+
}
103+
});
104+
105+
await page.evaluate(async () => {
106+
await document.querySelector("perspective-viewer").restore({
107+
plugin: "Datagrid",
108+
});
109+
});
110+
});
111+
112+
test(
113+
`Filter based on date results in correct perspective-click event`,
114+
runPerspectiveEventClickTest()
115+
);
116+
});
5.81 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import "/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js";
14+
import perspective from "/node_modules/@finos/perspective/dist/cdn/perspective.js";
15+
16+
async function load() {
17+
let resp = await fetch(
18+
"/node_modules/@finos/perspective-test/assets/all_types_small_multi.arrow"
19+
);
20+
21+
const buffer = await resp.arrayBuffer();
22+
const viewer = document.querySelector("perspective-viewer");
23+
const worker = await perspective.worker();
24+
const table = worker.table(buffer);
25+
await viewer.load(table);
26+
const config = {
27+
plugin: "datagrid",
28+
};
29+
await viewer.restore(config);
30+
}
31+
32+
await load();
33+
window.__TEST_PERSPECTIVE_READY__ = true;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
5+
<script type="module" src="/node_modules/@finos/perspective-viewer-d3fc/dist/cdn/perspective-viewer-d3fc.js"></script>
6+
<script type="module" src="/node_modules/@finos/perspective-viewer-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script>
7+
<script type="module" src="/node_modules/@finos/perspective-test/load-viewer-all-types-small-multi-arrow.js"></script>
8+
9+
<link rel="stylesheet" href="/node_modules/@finos/perspective-viewer/dist/css/pro.css" />
10+
<link rel="stylesheet" href="/node_modules/@fontsource/roboto-mono/400.css" />
11+
12+
<style>
13+
perspective-viewer {
14+
position: absolute;
15+
top: 0;
16+
left: 0;
17+
right: 0;
18+
bottom: 0;
19+
font-family: "Roboto Mono" !important;
20+
--preload-fonts: "Roboto Mono:400";
21+
}
22+
23+
perspective-viewer-datagrid::part(regular-table) {
24+
font-family: Arial;
25+
}
26+
</style>
27+
</head>
28+
29+
<body>
30+
<perspective-viewer></perspective-viewer>
31+
</body>
32+
</html>

tools/perspective-test/src/js/simple_viewer_tests.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

13-
import { getSvgContentString, compareContentsToSnapshot } from "./utils.ts";
14-
import { test } from "./index.js";
13+
import {
14+
getSvgContentString,
15+
compareContentsToSnapshot,
16+
shadow_click,
17+
} from "./utils.ts";
18+
import { test, expect } from "./index.js";
1519
import type { PerspectiveViewerConfig } from "@finos/perspective-viewer";
1620

1721
export type ContentExtractor = (page: any) => Promise<string>;
@@ -35,6 +39,37 @@ function runSimpleCompareTest(
3539
};
3640
}
3741

42+
export function runPerspectiveEventClickTest() {
43+
return async ({ page }) => {
44+
const viewerConfig = {
45+
filter: [["date", "<", "2025-01-01"]],
46+
};
47+
await restoreViewer(page, viewerConfig);
48+
49+
const viewer = await page.$("perspective-viewer")!;
50+
const perspectiveClick = viewer.evaluate(
51+
(element) =>
52+
new Promise((resolve) =>
53+
element.addEventListener("perspective-click", (event) => {
54+
// extract the detail
55+
resolve(event.detail);
56+
})
57+
)
58+
);
59+
60+
await shadow_click(
61+
page,
62+
"perspective-viewer-datagrid",
63+
"regular-table > table > tbody > tr:nth-child(1) > td:nth-child(2)"
64+
);
65+
66+
const detail = await perspectiveClick;
67+
const expectedFilter = [["date", "<", "2025-01-01"]];
68+
const resultFilter = detail["config"]["filter"];
69+
expect(resultFilter).toEqual(expectedFilter);
70+
};
71+
}
72+
3873
export function run_standard_tests(
3974
context: string,
4075
extractContent: ContentExtractor

0 commit comments

Comments
 (0)