Skip to content

Commit a0b3a80

Browse files
authored
Tree view enhancement (#6588)
* Opens by default the newly created tab in tree view * Adds a command to open the file browser when in tree view, which also fixes the broken menu entry 'file Browser' in view * (1) Remove the menu entry 'Open Files' in tree view, which was opening a new browser tab with the same contents, and was like a duplication of 'File Browser' entry, and (2) rename the menu entry 'Open Files' to 'File Browser' for consistency * Add test on 'File Browser' menu entry * Fix pre-commit * Fix test on File Browser menu entry * update snapshots of view menu * Do not activate newly created tree tab by default * Do not add 'openTree' command if it already exists (meaning that the current page contains a filebrowser plugin) * Wait for the file browser commands from JupyterLab to be fully created before create a new one * File Browser menu entry execution depends on the current page ('tree' or other) * Add the dependency to @jupyter-notebook/tree in application-extension * Fix typo * Remove dependency to tree in application-extension * Clean unused dependency * Delete a remaining comment
1 parent 69bc21f commit a0b3a80

File tree

6 files changed

+54
-6
lines changed

6 files changed

+54
-6
lines changed

packages/_metapackage/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{ "path": "../lab-extension" },
1616
{ "path": "../notebook-extension" },
1717
{ "path": "../terminal-extension" },
18+
{ "path": "../tree" },
1819
{ "path": "../tree-extension" },
1920
{ "path": "../ui-components" }
2021
]

packages/application-extension/src/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,22 @@ const pages: JupyterFrontEndPlugin<void> = {
262262
window.open(`${baseUrl}lab`);
263263
}
264264
});
265+
const page = PageConfig.getOption('notebookPage');
265266

266267
app.commands.addCommand(CommandIDs.openTree, {
267-
label: trans.__('Open Files'),
268+
label: trans.__('File Browser'),
268269
execute: () => {
269-
window.open(`${baseUrl}tree`);
270+
if (page === 'tree') {
271+
app.commands.execute('filebrowser:activate');
272+
} else {
273+
window.open(`${baseUrl}tree`);
274+
}
270275
}
271276
});
272277

273278
if (palette) {
274-
[CommandIDs.openLab, CommandIDs.openTree].forEach(command => {
275-
palette.addItem({ command, category: 'View' });
276-
});
279+
palette.addItem({ command: CommandIDs.openLab, category: 'View' });
280+
palette.addItem({ command: CommandIDs.openTree, category: 'View' });
277281
}
278282
}
279283
};

packages/tree-extension/src/index.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const FILE_BROWSER_FACTORY = 'FileBrowser';
4444
*/
4545
const FILE_BROWSER_PLUGIN_ID = '@jupyterlab/filebrowser-extension:browser';
4646

47+
/**
48+
* The namespace for command IDs.
49+
*/
50+
namespace CommandIDs {
51+
// The command to activate the filebrowser widget in tree view.
52+
export const activate = 'filebrowser:activate';
53+
}
54+
4755
/**
4856
* Plugin to add extra commands to the file browser to create
4957
* new notebooks, files, consoles and terminals
@@ -94,6 +102,28 @@ const createNew: JupyterFrontEndPlugin<void> = {
94102
}
95103
};
96104

105+
/**
106+
* A plugin to add file browser commands for the tree view.
107+
*/
108+
const openFileBrowser: JupyterFrontEndPlugin<void> = {
109+
id: '@jupyter-notebook/tree-extension:open-file-browser',
110+
requires: [INotebookTree, IFileBrowserFactory],
111+
autoStart: true,
112+
activate: (
113+
app: JupyterFrontEnd,
114+
notebookTree: INotebookTree,
115+
factory: IFileBrowserFactory
116+
) => {
117+
const { commands } = app;
118+
commands.addCommand(CommandIDs.activate, {
119+
execute: () => {
120+
const { defaultBrowser: browser } = factory;
121+
notebookTree.currentWidget = browser;
122+
}
123+
});
124+
}
125+
};
126+
97127
/**
98128
* A plugin to add the file browser widget to an INotebookShell
99129
*/
@@ -183,5 +213,9 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
183213
/**
184214
* Export the plugins as default.
185215
*/
186-
const plugins: JupyterFrontEndPlugin<any>[] = [createNew, notebookTreeWidget];
216+
const plugins: JupyterFrontEndPlugin<any>[] = [
217+
createNew,
218+
openFileBrowser,
219+
notebookTreeWidget
220+
];
187221
export default plugins;
Loading
Loading

ui-tests/test/tree.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ test('should update url when navigating in filebrowser', async ({
3636
const url = new URL(page.url());
3737
expect(url.pathname).toEqual(`/tree/${tmpPath}/${SUBFOLDER}`);
3838
});
39+
40+
test('Should activate file browser tab', async ({ page, tmpPath }) => {
41+
await page.goto(`tree/${tmpPath}`);
42+
await page.click('text="Running"');
43+
await expect(page.locator('#main-panel #jp-running-sessions')).toBeVisible();
44+
45+
await page.menu.clickMenuItem('View>File Browser');
46+
await expect(page.locator('#main-panel #filebrowser')).toBeVisible();
47+
});

0 commit comments

Comments
 (0)