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

Move handling of the file browser settings to a separate plugin, enable file browser single click navigation #7481

Merged
merged 11 commits into from
Oct 24, 2024
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ The file browser now:

- supports resizing the columns and remembers the column sizes after reloading JupyterLab
- supports uploading folders by drag-and-drop
- supports navigation with a single click (opt-in)
- supports navigation with a single click
- adds a file filter collapsed by default (funnel icon)

![a screenshot showing that it's now possible to resize the file browser columns](https://github.com/user-attachments/assets/b0d9cd0a-2828-43f7-a922-e8b271e5f7fc)

In Jupyter Notebook, the single click navigation is enabled by default. If you would like to disable it to get the same experience as in JupyterLab, go to `Settings → File Browser` and make sure "Navigate files and directories with single click" is unchecked.

### Improved kernel and server interactions

The previous release enabled connecting to external kernels, such as those spawned by a third-party application like Blender. In this release the kernel selector dialog was improved to also show the external kernels.
Expand Down
1 change: 0 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@
"@jupyterlab/filebrowser-extension:file-upload-status",
"@jupyterlab/filebrowser-extension:open-with",
"@jupyterlab/filebrowser-extension:search",
"@jupyterlab/filebrowser-extension:settings",
"@jupyterlab/filebrowser-extension:share-file"
],
"@jupyter-notebook/tree-extension": true,
Expand Down
75 changes: 56 additions & 19 deletions packages/tree-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ const fileActions: JupyterFrontEndPlugin<void> = {
selectionChanged.emit(void 0);
};
});
browser.model.pathChanged.connect(() => {
selectionChanged.emit(void 0);
});

// Create a toolbar item that adds buttons to the file browser toolbar
// to perform actions on the files
Expand All @@ -186,6 +189,58 @@ const fileActions: JupyterFrontEndPlugin<void> = {
},
};

/**
* A plugin to set the default file browser settings.
*/
const fileBrowserSettings: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/tree-extension:settings',
description: 'Set up the default file browser settings',
requires: [IDefaultFileBrowser],
optional: [ISettingRegistry],
autoStart: true,
activate: (
app: JupyterFrontEnd,
browser: IDefaultFileBrowser,
settingRegistry: ISettingRegistry | null
) => {
// Default config for notebook.
// This is a different set of defaults than JupyterLab.
const defaultFileBrowserConfig = {
navigateToCurrentDirectory: false,
singleClickNavigation: true,
showLastModifiedColumn: true,
showFileSizeColumn: true,
showHiddenFiles: false,
showFileCheckboxes: true,
sortNotebooksFirst: true,
showFullPath: false,
};

// Apply defaults on plugin activation
let key: keyof typeof defaultFileBrowserConfig;
for (key in defaultFileBrowserConfig) {
browser[key] = defaultFileBrowserConfig[key];
}

if (settingRegistry) {
void settingRegistry.load(FILE_BROWSER_PLUGIN_ID).then((settings) => {
function onSettingsChanged(settings: ISettingRegistry.ISettings): void {
let key: keyof typeof defaultFileBrowserConfig;
for (key in defaultFileBrowserConfig) {
const value = settings.get(key).user as boolean;
// only set the setting if it is defined by the user
if (value !== undefined) {
browser[key] = value;
}
}
}
settings.changed.connect(onSettingsChanged);
onSettingsChanged(settings);
});
}
},
};

/**
* A plugin to add the file filter toggle command to the palette
*/
Expand Down Expand Up @@ -360,25 +415,6 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
nbTreeWidget.tabBar.addTab(running.title);
}

const settings = settingRegistry.load(FILE_BROWSER_PLUGIN_ID);
Promise.all([settings, app.restored])
.then(([settings]) => {
// Set Notebook 7 defaults if there is no user setting override
[
'showFileCheckboxes',
'showFileSizeColumn',
'sortNotebooksFirst',
'showFullPath',
].forEach((setting) => {
if (settings.user[setting] === undefined) {
void settings.set(setting, true);
}
});
})
.catch((reason: Error) => {
console.error(reason.message);
});

app.shell.add(nbTreeWidget, 'main', { rank: 100 });

// add a separate tab for each setting editor
Expand Down Expand Up @@ -419,6 +455,7 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
const plugins: JupyterFrontEndPlugin<any>[] = [
createNew,
fileActions,
fileBrowserSettings,
fileFilterCommand,
loadPlugins,
openFileBrowser,
Expand Down
2 changes: 2 additions & 0 deletions ui-tests/test/filebrowser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
test('Select one folder', async ({ page, tmpPath }) => {
await page.filebrowser.refresh();

await page.keyboard.down('Control');
await page.getByText('folder1').last().click();

const toolbar = page.getByRole('toolbar');
Expand All @@ -31,12 +32,13 @@
test('Select one file', async ({ page, tmpPath }) => {
await page.filebrowser.refresh();

await page.keyboard.down('Control');
await page.getByText('empty.ipynb').last().click();

const toolbar = page.getByRole('toolbar');

['Rename', 'Delete', 'Open', 'Download', 'Delete'].forEach(async (text) => {
expect(toolbar.getByText(text)).toBeVisible();

Check failure on line 41 in ui-tests/test/filebrowser.spec.ts

View workflow job for this annotation

GitHub Actions / ui-tests (firefox)

[firefox] › test/filebrowser.spec.ts:32:7 › File Browser › Select one file

1) [firefox] › test/filebrowser.spec.ts:32:7 › File Browser › Select one file ──────────────────── Error: expect(locator).toBeVisible() Locator: getByRole('toolbar').getByText('Delete') Expected: visible Received: hidden Call log: - expect.toBeVisible with timeout 5000ms - waiting for getByRole('toolbar').getByText('Delete') 39 | 40 | ['Rename', 'Delete', 'Open', 'Download', 'Delete'].forEach(async (text) => { > 41 | expect(toolbar.getByText(text)).toBeVisible(); | ^ 42 | }); 43 | }); 44 | at forEach (/home/runner/work/notebook/notebook/ui-tests/test/filebrowser.spec.ts:41:39) at /home/runner/work/notebook/notebook/ui-tests/test/filebrowser.spec.ts:40:56
});
});

Expand All @@ -52,7 +54,7 @@

expect(toolbar.getByText('Rename')).toBeHidden();
expect(toolbar.getByText('Open')).toBeHidden();
expect(toolbar.getByText('Delete')).toBeVisible();

Check failure on line 57 in ui-tests/test/filebrowser.spec.ts

View workflow job for this annotation

GitHub Actions / ui-tests (firefox)

[firefox] › test/filebrowser.spec.ts:45:7 › File Browser › Select files and folders

2) [firefox] › test/filebrowser.spec.ts:45:7 › File Browser › Select files and folders ─────────── Error: expect(locator).toBeVisible() Locator: getByRole('toolbar').getByText('Delete') Expected: visible Received: hidden Call log: - expect.toBeVisible with timeout 5000ms - waiting for getByRole('toolbar').getByText('Delete') 55 | expect(toolbar.getByText('Rename')).toBeHidden(); 56 | expect(toolbar.getByText('Open')).toBeHidden(); > 57 | expect(toolbar.getByText('Delete')).toBeVisible(); | ^ 58 | }); 59 | 60 | test('Select files and open', async ({ page, tmpPath }) => { at /home/runner/work/notebook/notebook/ui-tests/test/filebrowser.spec.ts:57:41
});

test('Select files and open', async ({ page, tmpPath }) => {
Expand Down
Loading