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

Provide the YDrive as the default drive #365

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,11 @@ docs/source/changelog.md
!.yarn/versions
packages/docprovider/junit.xml
.jupyter_ystore.db

# Jupyter
Untitled*

# To easily link against unreleased JupyterLab packages
# TODO: remove?
.yalc
yalc.lock
2 changes: 2 additions & 0 deletions packages/docprovider-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@jupyterlab/fileeditor": "^4.2.0",
"@jupyterlab/logconsole": "^4.2.0",
"@jupyterlab/notebook": "^4.2.0",
"@jupyterlab/services": "file:.yalc/@jupyterlab/services",
"@jupyterlab/settingregistry": "^4.2.0",
"@jupyterlab/translation": "^4.2.0",
"@lumino/commands": "^2.1.0",
Expand Down Expand Up @@ -89,6 +90,7 @@
"extension": true,
"outputDir": "../../projects/jupyter-docprovider/jupyter_docprovider/labextension",
"disabledExtensions": [
"@jupyterlab/application-extension:default-drive",
"@jupyterlab/filebrowser-extension:defaultFileBrowser",
"@jupyterlab/notebook-extension:cell-executor"
],
Expand Down
48 changes: 33 additions & 15 deletions packages/docprovider-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ import {
} from '@jupyter/docprovider';
import { Awareness } from 'y-protocols/awareness';
import { URLExt } from '@jupyterlab/coreutils';
import {
IDefaultDrive,
IUserManager,
ServiceManagerPlugin,
User
} from '@jupyterlab/services';

/**
* The command IDs used by the file browser plugin.
Expand All @@ -50,21 +56,33 @@ const DOCUMENT_TIMELINE_URL = 'api/collaboration/timeline';
/**
* The default collaborative drive provider.
*/
export const drive: JupyterFrontEndPlugin<ICollaborativeDrive> = {
export const drive: ServiceManagerPlugin<YDrive> = {
id: '@jupyter/docprovider-extension:drive',
autoStart: true,
description: 'The default collaborative drive provider',
provides: ICollaborativeDrive,
requires: [ITranslator],
optional: [IGlobalAwareness],
provides: IDefaultDrive,
requires: [IUserManager],
activate: (_: null, user: User.IManager): YDrive => {
const drive = new YDrive(user);
return drive;
}
};

export const defaults: JupyterFrontEndPlugin<void> = {
id: '@jupyter/docprovider-extension:defaults',
autoStart: true,
requires: [IDefaultDrive],
optional: [IGlobalAwareness, ITranslator],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
globalAwareness: Awareness | null
): ICollaborativeDrive => {
const trans = translator.load('jupyter_collaboration');
const drive = new YDrive(app.serviceManager.user, trans, globalAwareness);
app.serviceManager.contents.addDrive(drive);
return drive;
ydrive: YDrive,
globalAwareness: Awareness | null,
translator: ITranslator | null
): void => {
ydrive.translator = (translator ?? nullTranslator).load('jupyterlab');
if (globalAwareness) {
ydrive.globalAwareness = globalAwareness;
}
Comment on lines +82 to +85
Copy link
Member Author

Choose a reason for hiding this comment

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

Because the service manager plugins are activated first and their app is still null during the first phase, we extract setting the translator and globalAwareness to a separate plugin, so it is activated as a regular plugin.

}
};

