Skip to content

Commit 1f1ebd1

Browse files
author
Jaipreet Singh
committed
Migrate changes to JLab1.0 and latest NBDime
* The update to nbdime5.x lost us some styles. This change adds them back and also makes some minor UI tweaks to the collapse/expand button. * Add back conditionally adding the commands since adding the commands more than once leads to errors when the file panel is re-rendered. * Update tests based on the latest changes in the NBDime API.
1 parent 1919468 commit 1f1ebd1

File tree

9 files changed

+191
-96
lines changed

9 files changed

+191
-96
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@jupyterlab/services": "^4.0.0",
4949
"@jupyterlab/terminal": "^1.0.0",
5050
"@phosphor/widgets": "^1.8.0",
51+
"nbdime": "~5.0.1",
5152
"react": "~16.8.4",
5253
"react-dom": "~16.8.4",
5354
"typestyle": "^2.0.1"

src/components/FileList.tsx

Lines changed: 81 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -110,109 +110,115 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
110110
disableFiles: false
111111
};
112112

113-
commands.addCommand(CommandIDs.gitFileOpen, {
114-
label: 'Open',
115-
caption: 'Open selected file',
116-
execute: async () => {
117-
await this.openListedFile(
118-
this.state.contextMenuTypeX,
119-
this.state.contextMenuTypeY,
120-
this.state.contextMenuFile,
121-
this.props.app
122-
);
123-
}
124-
});
113+
if (!commands.hasCommand(CommandIDs.gitFileOpen)) {
114+
commands.addCommand(CommandIDs.gitFileOpen, {
115+
label: 'Open',
116+
caption: 'Open selected file',
117+
execute: async () => {
118+
await this.openListedFile(
119+
this.state.contextMenuTypeX,
120+
this.state.contextMenuTypeY,
121+
this.state.contextMenuFile,
122+
this.props.app
123+
);
124+
}
125+
});
126+
}
125127

126-
commands.addCommand(CommandIDs.gitFileDiffWorking, {
127-
label: 'Diff',
128-
caption: 'Diff selected file',
129-
execute: () => {
130-
openDiffView(
131-
this.state.contextMenuFile,
132-
this.props.app,
133-
{
134-
currentRef: { specialRef: 'WORKING' },
135-
previousRef: { gitRef: 'HEAD' }
136-
},
137-
this.props.renderMime
138-
);
139-
}
140-
});
128+
if (!commands.hasCommand(CommandIDs.gitFileDiffWorking)) {
129+
commands.addCommand(CommandIDs.gitFileDiffWorking, {
130+
label: 'Diff',
131+
caption: 'Diff selected file',
132+
execute: () => {
133+
openDiffView(
134+
this.state.contextMenuFile,
135+
this.props.app,
136+
{
137+
currentRef: { specialRef: 'WORKING' },
138+
previousRef: { gitRef: 'HEAD' }
139+
},
140+
this.props.renderMime
141+
);
142+
}
143+
});
144+
}
141145

142-
commands.addCommand(CommandIDs.gitFileDiffIndex, {
143-
label: 'Diff',
144-
caption: 'Diff selected file',
145-
execute: () => {
146-
openDiffView(
147-
this.state.contextMenuFile,
148-
this.props.app,
149-
{
150-
currentRef: { specialRef: 'INDEX' },
151-
previousRef: { gitRef: 'HEAD' }
152-
},
153-
this.props.renderMime
154-
);
155-
}
156-
});
146+
if (!commands.hasCommand(CommandIDs.gitFileDiffIndex)) {
147+
commands.addCommand(CommandIDs.gitFileDiffIndex, {
148+
label: 'Diff',
149+
caption: 'Diff selected file',
150+
execute: () => {
151+
openDiffView(
152+
this.state.contextMenuFile,
153+
this.props.app,
154+
{
155+
currentRef: { specialRef: 'INDEX' },
156+
previousRef: { gitRef: 'HEAD' }
157+
},
158+
this.props.renderMime
159+
);
160+
}
161+
});
162+
}
157163

158-
commands.addCommand(CommandIDs.gitFileStage, {
159-
label: 'Stage',
160-
caption: 'Stage the changes of selected file',
161-
execute: () => {
162-
try {
164+
if (!commands.hasCommand(CommandIDs.gitFileStage)) {
165+
commands.addCommand(CommandIDs.gitFileStage, {
166+
label: 'Stage',
167+
caption: 'Stage the changes of selected file',
168+
execute: () => {
163169
this.addUnstagedFile(
164170
this.state.contextMenuFile,
165171
this.props.topRepoPath,
166172
this.props.refresh
167173
);
168-
} catch (err) {}
169-
}
170-
});
174+
}
175+
});
176+
}
171177

172-
commands.addCommand(CommandIDs.gitFileTrack, {
173-
label: 'Track',
174-
caption: 'Start tracking selected file',
175-
execute: () => {
176-
try {
178+
if (!commands.hasCommand(CommandIDs.gitFileTrack)) {
179+
commands.addCommand(CommandIDs.gitFileTrack, {
180+
label: 'Track',
181+
caption: 'Start tracking selected file',
182+
execute: () => {
177183
this.addUntrackedFile(
178184
this.state.contextMenuFile,
179185
this.props.topRepoPath,
180186
this.props.refresh
181187
);
182-
} catch (err) {}
183-
}
184-
});
188+
}
189+
});
190+
}
185191

