Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree view enhancement #6588

Merged
merged 16 commits into from
Jan 12, 2023
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
1 change: 1 addition & 0 deletions packages/_metapackage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{ "path": "../lab-extension" },
{ "path": "../notebook-extension" },
{ "path": "../terminal-extension" },
{ "path": "../tree" },
{ "path": "../tree-extension" },
{ "path": "../ui-components" }
]
Expand Down
14 changes: 9 additions & 5 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,22 @@ const pages: JupyterFrontEndPlugin<void> = {
window.open(`${baseUrl}lab`);
}
});
const page = PageConfig.getOption('notebookPage');

app.commands.addCommand(CommandIDs.openTree, {
label: trans.__('Open Files'),
label: trans.__('File Browser'),
execute: () => {
window.open(`${baseUrl}tree`);
if (page === 'tree') {
app.commands.execute('filebrowser:activate');
} else {
window.open(`${baseUrl}tree`);
}
}
});

if (palette) {
[CommandIDs.openLab, CommandIDs.openTree].forEach(command => {
palette.addItem({ command, category: 'View' });
});
palette.addItem({ command: CommandIDs.openLab, category: 'View' });
palette.addItem({ command: CommandIDs.openTree, category: 'View' });
}
}
};
Expand Down
36 changes: 35 additions & 1 deletion packages/tree-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const FILE_BROWSER_FACTORY = 'FileBrowser';
*/
const FILE_BROWSER_PLUGIN_ID = '@jupyterlab/filebrowser-extension:browser';

/**
* The namespace for command IDs.
*/
namespace CommandIDs {
// The command to activate the filebrowser widget in tree view.
export const activate = 'filebrowser:activate';
}

/**
* Plugin to add extra commands to the file browser to create
* new notebooks, files, consoles and terminals
Expand Down Expand Up @@ -94,6 +102,28 @@ const createNew: JupyterFrontEndPlugin<void> = {
}
};

/**
* A plugin to add file browser commands for the tree view.
*/
const openFileBrowser: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/tree-extension:open-file-browser',
requires: [INotebookTree, IFileBrowserFactory],
autoStart: true,
activate: (
app: JupyterFrontEnd,
notebookTree: INotebookTree,
factory: IFileBrowserFactory
) => {
const { commands } = app;
commands.addCommand(CommandIDs.activate, {
execute: () => {
const { defaultBrowser: browser } = factory;
notebookTree.currentWidget = browser;
}
});
}
};

/**
* A plugin to add the file browser widget to an INotebookShell
*/
Expand Down Expand Up @@ -183,5 +213,9 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [createNew, notebookTreeWidget];
const plugins: JupyterFrontEndPlugin<any>[] = [
createNew,
openFileBrowser,
notebookTreeWidget
];
export default plugins;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions ui-tests/test/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ test('should update url when navigating in filebrowser', async ({
const url = new URL(page.url());
expect(url.pathname).toEqual(`/tree/${tmpPath}/${SUBFOLDER}`);
});

test('Should activate file browser tab', async ({ page, tmpPath }) => {
await page.goto(`tree/${tmpPath}`);
await page.click('text="Running"');
await expect(page.locator('#main-panel #jp-running-sessions')).toBeVisible();

await page.menu.clickMenuItem('View>File Browser');
await expect(page.locator('#main-panel #filebrowser')).toBeVisible();
});