Skip to content

Commit 3343c7f

Browse files
author
Jaipreet Singh
committed
Use the new ReactWidget interface from JL1.0
1 parent 1f1ebd1 commit 3343c7f

File tree

1 file changed

+13
-45
lines changed

1 file changed

+13
-45
lines changed

src/components/diff/DiffWidget.tsx

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,13 @@
1-
import { Widget } from '@phosphor/widgets';
21
import * as React from 'react';
3-
import * as ReactDOM from 'react-dom';
42
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
53

64
import { getRefValue, IDiffContext } from './model';
75
import { Diff, isDiffSupported, RenderMimeProvider } from './Diff';
86
import { JupyterFrontEnd } from '@jupyterlab/application';
9-
import { showDialog } from '@jupyterlab/apputils';
7+
import { ReactWidget, showDialog } from '@jupyterlab/apputils';
108
import { PathExt } from '@jupyterlab/coreutils';
119
import { style } from 'typestyle';
1210

13-
export class DiffWidget extends Widget {
14-
private readonly _renderMime: IRenderMimeRegistry;
15-
private readonly _path: string;
16-
private readonly _diffContext: IDiffContext;
17-
18-
constructor(
19-
renderMime: IRenderMimeRegistry,
20-
path: string,
21-
gitContext: IDiffContext
22-
) {
23-
super();
24-
this._renderMime = renderMime;
25-
this._path = path;
26-
this._diffContext = gitContext;
27-
28-
this.title.label = PathExt.basename(path);
29-
this.title.iconClass = style({
30-
backgroundImage: 'var(--jp-icon-diff)'
31-
});
32-
this.title.closable = true;
33-
this.addClass('jp-git-diff-parent-diff-widget');
34-
35-
ReactDOM.render(
36-
<RenderMimeProvider value={this._renderMime}>
37-
<Diff path={this._path} diffContext={this._diffContext} />
38-
</RenderMimeProvider>,
39-
this.node
40-
);
41-
}
42-
43-
onUpdateRequest(): void {
44-
ReactDOM.unmountComponentAtNode(this.node);
45-
ReactDOM.render(
46-
<RenderMimeProvider value={this._renderMime}>
47-
<Diff path={this._path} diffContext={this._diffContext} />
48-
</RenderMimeProvider>,
49-
this.node
50-
);
51-
}
52-
}
53-
5411
/**
5512
* Method to open a main menu panel to show the diff of a given Notebook file.
5613
* If one already exists, just activates the existing one.
@@ -78,8 +35,19 @@ export function openDiffView(
7835
mainAreaItem = mainAreaItems.next();
7936
}
8037
if (!mainAreaItem) {
81-
const nbDiffWidget = new DiffWidget(renderMime, path, diffContext);
38+
const nbDiffWidget = ReactWidget.create(
39+
<RenderMimeProvider value={renderMime}>
40+
<Diff path={path} diffContext={diffContext} />
41+
</RenderMimeProvider>
42+
);
8243
nbDiffWidget.id = id;
44+
nbDiffWidget.title.label = PathExt.basename(path);
45+
nbDiffWidget.title.iconClass = style({
46+
backgroundImage: 'var(--jp-icon-diff)'
47+
});
48+
nbDiffWidget.title.closable = true;
49+
nbDiffWidget.addClass('jp-git-diff-parent-diff-widget');
50+
8351
app.shell.add(nbDiffWidget, 'main');
8452
app.shell.activateById(nbDiffWidget.id);
8553
}

0 commit comments

Comments
 (0)