186-
commands.addCommand(CommandIDs.gitFileUnstage, {
187-
label: 'Unstage',
188-
caption: 'Unstage the changes of selected file',
189-
execute: () => {
190-
try {
192+
if (!commands.hasCommand(CommandIDs.gitFileUnstage)) {
193+
commands.addCommand(CommandIDs.gitFileUnstage, {
194+
label: 'Unstage',
195+
caption: 'Unstage the changes of selected file',
196+
execute: () => {
191197
if (this.state.contextMenuTypeX !== 'D') {
192198
this.resetStagedFile(
193199
this.state.contextMenuFile,
194200
this.props.topRepoPath,
195201
this.props.refresh
196202
);
197203
}
198-
} catch (err) {}
199-
}
200-
});
204+
}
205+
});
206+
}
201207

202-
commands.addCommand(CommandIDs.gitFileDiscard, {
203-
label: 'Discard',
204-
caption: 'Discard recent changes of selected file',
205-
execute: () => {
206-
try {
208+
if (!commands.hasCommand(CommandIDs.gitFileDiscard)) {
209+
commands.addCommand(CommandIDs.gitFileDiscard, {
210+
label: 'Discard',
211+
caption: 'Discard recent changes of selected file',
212+
execute: () => {
207213
this.updateSelectedFile(
208214
this.state.contextMenuIndex,
209215
this.state.contextMenuStage
210216
);
211217
this.updateSelectedDiscardFile(this.state.contextMenuIndex);
212218
this.toggleDisableFiles();
213-
} catch (err) {}
214-
}
215-
});
219+
}
220+
});
221+
}
216222

