Skip to content

Commit da920f7

Browse files
committed
Fix compatibility issues with jlab 1.0
1 parent ace5c70 commit da920f7

File tree

4 files changed

+70
-75
lines changed

4 files changed

+70
-75
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@parente/jupyterlab-quickopen",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Quickly open a file in JupyterLab by part of its name",
55
"keywords": [
66
"jupyter",
@@ -31,17 +31,17 @@
3131
"watch": "tsc -w"
3232
},
3333
"dependencies": {
34-
"@jupyterlab/application": "^0.19.1",
35-
"@jupyterlab/apputils": "^0.19.1",
36-
"@jupyterlab/coreutils": "^2.2.1",
37-
"@jupyterlab/docmanager": "^0.19.1",
38-
"@jupyterlab/services": "^3.2.1",
39-
"@phosphor/messaging": "^1.2.2",
40-
"@phosphor/widgets": "^1.6.0"
34+
"@jupyterlab/application": "^1.0.0",
35+
"@jupyterlab/apputils": "^1.0.0",
36+
"@jupyterlab/coreutils": "^3.0.0",
37+
"@jupyterlab/docmanager": "^1.0.0",
38+
"@jupyterlab/services": "^4.0.0",
39+
"@phosphor/messaging": "^1.2.3",
40+
"@phosphor/widgets": "^1.8.1"
4141
},
4242
"devDependencies": {
4343
"rimraf": "^2.6.1",
44-
"typescript": "~3.1.1"
44+
"typescript": "~3.5.2"
4545
},
4646
"jupyterlab": {
4747
"extension": true,

schema/plugin.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"jupyter.lab.setting-icon-class": "jp-FaIcon fa fa-search",
3-
"jupyter.lab.setting-icon-label": "Quick Open",
4-
"title": "Quick Open",
5-
"description": "Quick open panel settings",
6-
"properties": {
7-
"excludes": {
8-
"title": "Exclude Patterns",
9-
"description": "File and directory patterns to exclude from the list",
10-
"type": "array",
11-
"items": { "type": "string" },
12-
"default": ["node_modules", "__pycache__"]
13-
}
14-
},
15-
"additionalProperties": false,
16-
"type": "object"
17-
}
2+
"jupyter.lab.setting-icon-class": "jp-SearchIcon",
3+
"jupyter.lab.setting-icon-label": "Quick Open",
4+
"title": "Quick Open",
5+
"description": "Quick open panel settings",
6+
"properties": {
7+
"excludes": {
8+
"title": "Exclude Patterns",
9+
"description": "File and directory patterns to exclude from the list",
10+
"type": "array",
11+
"items": { "type": "string" },
12+
"default": ["node_modules", "__pycache__"]
13+
}
14+
},
15+
"additionalProperties": false,
16+
"type": "object"
17+
}

src/index.ts

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
1-
import {
2-
JupyterLab, JupyterLabPlugin
3-
} from '@jupyterlab/application';
4-
import { ICommandPalette } from '@jupyterlab/apputils';
5-
import { ISettingRegistry, URLExt, PathExt } from '@jupyterlab/coreutils';
6-
import { IDocumentManager } from '@jupyterlab/docmanager';
7-
import { ServerConnection } from '@jupyterlab/services';
8-
import { CommandRegistry } from '@phosphor/commands';
9-
import { JSONObject } from '@phosphor/coreutils';
10-
import { Message } from '@phosphor/messaging';
11-
import { ISignal, Signal } from '@phosphor/signaling';
12-
import { CommandPalette } from '@phosphor/widgets';
1+
import { ILabShell, JupyterFrontEnd, JupyterFrontEndPlugin } from "@jupyterlab/application";
2+
import { ICommandPalette } from "@jupyterlab/apputils";
3+
import { ISettingRegistry, URLExt, PathExt } from "@jupyterlab/coreutils";
4+
import { IDocumentManager } from "@jupyterlab/docmanager";
5+
import { ServerConnection } from "@jupyterlab/services";
6+
import { CommandRegistry } from "@phosphor/commands";
7+
import { ReadonlyJSONObject } from "@phosphor/coreutils";
8+
import { Message } from "@phosphor/messaging";
9+
import { ISignal, Signal } from "@phosphor/signaling";
10+
import { CommandPalette } from "@phosphor/widgets";
1311
import "../style/index.css";
1412

1513
/** Structure of the JSON response from the server */
1614
interface QuickOpenResponse {
17-
readonly contents: { [key: string]: string[] },
18-
readonly scanSeconds: number,
15+
readonly contents: { [key: string]: string[] };
16+
readonly scanSeconds: number;
1917
}
2018

21-
2219
/** Makes a HTTP request for the server-side quick open scan */
2320
async function fetchContents(excludes: string[]): Promise<QuickOpenResponse> {
24-
const query = excludes.map(exclude => {
25-
return 'excludes='+encodeURIComponent(exclude);
26-
}).join('&');
21+
const query = excludes
22+
.map(exclude => {
23+
return "excludes=" + encodeURIComponent(exclude);
24+
})
25+
.join("&");
2726

2827
const settings = ServerConnection.makeSettings();
29-
const fullUrl = URLExt.join(settings.baseUrl, '/api/quickopen') + '?' + query;
30-
const response = await ServerConnection.makeRequest(fullUrl, {method: 'GET'}, settings);
28+
const fullUrl = URLExt.join(settings.baseUrl, "/api/quickopen") + "?" + query;
29+
const response = await ServerConnection.makeRequest(fullUrl, { method: "GET" }, settings);
3130
if (response.status !== 200) {
3231
throw new ServerConnection.ResponseError(response);
3332
}
3433
return await response.json();
3534
}
3635

