Skip to content

Commit a9d1e58

Browse files
authored
Merge pull request #384 from jaipreet-s/nbdiff1
Visual diff for Notebook files
2 parents 1f6a016 + 3343c7f commit a9d1e58

34 files changed

+1580
-134
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/FileItem.tsx

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { JupyterFrontEnd } from '@jupyterlab/application';
33
import {
44
changeStageButtonStyle,
55
changeStageButtonLeftStyle,
6-
discardFileButtonStyle
6+
discardFileButtonStyle,
7+
diffFileButtonStyle
78
} from '../componentsStyle/GitStageStyle';
89

910
import {
@@ -17,7 +18,6 @@ import {
1718
selectedFileChangedLabelStyle,
1819
fileChangedLabelBrandStyle,
1920
fileChangedLabelInfoStyle,
20-
discardWarningStyle,
2121
fileButtonStyle,
2222
fileGitButtonStyle,
2323
discardFileButtonSelectedStyle,
@@ -29,6 +29,10 @@ import { classes } from 'typestyle';
2929
import * as React from 'react';
3030

3131
import { showDialog, Dialog } from '@jupyterlab/apputils';
32+
import { ISpecialRef } from './diff/model';
33+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
34+
import { isDiffSupported } from './diff/Diff';
35+
import { openDiffView } from './diff/DiffWidget';
3236

3337
export interface IFileItemProps {
3438
topRepoPath: string;
@@ -55,6 +59,7 @@ export interface IFileItemProps {
5559
disableFile: boolean;
5660
toggleDisableFiles: Function;
5761
sideBarExpanded: boolean;
62+
renderMime: IRenderMimeRegistry;
5863
}
5964

6065
export class FileItem extends React.Component<IFileItemProps, {}> {
@@ -181,6 +186,15 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
181186
}
182187
}
183188

189+
getDiffFileIconClass() {
190+
return classes(
191+
fileButtonStyle,
192+
changeStageButtonStyle,
193+
fileGitButtonStyle,
194+
diffFileButtonStyle
195+
);
196+
}
197+
184198
getDiscardFileIconClass() {
185199
if (this.showDiscardWarning()) {
186200
return classes(
@@ -206,10 +220,6 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
206220
}
207221
}
208222

209-
getDiscardWarningClass() {
210-
return discardWarningStyle;
211-
}
212-
213223
/**
214224
* Callback method discarding unstanged changes for selected file.
215225
* It shows modal asking for confirmation and when confirmed make
@@ -236,6 +246,7 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
236246
this.props.updateSelectedDiscardFile(-1);
237247
});
238248
}
249+
239250
render() {
240251
return (
241252
<div
@@ -283,16 +294,49 @@ export class FileItem extends React.Component<IFileItemProps, {}> {
283294
{this.getFileChangedLabel(this.props.file.y)}
284295
</span>
285296
{this.props.stage === 'Changed' && (
286-
<button
287-
className={`jp-Git-button ${this.getDiscardFileIconClass()}`}
288-
title={'Discard this change'}
289-
onClick={() => {
290-
this.discardSelectedFileChanges();
291-
}}
292-
/>
297+
<React.Fragment>
298+
<button
299+
className={`jp-Git-button ${this.getDiscardFileIconClass()}`}
300+
title={'Discard this change'}
301+
onClick={() => {
302+
this.discardSelectedFileChanges();
303+
}}
304+
/>
305+
{isDiffSupported(this.props.file.to) &&
306+
this.diffButton({ specialRef: 'WORKING' })}
307+
</React.Fragment>
293308
)}
309+
{this.props.stage === 'Staged' &&
310+
isDiffSupported(this.props.file.to) &&
311+
this.diffButton({ specialRef: 'INDEX' })}
294312
</span>
295313
</div>
296314
);
297315
}
316+
317+
/**
318+
* Creates a button element which is used to request diff from within the
319+
* Git panel.
320+
*
321+
* @param currentRef the ref to diff against the git 'HEAD' ref
322+
*/
323+
private diffButton(currentRef: ISpecialRef): JSX.Element {
324+
return (
325+
<button
326+
className={`jp-Git-button ${this.getDiffFileIconClass()}`}
327+
title={'Diff this file'}
328+
onClick={() => {
329+
openDiffView(
330+
this.props.file.to,
331+
this.props.app,
332+
{
333+
previousRef: { gitRef: 'HEAD' },
334+
currentRef: { specialRef: currentRef.specialRef }
335+
},
336+
this.props.renderMime
337+
);
338+
}}
339+
/>
340+
);
341+
}
298342
}

0 commit comments

Comments
 (0)