Skip to content

Commit

Permalink
Handle generic document types in timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 9, 2024
1 parent 0754bc7 commit 42fa676
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
19 changes: 10 additions & 9 deletions packages/docprovider-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,28 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
statusBar: IStatusBar,
drive: ICollaborativeDrive
): Promise<void> => {
function isYDrive(drive: YDrive | ICollaborativeDrive): drive is YDrive {
return 'getProviderForPath' in drive;
}
try {
let sliderItem: Widget | null = null;
let timelineWidget: TimelineWidget | null = null;

const updateTimelineForDocument = async (documentPath: string) => {
if (drive && isYDrive(drive)) {
const updateTimelineForDocument = async (documentPath: string, documentId: string) => {
if (drive) {
// Remove 'RTC:' from document path
documentPath = documentPath.slice(drive.name.length + 1);
// Dispose of the previous timelineWidget if it exists
if (timelineWidget) {
timelineWidget.dispose();
timelineWidget = null;
}

const provider = (await drive.getProviderForPath(
documentPath
const [format, type] = documentId.split(':');
const provider = (drive.providers.get(
`${format}:${type}:${documentPath}`
)) as IForkProvider;
const fullPath = URLExt.join(
app.serviceManager.serverSettings.baseUrl,
DOCUMENT_TIMELINE_URL,
documentPath.split(':')[1]
documentPath
);

timelineWidget = new TimelineWidget(
Expand All @@ -194,7 +194,8 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
timelineWidget = null;
}
if (currentWidget && 'context' in currentWidget) {
await updateTimelineForDocument(currentWidget.context.path);
await currentWidget.context.ready;
await updateTimelineForDocument(currentWidget.context.path, currentWidget.context.model.sharedModel.getState('document_id') as string);
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions packages/docprovider/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DocumentChange, IAwareness, YDocument } from '@jupyter/ydoc';
import { Contents } from '@jupyterlab/services';

import { Token } from '@lumino/coreutils';
import { WebSocketProvider } from './yprovider';

/**
* The collaborative drive.
Expand Down Expand Up @@ -36,6 +37,8 @@ export interface ICollaborativeDrive extends Contents.IDrive {
* SharedModel factory for the YDrive.
*/
readonly sharedModelFactory: ISharedModelFactory;

readonly providers: Map<string, WebSocketProvider>;
}

/**
Expand Down
17 changes: 2 additions & 15 deletions packages/docprovider/src/ydrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,8 @@ export class YDrive extends Drive implements ICollaborativeDrive {
*/
readonly sharedModelFactory: ISharedModelFactory;

async getProviderForPath(path: string): Promise<IForkProvider> {
let key = '';
if (path.split('.')[1] === 'ipynb') {
key = `json:notebook:${path.split(':')[1]}`;
} else if (path.split('.')[1] === 'jcad') {
key = `text:jcad:${path.split(':')[1]}`;
} else {
key = `text:file:${path.split(':')[1]}`;
}

const provider = this._providers.get(key);
if (!provider) {
throw new Error(`No provider found for path: ${path}`);
}
return provider;
get providers(): Map<string, WebSocketProvider> {
return this._providers;
}

/**
Expand Down

0 comments on commit 42fa676

Please sign in to comment.