Skip to content

Commit a2fcb37

Browse files
authored
Merge pull request #3059 from finos/fix-jlab-renderers
Fix jupyterlab renderers
2 parents c3bacb9 + ae91037 commit a2fcb37

5 files changed

Lines changed: 68 additions & 36 deletions

File tree

packages/perspective-jupyterlab/src/js/psp_widget.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export class PerspectiveWidget extends Widget {
116116
* method) must be called in order for its memory to be reclaimed.
117117
*/
118118

119-
delete() {
120-
this.viewer.delete();
119+
async delete() {
120+
await this.viewer.delete();
121121
}
122122

123123
/**

packages/perspective-jupyterlab/src/js/renderer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const baddialog = () => {
4646
});
4747
};
4848

49-
const WORKER = perspective.worker();
5049
export class PerspectiveDocumentWidget extends DocumentWidget {
5150
constructor(options, type = "csv") {
5251
super({
@@ -102,7 +101,8 @@ export class PerspectiveDocumentWidget extends DocumentWidget {
102101
table.replace(data);
103102
} catch (e) {
104103
// construct new table
105-
const table_promise = WORKER.table(data);
104+
this.worker = await perspective.worker();
105+
const table_promise = this.worker.table(data);
106106

107107
// load data
108108
await this._psp.viewer.load(table_promise);
@@ -151,7 +151,8 @@ export class PerspectiveDocumentWidget extends DocumentWidget {
151151
if (this._monitor) {
152152
this._monitor.dispose();
153153
}
154-
this._psp.delete();
154+
155+
this.worker.terminate();
155156
super.dispose();
156157
}
157158

packages/perspective-jupyterlab/src/less/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ div.PSPContainer perspective-viewer[theme="Pro Light"] {
4949

5050
div.PSPContainer perspective-viewer {
5151
display: block;
52-
height: 98%;
52+
height: 100%;
5353
}

packages/perspective-jupyterlab/test/jupyter/widget.spec.mts renamed to packages/perspective-jupyterlab/test/jupyter/widget.spec.mjs

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,32 @@ const getEditMode = async (viewer) => {
3535
// utils.with_jupyterlab(process.env.__JUPYTERLAB_PORT__, () => {
3636
describe_jupyter(
3737
() => {
38+
test_jupyter(
39+
"Open arrow and csv from file browser",
40+
[],
41+
async ({ page }) => {
42+
await page.locator("#tab-key-1-7").click();
43+
await page
44+
.locator(`.jp-DirListing-item[data-file-type="arrow"]`)
45+
.click({ button: "right" });
46+
47+
await page.hover(`.lm-Menu .lm-Menu-item[data-type="submenu"]`);
48+
await page
49+
.locator(`.lm-Menu-item[data-command="filebrowser:open"]`)
50+
.click();
51+
52+
const num_columns = await page
53+
.locator("regular-table thead tr")
54+
.first()
55+
.evaluate((tr) => tr.childElementCount);
56+
57+
expect(num_columns).toEqual(14);
58+
await expect(
59+
page.locator("regular-table tbody tr"),
60+
).toHaveCount(5);
61+
},
62+
);
63+
3864
// Basics
3965
test_jupyter(
4066
"Loads data",
@@ -51,9 +77,9 @@ describe_jupyter(
5177

5278
expect(num_columns).toEqual(3);
5379
await expect(
54-
page.locator("regular-table tbody tr")
80+
page.locator("regular-table tbody tr"),
5581
).toHaveCount(5);
56-
}
82+
},
5783
);
5884

5985
test_jupyter(
@@ -78,9 +104,9 @@ describe_jupyter(
78104
expect(num_columns).toEqual(3);
79105

80106
await expect(
81-
page.locator("regular-table tbody tr")
107+
page.locator("regular-table tbody tr"),
82108
).toHaveCount(10);
83-
}
109+
},
84110
);
85111

86112
test_jupyter(
@@ -105,15 +131,16 @@ describe_jupyter(
105131
expect(num_columns).toEqual(3);
106132

107133
await expect(
108-
page.locator("regular-table tbody tr")
134+
page.locator("regular-table tbody tr"),
109135
).toHaveCount(5);
110-
}
136+
},
111137
);
112138

113139
test_jupyter(
114140
"Loads AsyncTable",
115141
[
116142
`
143+
import asyncio
117144
server = perspective.Server()
118145
sync_client = server.new_local_client()
119146
sync_client.table({"Income": [5,4,3,2,1], "Expense": [4,3,2,1,1], "Profit": [1,1,1,1,0]}, name="Microstore")
@@ -133,16 +160,17 @@ async_table = await async_client.open_table("Microstore")`,
133160

134161
expect(num_columns).toEqual(3);
135162
await expect(
136-
page.locator("regular-table tbody tr")
163+
page.locator("regular-table tbody tr"),
137164
).toHaveCount(5);
138-
}
165+
},
139166
);
140167

141168
test_jupyter(
142169
"Loads updates to AsyncTable",
143170
[
144171
[
145172
`
173+
import asyncio
146174
server = perspective.Server()
147175
sync_client = server.new_local_client()
148176
sync_table = sync_client.table(arrow_data)
@@ -165,9 +193,9 @@ async_table = await async_client.open_table(sync_table.get_name())`,
165193
expect(num_columns).toEqual(3);
166194

167195
await expect(
168-
page.locator("regular-table tbody tr")
196+
page.locator("regular-table tbody tr"),
169197
).toHaveCount(10);
170-
}
198+
},
171199
);
172200
// Restore
173201

@@ -189,7 +217,7 @@ async_table = await async_client.open_table(sync_table.get_name())`,
189217
});
190218

191219
expect(settings).toEqual(false);
192-
}
220+
},
193221
);
194222

195223
test_jupyter(
@@ -207,7 +235,7 @@ async_table = await async_client.open_table(sync_table.get_name())`,
207235
const viewer = await default_body(page);
208236
const edit_mode = await getEditMode(viewer);
209237
expect(edit_mode).toEqual("EDIT");
210-
}
238+
},
211239
);
212240

213241
test_jupyter(
@@ -228,12 +256,12 @@ async_table = await async_client.open_table(sync_table.get_name())`,
228256

229257
await add_and_execute_cell(
230258
page,
231-
'w.plugin_config = {"edit_mode": "EDIT"}'
259+
'w.plugin_config = {"edit_mode": "EDIT"}',
232260
);
233261

234262
edit_mode = await getEditMode(viewer);
235263
expect(edit_mode).toEqual("EDIT");
236-
}
264+
},
237265
);
238266

239267
test_jupyter(
@@ -255,14 +283,14 @@ async_table = await async_client.open_table(sync_table.get_name())`,
255283
await viewer.evaluate(async (viewer) => {
256284
const edit =
257285
viewer.children[1].shadowRoot.querySelector(
258-
"span#edit_mode"
286+
"span#edit_mode",
259287
);
260288
edit.click();
261289
});
262290

263291
edit_mode = await getEditMode(viewer);
264292
expect(edit_mode).toEqual("EDIT");
265-
}
293+
},
266294
);
267295

268296
test_jupyter(
@@ -328,7 +356,7 @@ w.filter = [["i8", "<", 50]]
328356
w.group_by = ["date"]
329357
w.split_by = ["bool"]
330358
w.sort = [["date", "asc"]]
331-
w.theme = "Pro Dark"`
359+
w.theme = "Pro Dark"`,
332360
);
333361

334362
// grab the config again
@@ -353,7 +381,7 @@ w.theme = "Pro Dark"`
353381
theme: "Pro Dark",
354382
title: null,
355383
});
356-
}
384+
},
357385
);
358386

359387
test_jupyter(
@@ -439,10 +467,10 @@ assert w.plugin_config == {}
439467
assert w.settings == False
440468
assert w.sort == [["date", "asc"]]
441469
assert w.theme == "Pro Dark"
442-
"Passed"`
470+
"Passed"`,
443471
);
444472
expect(error_cells_dont_exist).toBe(true);
445-
}
473+
},
446474
);
447475

448476
test_jupyter(
@@ -460,7 +488,7 @@ assert w.theme == "Pro Dark"
460488
[
461489
`assert w.table.view().to_columns() == {'a': [True, False, True], 'b': ['abc', 'def', 'ghi']}`,
462490
`"Passed"`,
463-
].join("\n")
491+
].join("\n"),
464492
);
465493
expect(error_cells_dont_exist).toBe(true);
466494

@@ -478,11 +506,11 @@ assert w.theme == "Pro Dark"
478506
[
479507
`assert w.table.view().to_columns() == {'a': [False, True, False], 'b': ['abc', 'def', 'ghi']}`,
480508
`"Passed"`,
481-
].join("\n")
509+
].join("\n"),
482510
);
483511

484512
expect(error_cells_dont_exist).toBe(true);
485-
}
513+
},
486514
);
487515

488516
test_jupyter("Restores from saved config", [], async ({ page }) => {
@@ -496,7 +524,7 @@ table = client.table(arrow_data)
496524
w = perspective.widget.PerspectiveWidget(table)
497525
config = w.save()
498526
perpsective.PerspectiveWidget(df, **config)
499-
`
527+
`,
500528
);
501529
expect(errored).toBe(false);
502530
});
@@ -530,7 +558,7 @@ perpsective.PerspectiveWidget(df, **config)
530558

531559
await page.evaluate(async () => {
532560
await document
533-
.querySelector("perspective-viewer")!
561+
.querySelector("perspective-viewer")
534562
.flush();
535563
});
536564
}
@@ -542,9 +570,9 @@ perpsective.PerspectiveWidget(df, **config)
542570

543571
// expect(num_columns).toEqual(3);
544572
await expect(
545-
page.locator("regular-table tbody tr")
573+
page.locator("regular-table tbody tr"),
546574
).toHaveCount(5);
547-
}
575+
},
548576
);
549577

550578
// *************************
@@ -559,12 +587,12 @@ perpsective.PerspectiveWidget(df, **config)
559587
// assert_no_error_in_cell runs add_and_execute_cell internally so only need to check one
560588
const error_cells_dont_exist = await assert_no_error_in_cell(
561589
page,
562-
"raise Exception('anything')"
590+
"raise Exception('anything')",
563591
);
564592
expect(error_cells_dont_exist).toBe(false);
565-
}
593+
},
566594
);
567595
},
568-
{ name: "Simple", root: path.join(__dirname, "..", "..") }
596+
{ name: "Simple", root: path.join(__dirname, "..", "..") },
569597
);
570598
// });

rust/perspective-js/src/ts/wasm/browser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export async function worker(
9191
async () => {
9292
console.debug("Closing WebWorker");
9393
port.close();
94+
if (webworker instanceof Worker) {
95+
webworker.terminate();
96+
}
9497
},
9598
);
9699

0 commit comments

Comments
 (0)