Skip to content

Commit 682d14d

Browse files
Handle generic document types in timeline (#349)
1 parent 0754bc7 commit 682d14d

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

packages/docprovider-extension/src/filebrowser.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,31 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
147147
statusBar: IStatusBar,
148148
drive: ICollaborativeDrive
149149
): Promise<void> => {
150-
function isYDrive(drive: YDrive | ICollaborativeDrive): drive is YDrive {
151-
return 'getProviderForPath' in drive;
152-
}
153150
try {
154151
let sliderItem: Widget | null = null;
155152
let timelineWidget: TimelineWidget | null = null;
156153

157-
const updateTimelineForDocument = async (documentPath: string) => {
158-
if (drive && isYDrive(drive)) {
154+
const updateTimelineForDocument = async (
155+
documentPath: string,
156+
documentId: string
157+
) => {
158+
if (drive) {
159+
// Remove 'RTC:' from document path
160+
documentPath = documentPath.slice(drive.name.length + 1);
159161
// Dispose of the previous timelineWidget if it exists
160162
if (timelineWidget) {
161163
timelineWidget.dispose();
162164
timelineWidget = null;
163165
}
164166

165-
const provider = (await drive.getProviderForPath(
166-
documentPath
167-
)) as IForkProvider;
167+
const [format, type] = documentId.split(':');
168+
const provider = drive.providers.get(
169+
`${format}:${type}:${documentPath}`
170+
) as IForkProvider;
168171
const fullPath = URLExt.join(
169172
app.serviceManager.serverSettings.baseUrl,
170173
DOCUMENT_TIMELINE_URL,
171-
documentPath.split(':')[1]
174+
documentPath
172175
);
173176

174177
timelineWidget = new TimelineWidget(
@@ -194,7 +197,13 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
194197
timelineWidget = null;
195198
}
196199
if (currentWidget && 'context' in currentWidget) {
197-
await updateTimelineForDocument(currentWidget.context.path);
200+
await currentWidget.context.ready;
201+
await updateTimelineForDocument(
202+
currentWidget.context.path,
203+
currentWidget.context.model.sharedModel.getState(
204+
'document_id'
205+
) as string
206+
);
198207
}
199208
});
200209
}

packages/docprovider/src/tokens.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DocumentChange, IAwareness, YDocument } from '@jupyter/ydoc';
55
import { Contents } from '@jupyterlab/services';
66

77
import { Token } from '@lumino/coreutils';
8+
import { WebSocketProvider } from './yprovider';
89

910
/**
1011
* The collaborative drive.
@@ -36,6 +37,8 @@ export interface ICollaborativeDrive extends Contents.IDrive {
3637
* SharedModel factory for the YDrive.
3738
*/
3839
readonly sharedModelFactory: ISharedModelFactory;
40+
41+
readonly providers: Map<string, WebSocketProvider>;
3942
}
4043

4144
/**

packages/docprovider/src/ydrive.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,8 @@ export class YDrive extends Drive implements ICollaborativeDrive {
6464
*/
6565
readonly sharedModelFactory: ISharedModelFactory;
6666

67-
async getProviderForPath(path: string): Promise<IForkProvider> {
68-
let key = '';
69-
if (path.split('.')[1] === 'ipynb') {
70-
key = `json:notebook:${path.split(':')[1]}`;
71-
} else if (path.split('.')[1] === 'jcad') {
72-
key = `text:jcad:${path.split(':')[1]}`;
73-
} else {
74-
key = `text:file:${path.split(':')[1]}`;
75-
}
76-
77-
const provider = this._providers.get(key);
78-
if (!provider) {
79-
throw new Error(`No provider found for path: ${path}`);
80-
}
81-
return provider;
67+
get providers(): Map<string, WebSocketProvider> {
68+
return this._providers;
8269
}
8370

8471
/**

0 commit comments

Comments
 (0)