Skip to content

Commit

Permalink
Fix the handling of the file browser configuration (jupyterlab#16870)
Browse files Browse the repository at this point in the history
* Fix setting of the file browser defaults

* Move handling of the file browser settings to a separate plugin

* add docstring

* rename plugin

* add description

* handle no settingRegistry

* fix settings

* keep same logic as before

* keep previous assignment

* Update Playwright Snapshots

* Update Playwright Snapshots

* revert partial snapshot update

* update example snapshots

* more snapshot update

* simplify

* Update packages/filebrowser-extension/src/index.ts

Co-authored-by: Michał Krassowski <[email protected]>

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michał Krassowski <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 48691c6 commit d6f97bd
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 41 deletions.
Binary file modified examples/app/example.spec.ts-snapshots/example-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/federated/example.spec.ts-snapshots/example-linux.png
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"@jupyterlab/extensionmanager-extension:plugin": "Adds the extension manager plugin.",
"@jupyterlab/filebrowser-extension:factory": "Provides the file browser factory.",
"@jupyterlab/filebrowser-extension:default-file-browser": "Provides the default file browser",
"@jupyterlab/filebrowser-extension:browser": "Set up the default file browser (commands, settings,...).",
"@jupyterlab/filebrowser-extension:browser": "Set up the default file browser commands",
"@jupyterlab/filebrowser-extension:settings": "Set up the default file browser settings",
"@jupyterlab/filebrowser-extension:share-file": "Adds the \"Copy Shareable Link\" command; useful for JupyterHub deployment for example.",
"@jupyterlab/filebrowser-extension:file-upload-status": "Adds a file upload status widget.",
"@jupyterlab/filebrowser-extension:download": "Adds the download file commands. Disabling this plugin will NOT disable downloading files from the server, if the user enters the appropriate download URLs.",
Expand Down
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 49 additions & 40 deletions packages/filebrowser-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const namespace = 'filebrowser';
*/
const browser: JupyterFrontEndPlugin<IFileBrowserCommands> = {
id: FILE_BROWSER_PLUGIN_ID,
description: 'Set up the default file browser (commands, settings,...).',
description: 'Set up the default file browser commands and state restoration',
requires: [IDefaultFileBrowser, IFileBrowserFactory, ITranslator],
optional: [
ILayoutRestorer,
Expand Down Expand Up @@ -213,52 +213,60 @@ const browser: JupyterFrontEndPlugin<IFileBrowserCommands> = {
treePathUpdater(args.newValue);
});
}

if (settingRegistry) {
void settingRegistry.load(FILE_BROWSER_PLUGIN_ID).then(settings => {
/**
* File browser configuration.
*/
const fileBrowserConfig = {
navigateToCurrentDirectory: false,
singleClickNavigation: false,
showLastModifiedColumn: true,
showFileSizeColumn: false,
showHiddenFiles: false,
showFileCheckboxes: false,
sortNotebooksFirst: false,
showFullPath: false
};
const fileBrowserModelConfig = {
filterDirectories: true
};

function onSettingsChanged(
settings: ISettingRegistry.ISettings
): void {
let key: keyof typeof fileBrowserConfig;
for (key in fileBrowserConfig) {
const value = settings.get(key).composite as boolean;
fileBrowserConfig[key] = value;
browser[key] = value;
}

const value = settings.get('filterDirectories')
.composite as boolean;
fileBrowserModelConfig.filterDirectories = value;
browser.model.filterDirectories = value;
}
settings.changed.connect(onSettingsChanged);
onSettingsChanged(settings);
});
}
});
return {
openPath: CommandIDs.openPath
};
}
};

/**
* Handle the file browser settings taking into account user defined settings.
*/
const browserSettings: JupyterFrontEndPlugin<void> = {
id: '@jupyterlab/filebrowser-extension:settings',
description: 'Set up the default file browser settings',
requires: [IDefaultFileBrowser],
optional: [ISettingRegistry],
autoStart: true,
activate: (
app: JupyterFrontEnd,
browser: IDefaultFileBrowser,
settingRegistry: ISettingRegistry | null
) => {
if (settingRegistry) {
void settingRegistry.load(FILE_BROWSER_PLUGIN_ID).then(settings => {
/**
* File browser default configuration.
*/
const defaultFileBrowserConfig = {
navigateToCurrentDirectory: false,
singleClickNavigation: false,
showLastModifiedColumn: true,
showFileSizeColumn: false,
showHiddenFiles: false,
showFileCheckboxes: false,
sortNotebooksFirst: false,
showFullPath: false
};

function onSettingsChanged(settings: ISettingRegistry.ISettings): void {
let key: keyof typeof defaultFileBrowserConfig;
for (key in defaultFileBrowserConfig) {
const value = settings.get(key).composite as boolean;
browser[key] = value;
}

const value = settings.get('filterDirectories').composite as boolean;
browser.model.filterDirectories = value;
}
settings.changed.connect(onSettingsChanged);
onSettingsChanged(settings);
});
}
}
};

/**
* The default file browser factory provider.
*/
Expand Down Expand Up @@ -1377,6 +1385,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
factory,
defaultFileBrowser,
browser,
browserSettings,
shareFile,
fileUploadStatus,
downloadPlugin,
Expand Down

0 comments on commit d6f97bd

Please sign in to comment.