Skip to content

Commit 5d6b908

Browse files
authored
Merge pull request #45 from fcollonval/update-jlab3-dep
Update to @jupyterlab/git and nbdime for JLab 3
2 parents 909cad7 + 9fce546 commit 5d6b908

File tree

9 files changed

+141
-50
lines changed

9 files changed

+141
-50
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@jupyterlab/coreutils": "^5.0.3",
5858
"@jupyterlab/docregistry": "^3.0.6",
5959
"@jupyterlab/filebrowser": "^3.0.6",
60-
"@jupyterlab/git": "0.30.0-beta.3 - 0.40.0",
60+
"@jupyterlab/git": "0.30.0 - 0.40.0",
6161
"@jupyterlab/mainmenu": "^3.0.5",
6262
"@jupyterlab/nbformat": "^3.0.3",
6363
"@jupyterlab/rendermime": "^3.0.6",
@@ -70,8 +70,7 @@
7070
"codemirror": "~5.57.0",
7171
"json-source-map": "^0.6.1",
7272
"moment": "^2.24.0",
73-
"nbdime": "^6.1.0-beta.1",
74-
"nbdime-jupyterlab": "^2.1.0-beta.1",
73+
"nbdime": "^6.1.0",
7574
"react": "^17.0.1",
7675
"react-dom": "^17.0.1",
7776
"react-spinners": "^0.5.12"
@@ -133,6 +132,7 @@
133132
"singleton": true
134133
},
135134
"nbdime": {
135+
"bundled": false,
136136
"singleton": true
137137
},
138138
"react": {

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[metadata]
22
long_description = file: README.md
33
long_description_content_type = text/markdown
4-
license-file = LICENSE
5-
description-file = README.md
4+
license_file = LICENSE
5+
description_file = README.md
66
platforms = Linux, Mac OS X, Windows
77
keywords =
88
Interactive
@@ -32,7 +32,7 @@ setup_requires =
3232
wheel
3333
install_requires =
3434
jupyterlab ~=3.0
35-
jupyterlab-git >=0.30.0b3,<0.40.0a0
35+
jupyterlab-git >=0.30.0,<0.40.0a0
3636
packages = find:
3737
include_package_data = True
3838
zip_safe = False

src/components/ActionButton.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { LabIcon } from '@jupyterlab/ui-components';
2+
import * as React from 'react';
3+
4+
/**
5+
* Action button properties interface
6+
*/
7+
export interface IActionButtonProps {
8+
/**
9+
* Is disabled?
10+
*/
11+
disabled?: boolean;
12+
/**
13+
* Icon
14+
*/
15+
icon: LabIcon;
16+
/**
17+
* Button title
18+
*/
19+
title: string;
20+
/**
21+
* On-click event handler
22+
*/
23+
onClick?: (event?: React.MouseEvent<HTMLButtonElement>) => void;
24+
}
25+
26+
/**
27+
* Action button component
28+
*
29+
* @param props Component properties
30+
*/
31+
export function ActionButton(props: IActionButtonProps): JSX.Element {
32+
const { disabled, title, onClick, icon } = props;
33+
return (
34+
<button
35+
disabled={disabled}
36+
className={'jp-PullRequestButton'}
37+
title={title}
38+
onClick={onClick}
39+
>
40+
<icon.react elementPosition="center" tag="span" />
41+
</button>
42+
);
43+
}

src/components/Toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { refreshIcon } from '@jupyterlab/ui-components';
3-
import { ActionButton } from '@jupyterlab/git/lib/components/ActionButton';
3+
import { ActionButton } from './ActionButton';
44

55
/**
66
* Toolbar properties

src/components/browser/PullRequestItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { DocumentRegistry } from '@jupyterlab/docregistry';
2-
import { ActionButton } from '@jupyterlab/git/lib/components/ActionButton';
32
import {
43
caretDownIcon,
54
caretUpIcon,
@@ -10,6 +9,7 @@ import React from 'react';
109
import { BeatLoader } from 'react-spinners';
1110
import { CommandIDs, IFile, IPullRequest } from '../../tokens';
1211
import { requestAPI } from '../../utils';
12+
import { ActionButton } from '../ActionButton';
1313
import { FileItem } from './FileItem';
1414

1515
/**

src/components/diff/NotebookDiff.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
import { NotebookDiff } from '@jupyterlab/git';
99
import { DiffModel } from '@jupyterlab/git/lib/components/diff/model';
10-
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
10+
import { INotebookContent } from '@jupyterlab/nbformat';
1111
import jsonMap from 'json-source-map';
12+
import { IDiffEntry } from 'nbdime/lib/diff/diffentries';
1213
import { CellDiffModel, NotebookDiffModel } from 'nbdime/lib/diff/model';
1314
import { NotebookDiffWidget } from 'nbdime/lib/diff/widget';
1415
import {
@@ -17,8 +18,23 @@ import {
1718
IThread,
1819
IThreadCell
1920
} from '../../tokens';
21+
import { requestAPI } from '../../utils';
2022
import { NotebookCellsDiff } from './NotebookCellsDiff';
2123

24+
/**
25+
* Data return by the ndbime api endpoint
26+
*/
27+
interface INbdimeDiff {
28+
/**
29+
* Base notebook content
30+
*/
31+
base: INotebookContent;
32+
/**
33+
* Diff to obtain challenger from base
34+
*/
35+
diff: IDiffEntry[];
36+
}
37+
2238
export class NotebookPRDiff extends NotebookDiff {
2339
constructor(props: IDiffOptions) {
2440
super(
@@ -160,16 +176,22 @@ export class NotebookPRDiff extends NotebookDiff {
160176
return threadsByChunk;
161177
}
162178

163-
protected createDiffView(
164-
model: NotebookDiffModel,
165-
renderMime: IRenderMimeRegistry
166-
): NotebookDiffWidget {
167-
// return new NotebookDiffWidget(model, renderMime);
179+
protected async createDiffView(
180+
challengerContent: string,
181+
referenceContent: string
182+
): Promise<NotebookDiffWidget> {
183+
const data = await requestAPI<INbdimeDiff>('git/diffnotebook', 'POST', {
184+
currentContent: challengerContent,
185+
previousContent: referenceContent
186+
});
187+
188+
const model = new NotebookDiffModel(data.base, data.diff);
189+
168190
const baseMapping = Private.computeNotebookMapping(
169-
this._props.diff.base.content || '{}'
191+
referenceContent || '{}'
170192
);
171193
const headMapping = Private.computeNotebookMapping(
172-
this._props.diff.head.content || '{}'
194+
challengerContent || '{}'
173195
);
174196
const comments = NotebookPRDiff.mapThreadsOnChunks(
175197
baseMapping,
@@ -183,7 +205,7 @@ export class NotebookPRDiff extends NotebookDiff {
183205
filename: this._props.filename,
184206
model,
185207
comments,
186-
renderMime
208+
renderMime: this._props.renderMime
187209
});
188210
}
189211

src/components/diff/plaintext.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { PlainTextDiff } from '@jupyterlab/git';
33
import { DiffModel } from '@jupyterlab/git/lib/components/diff/model';
44
import { Widget } from '@lumino/widgets';
5-
import { LineWidget } from 'codemirror';
5+
import { LineWidget, MergeView } from 'codemirror';
66
import { IComment, IDiffOptions, IThread } from '../../tokens';
77
import { generateNode } from '../../utils';
88
import { Discussion } from '../discussion/Discussion';
@@ -101,22 +101,17 @@ export class PlainTextPRDiff extends PlainTextDiff {
101101
editor.setGutterMarker(lineIdx, 'jp-PullRequestCommentDecoration', div);
102102
}
103103
}
104-
105104
/**
106105
* Create the Plain Text Diff view
107106
*/
108-
protected async createDiffView(): Promise<void> {
109-
await super.createDiffView();
107+
protected async createDiffView(
108+
challengerContent: string,
109+
referenceContent: string
110+
): Promise<void> {
111+
await super.createDiffView(challengerContent, referenceContent);
110112

111113
if (this._mergeView) {
112114
{
113-
this._mergeView.leftOriginal().setOption('gutters', [
114-
'CodeMirror-linenumbers',
115-
// FIXME without this - the comment decoration does not show up
116-
// But it add a single comment decoration on the first line of each editors
117-
'jp-PullRequestCommentDecoration',
118-
'CodeMirror-patchgutter'
119-
]);
120115
const { from, to } = this._mergeView.leftOriginal().getViewport();
121116
this.updateView(
122117
this._mergeView.leftOriginal(),
@@ -135,13 +130,6 @@ export class PlainTextPRDiff extends PlainTextDiff {
135130
}
136131

137132
{
138-
this._mergeView.editor().setOption('gutters', [
139-
'CodeMirror-linenumbers',
140-
// FIXME without this - the comment decoration does not show up
141-
// But it add a single comment decoration on the first line of each editors
142-
'jp-PullRequestCommentDecoration',
143-
'CodeMirror-patchgutter'
144-
]);
145133
const { from, to } = this._mergeView.editor().getViewport();
146134
this.updateView(this._mergeView.editor(), from, to, 'line');
147135
this._mergeView
@@ -194,6 +182,24 @@ export class PlainTextPRDiff extends PlainTextDiff {
194182
}
195183
}
196184

185+
/**
186+
* Returns default CodeMirror editor options
187+
*
188+
* @returns CodeMirror editor options
189+
*/
190+
protected getDefaultOptions(): Partial<MergeView.MergeViewEditorConfiguration> {
191+
return {
192+
...super.getDefaultOptions(),
193+
gutters: [
194+
'CodeMirror-linenumbers',
195+
// without this - the comment decoration does not show up
196+
// But it add a single comment decoration on the first line of each editors
197+
'jp-PullRequestCommentDecoration',
198+
'CodeMirror-patchgutter'
199+
]
200+
};
201+
}
202+
197203
/**
198204
* Create the widget associated with a discussion
199205
*

style/base.css

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*-----------------------------------------------------------------------------
22
| JupyterLab Pull Requests Style
33
|----------------------------------------------------------------------------*/
4-
@import url('~@jupyterlab/git/style/index.css');
54

65
.jp-PullRequestPanel {
76
height: 100%;
@@ -10,6 +9,26 @@
109
background-color: var(--jp-layout-color0);
1110
}
1211

12+
.jp-PullRequestButton {
13+
flex: 0 0 auto;
14+
background: none;
15+
line-height: 0px;
16+
padding: 0px 4px;
17+
width: 16px;
18+
border: none;
19+
outline: none;
20+
cursor: pointer;
21+
}
22+
23+
.jp-PullRequestButton:active {
24+
transform: scale(1.272019649);
25+
overflow: hidden;
26+
}
27+
28+
.jp-PullRequestButton:disabled {
29+
cursor: default;
30+
}
31+
1332
.jp-PullRequestToolbar {
1433
flex: 0 0 auto;
1534
border-bottom: none;

yarn.lock

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,10 @@
14831483
"@lumino/widgets" "^1.16.1"
14841484
react "^17.0.1"
14851485

1486-
"@jupyterlab/[email protected]-beta.3 - 0.40.0":
1487-
version "0.30.0-beta.3"
1488-
resolved "https://registry.yarnpkg.com/@jupyterlab/git/-/git-0.30.0-beta.3.tgz#ddc9cd29d9a8c1e8ed488e8d0b34fe3babce24c5"
1489-
integrity sha512-jgUWXj2OQGxXTDuUIXbZZgfLF3wUHp8WyTMf4CRHu6kNtek2Uyrp/ScdMiD0dO5yYnkSAN2iiELFlzFfFrEnSw==
1486+
"@jupyterlab/[email protected] - 0.40.0":
1487+
version "0.30.0"
1488+
resolved "https://registry.yarnpkg.com/@jupyterlab/git/-/git-0.30.0.tgz#12b80050283bcabfa09ec2ee2813f93b91c88836"
1489+
integrity sha512-e0TXn8sApwliaUjEVRCVYISft85dJKg7BBdsWY5ghHvjtLjrh26h4Fx9dcDr+Np/Kjrr/i/8gTUUmA/ZBU0kDQ==
14901490
dependencies:
14911491
"@jupyterlab/application" "^3.0.0"
14921492
"@jupyterlab/apputils" "^3.0.0"
@@ -1514,7 +1514,8 @@
15141514
"@material-ui/icons" "^4.5.1"
15151515
"@material-ui/lab" "^4.0.0-alpha.54"
15161516
diff-match-patch "^1.0.4"
1517-
nbdime "^6.1.0-beta.1"
1517+
nbdime "^6.1.0"
1518+
nbdime-jupyterlab "^2.1.0"
15181519
react "^17.0.1"
15191520
react-dom "^17.0.1"
15201521
react-textarea-autosize "^7.1.2"
@@ -6348,10 +6349,10 @@ natural-compare@^1.4.0:
63486349
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
63496350
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
63506351

6351-
6352-
version "2.1.0-beta.1"
6353-
resolved "https://registry.yarnpkg.com/nbdime-jupyterlab/-/nbdime-jupyterlab-2.1.0-beta.1.tgz#9b650bd044e94bec24e8ac80b1f25616fd669851"
6354-
integrity sha512-4QTXnQbSJMbFVnNM35lcrDFLmYF8UCVLa2kUFcEKzsp5gHgQ+zRtxOq0aS4hLI26p394wzAuME24k8bnk2PvaA==
6352+
nbdime-jupyterlab@^2.1.0:
6353+
version "2.1.0"
6354+
resolved "https://registry.yarnpkg.com/nbdime-jupyterlab/-/nbdime-jupyterlab-2.1.0.tgz#3b7ebe2ce65f02038f86ceab4df9f705d315dc16"
6355+
integrity sha512-aZdMumdglw9S0JDVm6WVLOadGQyWOmPetpk8SGN4CEJ5mL9is1siLLkEI4diQWFFzDXzNkkh1KEfgJpmRLIemg==
63556356
dependencies:
63566357
"@jupyterlab/apputils" "^2 || ^3"
63576358
"@jupyterlab/coreutils" "^4 || ^5"
@@ -6364,12 +6365,12 @@ [email protected]:
63646365
"@lumino/coreutils" "^1.3.0"
63656366
"@lumino/disposable" "^1.1.2"
63666367
"@lumino/widgets" "^1.6.0"
6367-
nbdime "^6.1.0-beta.1"
6368+
nbdime "^6.1.0"
63686369

6369-
nbdime@^6.1.0-beta.1:
6370-
version "6.1.0-beta.1"
6371-
resolved "https://registry.yarnpkg.com/nbdime/-/nbdime-6.1.0-beta.1.tgz#3b925f1ef3f028a25ae851e5cd5e7f3c50fc2304"
6372-
integrity sha512-Rrap6tRT1GDT4OZ1dbt3FG9oWA458LvuTKqR0zkdzREg1pGnkidpVshE7xoPsshpCXmRrqvGOQG3lSSygFPnDA==
6370+
nbdime@^6.1.0:
6371+
version "6.1.0"
6372+
resolved "https://registry.yarnpkg.com/nbdime/-/nbdime-6.1.0.tgz#d8d0e89c22ae888d024985405f9bf388c8ebb0d5"
6373+
integrity sha512-bJHS2kF87kswm/5jphl9TCB6HGJcTUf4FViIliLUexZ3Vpmu97Dr2O1t9psHsMWT13wEUgzqHsLwg6EnnU+Fug==
63736374
dependencies:
63746375
"@jupyterlab/codeeditor" "^2 || ^3"
63756376
"@jupyterlab/codemirror" "^2 || ^3"

0 commit comments

Comments
 (0)