37-
3836
/**
3937
* Shows files nested under directories in the root notebooks directory
4038
* configured on the server.
4139
*/
4240
class QuickOpenWidget extends CommandPalette {
4341
private _pathSelected = new Signal<this, string>(this);
44-
private _settings: JSONObject;
42+
private _settings: ReadonlyJSONObject;
4543

4644
constructor(options: CommandPalette.IOptions) {
4745
super(options);
4846

49-
this.id = 'jupyterlab-quickopen';
50-
this.title.iconClass = 'jp-SideBar-tabIcon jp-FaIcon fa fa-search';
51-
this.title.caption = 'Quick Open';
47+
this.id = "jupyterlab-quickopen";
48+
this.title.iconClass = "jp-SideBar-tabIcon jp-SearchIcon";
49+
this.title.caption = "Quick Open";
5250
}
5351

5452
/** Signal when a selected path is activated. */
@@ -57,7 +55,7 @@ class QuickOpenWidget extends CommandPalette {
5755
}
5856

5957
/** Current extension settings */
60-
set settings(settings: JSONObject) {
58+
set settings(settings: ReadonlyJSONObject) {
6159
this._settings = settings;
6260
}
6361

@@ -73,11 +71,11 @@ class QuickOpenWidget extends CommandPalette {
7371
// Remove all paths from the view
7472
this.clearItems();
7573

76-
for(let category in response.contents) {
77-
for(let fn of response.contents[category]) {
74+
for (let category in response.contents) {
75+
for (let fn of response.contents[category]) {
7876
// Creates commands that are relative file paths on the server
7977
let command = `${category}/${fn}`;
80-
if(!this.commands.hasCommand(command)) {
78+
if (!this.commands.hasCommand(command)) {
8179
// Only add the command to the registry if it does not yet exist
8280
// TODO: Track disposables and remove
8381
this.commands.addCommand(command, {
@@ -93,24 +91,23 @@ class QuickOpenWidget extends CommandPalette {
9391
}
9492
}
9593
}
96-
9794
}
9895

99-
10096
/**
10197
* Initialization data for the jupyterlab-quickopen extension.
10298
*/
103-
const extension: JupyterLabPlugin<void> = {
104-
id: '@parente/jupyterlab-quickopen:plugin',
99+
const extension: JupyterFrontEndPlugin<void> = {
100+
id: "@parente/jupyterlab-quickopen:plugin",
105101
autoStart: true,
106-
requires: [ICommandPalette, IDocumentManager, ISettingRegistry],
102+
requires: [ICommandPalette, IDocumentManager, ILabShell, ISettingRegistry],
107103
activate: async (
108-
app: JupyterLab,
104+
app: JupyterFrontEnd,
109105
palette: ICommandPalette,
110106
docManager: IDocumentManager,
111-
settingRegistry: ISettingRegistry) => {
112-
113-
window['docManager'] = docManager;
107+
labShell: ILabShell,
108+
settingRegistry: ISettingRegistry
109+
) => {
110+
window["docManager"] = docManager;
114111

115112
console.log(`Activated extension: ${extension.id}`);
116113
const commands: CommandRegistry = new CommandRegistry();
@@ -120,29 +117,29 @@ const extension: JupyterLabPlugin<void> = {
120117
// Listen for path selection signals and show the selected files in the
121118
// appropriate editor/viewer
122119
widget.pathSelected.connect((sender: QuickOpenWidget, path: string) => {
123-
app.shell.collapseLeft();
120+
labShell.collapseLeft();
124121
docManager.openOrReveal(PathExt.normalize(path));
125122
});
126123

127124
// Listen for setting changes and apply them to the widget
128125
widget.settings = settings.composite;
129126
settings.changed.connect((settings: ISettingRegistry.ISettings) => {
130127
widget.settings = settings.composite;
131-
})
128+
});
132129

133130
// Add a command to activate the quickopen sidebar so that the user can
134131
// find it in the command palette, assign a hotkey, etc.
135-
const command: string = 'quickopen:activate';
132+
const command: string = "quickopen:activate";
136133
app.commands.addCommand(command, {
137-
label: 'Quick Open',
134+
label: "Quick Open",
138135
execute: () => {
139-
app.shell.activateById(widget.id);
136+
labShell.activateById(widget.id);
140137
}
141138
});
142-
palette.addItem({command, category: 'File Operations'});
139+
palette.addItem({ command, category: "File Operations" });
143140

144141
// Add the quickopen widget as a left sidebar
145-
app.shell.addToLeftArea(widget, { rank: 1000 });
142+
labShell.add(widget, "left", { rank: 1000 });
146143
}
147144
};
148145

style/index.css

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.jp-FaIcon {
2-
font-size: 20px;
3-
color: #777;
4-
margin: auto;
5-
}
1+
.jp-SearchIcon {
2+
background-image: var(--jp-icon-search);
3+
}

0 commit comments

Comments
 (0)