Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ILayoutRestorer } from "@jupyterlab/application";
import { IThemeManager, WidgetTracker } from "@jupyterlab/apputils";
import { IThemeManager, showErrorMessage, WidgetTracker } from "@jupyterlab/apputils";
import { IDefaultDrive } from "@jupyterlab/services";
import { ITranslator } from "@jupyterlab/translation";
import type { JupyterFrontEnd, JupyterFrontEndPlugin } from "@jupyterlab/application";
Expand Down Expand Up @@ -154,24 +154,30 @@ function activateArrowGrid(
app.docRegistry.addWidgetFactory(factory);

factory.widgetCreated.connect(async (_sender, widget) => {
// Track the widget.
void tracker.add(widget);
// Notify the widget tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void tracker.save(widget);
});
try {
// Track the widget.
void tracker.add(widget);
// Notify the widget tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void tracker.save(widget);
});

if (csv_ft) {
widget.title.icon = csv_ft.icon;
widget.title.iconClass = csv_ft.iconClass!;
widget.title.iconLabel = csv_ft.iconLabel!;
if (csv_ft) {
widget.title.icon = csv_ft.icon;
widget.title.iconClass = csv_ft.iconClass!;
widget.title.iconLabel = csv_ft.iconLabel!;
}
await widget.content.ready;
widget.content.style = style;
widget.content.rendererConfig = rendererConfig;
updateThemes();
console.log("JupyterLab extension arbalister is activated!");
} catch (error) {
await showErrorMessage(
trans.__("ArrowGridViewer widget initialization failed"),
error as Error,
);
}
await widget.content.ready;
widget.content.style = style;
widget.content.rendererConfig = rendererConfig;
updateThemes();

console.log("JupyterLab extension arbalister is activated!");
});

const updateThemes = (newTheme?: string | null) => {
Expand All @@ -192,8 +198,15 @@ function activateArrowGrid(
};
if (themeManager) {
themeManager.themeChanged.connect((_, args) => {
const newTheme = args.newValue;
updateThemes(newTheme);
try {
const newTheme = args.newValue;
updateThemes(newTheme);
} catch (error) {
void showErrorMessage(
trans.__("Failed to the viewer according to updated theme"),
error as Error,
);
}
});
}
}
Expand Down
25 changes: 22 additions & 3 deletions src/widget.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Dialog, showDialog } from "@jupyterlab/apputils";
import { ABCWidgetFactory, DocumentWidget } from "@jupyterlab/docregistry";
import { PromiseDelegate } from "@lumino/coreutils";
import { BasicKeyHandler, BasicMouseHandler, DataGrid, TextRenderer } from "@lumino/datagrid";
Expand Down Expand Up @@ -73,9 +74,27 @@ export class ArrowGridViewer extends Panel {
}

private async _updateGrid() {
const model = new ArrowModel({ path: this.path });
await model.ready;
this._grid.dataModel = model;
try {
const model = new ArrowModel({ path: this.path });
await model.ready;
this._grid.dataModel = model;
} catch (error) {
const trans = Dialog.translator.load("jupyterlab");
const buttons = [
Dialog.cancelButton({ label: trans.__("Close") }),
Dialog.okButton({ label: trans.__("Retry") }),
];
const confirm = await showDialog({
title: "Failed to initialized ArrowGridViewer",
body: typeof error === "string" ? error : (error as Error).message,
buttons,
});
const shouldRetry = confirm.button.accept;

if (shouldRetry) {
await this._updateGrid();
}
}
}

private async _updateRenderer(): Promise<void> {
Expand Down
Loading