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

Make the default drive in the Contents Service configurable #16141

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 42 additions & 2 deletions packages/services/src/contents/index.ts
Expand Up @@ -295,6 +295,11 @@ export namespace Contents {
*/
readonly serverSettings: ServerConnection.ISettings;

/**
* Set the default `IDrive` in the manager.
*/
setDefaultDrive(driveName: string): void;

/**
* Add an `IDrive` to the manager.
*/
Expand Down Expand Up @@ -637,8 +642,40 @@ export class ContentsManager implements Contents.IManager {
constructor(options: ContentsManager.IOptions = {}) {
const serverSettings = (this.serverSettings =
options.serverSettings ?? ServerConnection.makeSettings());
this._defaultDrive = options.defaultDrive ?? new Drive({ serverSettings });
this._defaultDrive.fileChanged.connect(this._onFileChanged, this);
// Create a drive for the Jupyter Server REST API.
let contentsDrive = new Drive({ serverSettings, name: 'contents' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default drive name is Default

https://github.com/jupyterlab/jupyterlab/blob/main/packages/services/src/contents/index.ts#L1079

So although it is not a good name if this PR is merged, I would not change it for backward compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

this._additionalDrives.set('contents', contentsDrive);
// If a different drive is given in options, also add it here.
let defaultDriveName = 'contents';
// Set the default drive based on the given options.
if (options.defaultDrive) {
defaultDriveName = options.defaultDrive.name;
this._additionalDrives.set(
options.defaultDrive.name,
options.defaultDrive
);
}
this.setDefaultDrive(defaultDriveName);
}

/**
* Set the default drive of the contents manager. This can be changed
* at any time.
*
* The default drive does not use its drive prefix when displaying
* paths.
*/
setDefaultDrive(driveName: string): void {
let drive = this._additionalDrives.get(driveName);
if (drive) {
// Remove the signal from the previous default drive.
if (this._defaultDrive) {
this._defaultDrive.fileChanged.disconnect(this._onFileChanged);
}
// Set the new Drive.
this._defaultDrive = drive;
this._defaultDrive.fileChanged.connect(this._onFileChanged, this);
}
}

/**
Expand Down Expand Up @@ -1517,6 +1554,9 @@ export namespace ContentsManager {
export interface IOptions {
/**
* The default drive backend for the contents manager.
*
* The default drive means all implicit paths (i.e. no drive prefix)
* will use this drive by default.
*/
defaultDrive?: Contents.IDrive;

Expand Down