217223
this.state.contextMenuStaged.addItem({ command: CommandIDs.gitFileOpen });
218224
this.state.contextMenuStaged.addItem({
@@ -328,6 +334,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
328334
updateSelectedStage = (stage: string): void => {
329335
this.setState({ selectedStage: stage });
330336
};
337+
331338
/** Open a file in the git listing */
332339
async openListedFile(
333340
typeX: string,

src/components/diff/DiffWidget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
55

66
import { getRefValue, IDiffContext } from './model';
77
import { Diff, isDiffSupported, RenderMimeProvider } from './Diff';
8-
import { JupyterLab } from '@jupyterlab/application';
8+
import { JupyterFrontEnd } from '@jupyterlab/application';
99
import { showDialog } from '@jupyterlab/apputils';
1010
import { PathExt } from '@jupyterlab/coreutils';
1111
import { style } from 'typestyle';
@@ -62,7 +62,7 @@ export class DiffWidget extends Widget {
6262
*/
6363
export function openDiffView(
6464
path: string,
65-
app: JupyterLab,
65+
app: JupyterFrontEnd,
6666
diffContext: IDiffContext,
6767
renderMime: IRenderMimeRegistry
6868
) {
@@ -80,7 +80,7 @@ export function openDiffView(
8080
if (!mainAreaItem) {
8181
const nbDiffWidget = new DiffWidget(renderMime, path, diffContext);
8282
nbDiffWidget.id = id;
83-
app.shell.addToMainArea(nbDiffWidget);
83+
app.shell.add(nbDiffWidget, 'main');
8484
app.shell.activateById(nbDiffWidget.id);
8585
}
8686
} else {

src/components/diff/NbDiff.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ export class NBDiff extends React.Component<IDiffProps, INBDiffState> {
173173

174174
httpGitRequest('/nbdime/api/gitdiff', 'POST', {
175175
file_path: this.props.path,
176-
ref_prev: { git: diffContext.previousRef.gitRef },
177-
ref_curr: currentRefValue
176+
ref_local: { git: diffContext.previousRef.gitRef },
177+
ref_remote: currentRefValue
178178
}).then((response: Response) => {
179179
response
180180
.json()

src/componentsStyle/GitStageStyle.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ export const changeStageButtonStyle = style({
7676

7777
export const discardFileButtonStyle = style({
7878
backgroundImage: 'var(--jp-icon-discard-file)',
79-
marginLeft: '6px'
79+
marginLeft: '6px',
80+
paddingRight: '1px'
8081
});
8182

8283
export const diffFileButtonStyle = style({
8384
backgroundImage: 'var(--jp-icon-diff)',
84-
marginLeft: '6px'
85+
paddingLeft: '0px'
8586
});
8687

8788
export const caretdownImageStyle = style({

style/diff.css

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
background-size: 20px;
7777
background-position: center;
7878
background-repeat: no-repeat;
79-
height: 15px;
79+
height: 10px;
8080
width: 15px;
8181
font-size: var(--jp-ui-font-size1);
8282
line-height: var(--jp-private-toolbar-height);
@@ -87,6 +87,7 @@
8787
text-decoration: none;
8888
transition: background-color 0.1s ease;
8989
margin-left: 5px;
90+
border: transparent;
9091
}
9192

9293
.jp-git-diff-Widget {
@@ -452,3 +453,56 @@
452453
.jp-git-Notebook-diff .jp-Diff-renderedOutput {
453454
min-height: 2em;
454455
}
456+
457+
.jp-git-Notebook-diff .jp-CollapsiblePanel {
458+
border: var(--jp-git-diff-output-border-color) solid 1pt;
459+
}
460+
461+
.jp-git-Notebook-diff button.jp-CollapsiblePanel-header-icon::-moz-focus-inner {
462+
border: none;
463+
}
464+
465+
.jp-git-Notebook-diff .jp-CollapsiblePanel-header-icon-opened {
466+
background-image: var(--jp-icon-caretup);
467+
}
468+
469+
.jp-git-Notebook-diff .jp-CollapsiblePanel-header-icon-closed {
470+
background-image: var(--jp-icon-caretdown);
471+
}
472+
473+
.jp-git-Notebook-diff .jp-CollapsiblePanel-header {
474+
padding-top: .2em;
475+
padding-bottom: .2em;
476+
background-color: var(--jp-git-diff-output-color);
477+
padding-left: 2em;
478+
padding-right: 2em;
479+
color: var(--jp-ui-font-color1);
480+
}
481+
482+
.jp-git-Notebook-diff .jp-CollapsiblePanel-container {
483+
overflow: hidden;
484+
}
485+
486+
.jp-git-Notebook-diff .jp-CollapsiblePanel-slider {
487+
height:100%;
488+
-webkit-transition: -webkit-transform .3s ease, height 0.3s;
489+
-moz-transition: -moz-transform .3s ease, height 0.3s;
490+
-ms-transition: -ms-transform .3s ease, height 0.3s;
491+
transition: transform .3s ease, height 0.3s;
492+
}
493+
494+
.jp-git-Notebook-diff .jp-CollapsiblePanel-opened {
495+
-webkit-transform: translate(0, 0%);
496+
-moz-transform: translate(0, 0%);
497+
-ms-transform: translate(0, 0%);
498+
transform: translate(0, 0%);
499+
height: 100%;
500+
}
501+
502+
.jp-git-Notebook-diff .jp-CollapsiblePanel-closed {
503+
-webkit-transform: translate(0, -100%);
504+
-moz-transform: translate(0, -100%);
505+
-ms-transform: translate(0, -100%);
506+
transform: translate(0, -100%);
507+
height: 0;
508+
}

style/variables.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
--jp-icon-git-pull-disabled: url('./images/git-clone-icon-disabled.svg');
2222
--jp-git-diff-deleted-color: rgba(255, 193, 193, 0.5);
2323
--jp-git-diff-added-color: rgba(201, 243, 194, 0.5);
24+
--jp-git-diff-output-color: rgba(0, 141, 255, 0.3);
25+
--jp-git-diff-output-border-color: rgba(0, 141, 255, 0.7);
2426
}
2527

2628
[data-jp-theme-light='true'] {

tests/test-components/NBDiff.spec.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('NBDiff', () => {
3838
expect(httpGitRequest).toHaveBeenCalled();
3939
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
4040
file_path: '/path/to/File.ipynb',
41-
ref_curr: { special: 'WORKING' },
42-
ref_prev: { git: '83baee' }
41+
ref_remote: { special: 'WORKING' },
42+
ref_local: { git: '83baee' }
4343
});
4444
expect(node.find('.jp-git-diff-error').text()).toContain(
4545
'TEST_ERROR_MESSAGE'
@@ -75,8 +75,8 @@ describe('NBDiff', () => {
7575
expect(httpGitRequest).toHaveBeenCalled();
7676
expect(httpGitRequest).toBeCalledWith('/nbdime/api/gitdiff', 'POST', {
7777
file_path: '/path/to/File.ipynb',
78-
ref_curr: { special: 'WORKING' },
79-
ref_prev: { git: '83baee' }
78+
ref_remote: { special: 'WORKING' },
79+
ref_local: { git: '83baee' }
8080
});
8181
expect(node.find('.jp-git-diff-error').html()).toBeNull();
8282
expect(node.find(NBDiffHeader)).toHaveLength(1);
@@ -99,13 +99,13 @@ function createTestResponse(
9999
trailer: Promise.resolve(Headers as any),
100100
type: 'basic',
101101
url: '/foo/bar',
102-
clone: jest.fn<Response>(),
102+
clone: jest.fn<Response, []>(),
103103
body: null,
104104
bodyUsed: false,
105-
arrayBuffer: jest.fn<Promise<ArrayBuffer>>(),
106-
blob: jest.fn<Promise<Blob>>(),
107-
formData: jest.fn<Promise<FormData>>(),
108-
text: jest.fn<Promise<String>>()
105+
arrayBuffer: jest.fn<Promise<ArrayBuffer>, []>(),
106+
blob: jest.fn<Promise<Blob>, []>(),
107+
formData: jest.fn<Promise<FormData>, []>(),
108+
text: jest.fn<Promise<string>, []>()
109109
};
110110
return Promise.resolve(testResponse);
111111
}

0 commit comments

Comments
 (0)