Expand All @@ -76,7 +94,7 @@ export const yfile: JupyterFrontEndPlugin<void> = {
description:
"Plugin to register the shared model factory for the content type 'file'",
autoStart: true,
requires: [ICollaborativeDrive],
requires: [IDefaultDrive],
optional: [],
activate: (app: JupyterFrontEnd, drive: ICollaborativeDrive): void => {
const yFileFactory = () => {
Expand All @@ -94,7 +112,7 @@ export const ynotebook: JupyterFrontEndPlugin<void> = {
description:
"Plugin to register the shared model factory for the content type 'notebook'",
autoStart: true,
requires: [ICollaborativeDrive],
requires: [IDefaultDrive],
optional: [ISettingRegistry],
activate: (
app: JupyterFrontEnd,
Expand Down Expand Up @@ -141,7 +159,7 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
id: '@jupyter/docprovider-extension:statusBarTimeline',
description: 'Plugin to add a timeline slider to the status bar',
autoStart: true,
requires: [IStatusBar, ICollaborativeDrive],
requires: [IStatusBar, IDefaultDrive],
activate: async (
app: JupyterFrontEnd,
statusBar: IStatusBar,
Expand Down Expand Up @@ -238,7 +256,7 @@ export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
id: '@jupyter/docprovider-extension:defaultFileBrowser',
description: 'The default file browser factory provider',
provides: IDefaultFileBrowser,
requires: [ICollaborativeDrive, IFileBrowserFactory],
requires: [IDefaultDrive, IFileBrowserFactory],
optional: [IRouter, JupyterFrontEnd.ITreeResolver, ILabShell, ITranslator],
activate: async (
app: JupyterFrontEnd,
Expand Down
6 changes: 1 addition & 5 deletions packages/docprovider-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* @module collaboration-extension
*/

import { JupyterFrontEndPlugin } from '@jupyterlab/application';

import {
drive,
yfile,
Expand All @@ -20,7 +18,7 @@ import { notebookCellExecutor } from './executor';
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
export default [
drive,
yfile,
ynotebook,
Expand All @@ -29,5 +27,3 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
notebookCellExecutor,
statusBarTimeline
];

export default plugins;
4 changes: 3 additions & 1 deletion packages/docprovider-extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
"rootDir": "src",
// TODO: remove, needed because of the local linking of packages
"skipLibCheck": true
},
"include": ["src/*"]
}
18 changes: 13 additions & 5 deletions packages/docprovider/src/ydrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class YDrive extends Drive implements ICollaborativeDrive {
*/
constructor(
user: User.IManager,
translator: TranslationBundle,
globalAwareness: Awareness | null
translator?: TranslationBundle,
globalAwareness?: Awareness
) {
super({ name: 'RTC' });
super();
this._user = user;
this._trans = translator;
this._globalAwareness = globalAwareness;
Expand All @@ -68,6 +68,14 @@ export class YDrive extends Drive implements ICollaborativeDrive {
return this._providers;
}

set translator(translator: TranslationBundle) {
this._trans = translator;
}

set globalAwareness(awareness: Awareness) {
this._globalAwareness = awareness;
}

/**
* Dispose of the resources held by the manager.
*/
Expand Down Expand Up @@ -241,9 +249,9 @@ export class YDrive extends Drive implements ICollaborativeDrive {
};

private _user: User.IManager;
private _trans: TranslationBundle;
private _trans: TranslationBundle | undefined;
private _providers: Map<string, WebSocketProvider>;
private _globalAwareness: Awareness | null;
private _globalAwareness: Awareness | undefined;
private _ydriveFileChanged = new Signal<this, Contents.IChangedArgs>(this);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/docprovider/src/yprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { showErrorMessage, Dialog } from '@jupyterlab/apputils';
import { User } from '@jupyterlab/services';
import { TranslationBundle } from '@jupyterlab/translation';
import { nullTranslator, TranslationBundle } from '@jupyterlab/translation';

import { PromiseDelegate } from '@lumino/coreutils';
import { IDisposable } from '@lumino/disposable';
Expand Down Expand Up @@ -51,7 +51,7 @@ export class WebSocketProvider implements IDocumentProvider, IForkProvider {
this._sharedModel = options.model;
this._awareness = options.model.awareness;
this._yWebsocketProvider = null;
this._trans = options.translator;
this._trans = options.translator ?? nullTranslator.load('jupyterlab');

const user = options.user;

Expand Down Expand Up @@ -234,6 +234,6 @@ export namespace WebSocketProvider {
/**
* The jupyterlab translator
*/
translator: TranslationBundle;
translator?: TranslationBundle;
}
}
Loading
Loading