Skip to content

Commit 8a4b27a

Browse files
authored
Merge pull request #1 from Zsailer/remove-old-diffs
Remove old diffs when a new diff is created
2 parents d597445 + dc5cfab commit 8a4b27a

File tree

10 files changed

+75
-77
lines changed

10 files changed

+75
-77
lines changed

.github/workflows/check-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
uses: actions/checkout@v4
1818
- name: Base Setup
1919
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
20+
- name: Install typing_extension for Python 3.12
21+
shell: bash
22+
run: pip install typing_extensions
2023
- name: Check Release
2124
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2
2225
with:

.github/workflows/prep-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
contents: write
3131
steps:
3232
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
33-
33+
- name: Install typing_extension for Python 3.12
34+
shell: bash
35+
run: pip install typing_extensions
3436
- name: Prep Release
3537
id: prep-release
3638
uses: jupyter-server/jupyter_releaser/.github/actions/prep-release@v2

.github/workflows/publish-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ jobs:
2020
id-token: write
2121
steps:
2222
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
23-
23+
- name: Install typing_extension for Python 3.12
24+
shell: bash
25+
run: pip install typing_extensions
2426
- uses: actions/create-github-app-token@v1
2527
id: app-token
2628
with:

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
## Contributing
32

43
### Development install

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@jupyterlab/services": "^7.0.0",
6464
"@jupyterlab/ui-components": "^4.0.0",
6565
"@lumino/widgets": "^2.0.0",
66-
"jupyterlab-cell-input-footer": "^0.2.0",
66+
"jupyterlab-cell-input-footer": "^0.3.0",
6767
"nbdime": "^7.0.1"
6868
},
6969
"devDependencies": {

src/command.ts

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,95 @@
1-
import {
2-
ICellFooterTracker,
3-
} from 'jupyterlab-cell-input-footer';
1+
import { ICellFooterTracker } from 'jupyterlab-cell-input-footer';
42
import { IDiffEntry } from 'nbdime/lib/diff/diffentries';
53
import { createPatchStringDiffModel } from 'nbdime/lib/diff/model';
64
import { MergeView } from 'nbdime/lib/common/mergeview';
7-
import {
8-
ToolbarButton,
9-
} from '@jupyterlab/ui-components';
10-
import {
11-
requestAPI
12-
} from './handler';
5+
import { ToolbarButton } from '@jupyterlab/ui-components';
6+
import { requestAPI } from './handler';
137

148
export namespace ShowDiff {
15-
169
export interface ICommandArgs {
17-
cell_id?: string,
18-
original_source: string,
19-
diff: IDiffEntry[]
10+
cell_id?: string;
11+
original_source: string;
12+
diff: IDiffEntry[];
2013
}
2114

2215
export interface IFetchDiff {
23-
original_source: string,
24-
new_source: string
16+
original_source: string;
17+
new_source: string;
2518
}
2619
}
2720

28-
2921
/**
3022
* Adds a Diff UX underneath a JupyterLab cell.
31-
*
32-
* @param data
33-
* @param cellFooterTracker
23+
*
24+
* @param data
25+
* @param cellFooterTracker
3426
*/
35-
export function showCellDiff(data: ShowDiff.ICommandArgs, cellFooterTracker: ICellFooterTracker) {
36-
let diff = createPatchStringDiffModel(
37-
data["original_source"],
38-
data["diff"]
39-
)
40-
41-
let mergeView: MergeView;
42-
mergeView = new MergeView({ remote: diff });
43-
mergeView.addClass("nbdime-root");
44-
mergeView.addClass("jp-Notebook-diff");
27+
export function showCellDiff(
28+
data: ShowDiff.ICommandArgs,
29+
cellFooterTracker: ICellFooterTracker
30+
) {
31+
const diff = createPatchStringDiffModel(
32+
data['original_source'],
33+
data['diff']
34+
);
35+
36+
const mergeView = new MergeView({ remote: diff });
37+
//
38+
mergeView.addClass('jp-cell-diff');
39+
// Add the classes below to pick up the styling from nbdime.
40+
mergeView.addClass('nbdime-root');
41+
mergeView.addClass('jp-Notebook-diff');
4542
mergeView.hide();
4643

47-
let footer = cellFooterTracker.getFooter(data.cell_id);
44+
const footer = cellFooterTracker.getFooter(data.cell_id);
45+
// Try removing any old widget that exists.
46+
try {
47+
footer?.removeWidget('jp-cell-diff');
48+
} finally {
49+
// Do Nothing
50+
}
51+
4852
footer?.addWidget(mergeView);
4953

5054
if (footer?.isHidden) {
5155
footer.show();
5256
footer.update();
5357
}
54-
footer?.addItemOnLeft(
58+
footer?.addToolbarItemOnLeft(
5559
'compare',
5660
new ToolbarButton({
5761
// icon: wandIcon,
58-
label: "Compare changes",
62+
label: 'Compare changes',
5963
enabled: true,
60-
onClick: () => {
64+
onClick: () => {
6165
if (mergeView.isHidden) {
62-
mergeView.show()
66+
mergeView.show();
6367
return;
6468
}
65-
mergeView.hide()
69+
mergeView.hide();
6670
}
6771
})
6872
);
6973
}
7074

71-
72-
export async function fetchDiff(data: ShowDiff.IFetchDiff): Promise<ShowDiff.ICommandArgs> {
75+
export async function fetchDiff(
76+
data: ShowDiff.IFetchDiff
77+
): Promise<ShowDiff.ICommandArgs> {
7378
return await requestAPI('api/celldiff');
7479
}
7580

76-
7781
/**
7882
* Adds a diff to the Cell Footer
79-
*
83+
*
8084
*/
8185
export function showCellDiffCommand(cellFooterTracker: ICellFooterTracker) {
8286
return (args: any) => {
83-
let data: ShowDiff.ICommandArgs = (args as any);
84-
let cellId = data["cell_id"];
87+
const data: ShowDiff.ICommandArgs = args as any;
88+
const cellId = data['cell_id'];
8589
if (cellId) {
86-
87-
if (data && data["original_source"] && data["diff"]) {
88-
89-
showCellDiff(data, cellFooterTracker)
90+
if (data && data['original_source'] && data['diff']) {
91+
showCellDiff(data, cellFooterTracker);
9092
}
9193
}
92-
}
94+
};
9395
}
94-

src/handler.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ export async function requestAPI<T>(
1515
): Promise<T> {
1616
// Make request to Jupyter API
1717
const settings = ServerConnection.makeSettings();
18-
const requestUrl = URLExt.join(
19-
settings.baseUrl,
20-
endPoint
21-
);
18+
const requestUrl = URLExt.join(settings.baseUrl, endPoint);
2219

2320
let response: Response;
2421
try {
@@ -42,4 +39,4 @@ export async function requestAPI<T>(
4239
}
4340

4441
return data;
45-
}
42+
}

src/index.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import {
33
JupyterFrontEndPlugin
44
} from '@jupyterlab/application';
55

6-
import {
7-
showCellDiffCommand
8-
} from './command';
6+
import { showCellDiffCommand } from './command';
97

10-
import {
11-
ICellFooterTracker
12-
} from 'jupyterlab-cell-input-footer';
8+
import { ICellFooterTracker } from 'jupyterlab-cell-input-footer';
139

1410
/**
1511
* A JupyterLab plugin providing a command for displaying a diff below a cell.
@@ -19,18 +15,15 @@ const showDiff: JupyterFrontEndPlugin<void> = {
1915
requires: [ICellFooterTracker],
2016
autoStart: true,
2117
activate: async (
22-
app: JupyterFrontEnd,
23-
cellFooterTracker: ICellFooterTracker,
18+
app: JupyterFrontEnd,
19+
cellFooterTracker: ICellFooterTracker
2420
) => {
25-
console.log("Jupyterlab extension - show cell diff.")
21+
console.log('Jupyterlab extension - show cell diff.');
2622
await app.serviceManager.ready;
2723

28-
app.commands.addCommand(
29-
'show-diff',
30-
{
31-
execute: showCellDiffCommand(cellFooterTracker)
32-
}
33-
)
24+
app.commands.addCommand('show-diff', {
25+
execute: showCellDiffCommand(cellFooterTracker)
26+
});
3427
}
3528
};
3629

style/base.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
.jp-cellfooter .cm-merge-2pane {
88
display: grid;
9-
padding: 0px;
9+
padding: 0;
10+
1011
/* editor | gap | editor */
1112
grid-template-columns: 49% 2% 49%;
1213
grid-auto-rows: minmax(18px, auto);

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3727,7 +3727,7 @@ __metadata:
37273727
eslint: ^8.36.0
37283728
eslint-config-prettier: ^8.8.0
37293729
eslint-plugin-prettier: ^5.0.0
3730-
jupyterlab-cell-input-footer: ^0.2.0
3730+
jupyterlab-cell-input-footer: ^0.3.0
37313731
mkdirp: ^1.0.3
37323732
nbdime: ^7.0.1
37333733
npm-run-all2: ^7.0.1
@@ -3745,13 +3745,13 @@ __metadata:
37453745
languageName: unknown
37463746
linkType: soft
37473747

3748-
"jupyterlab-cell-input-footer@npm:^0.2.0":
3749-
version: 0.2.0
3750-
resolution: "jupyterlab-cell-input-footer@npm:0.2.0"
3748+
"jupyterlab-cell-input-footer@npm:^0.3.0":
3749+
version: 0.3.0
3750+
resolution: "jupyterlab-cell-input-footer@npm:0.3.0"
37513751
dependencies:
37523752
"@jupyterlab/services": ^7.0.0
37533753
"@lumino/coreutils": ^2.1.2
3754-
checksum: b298f6ba525668ce18c25c1e1bd5c1f515d2c76f9611092b88e1ae2769e2966784455c4d7e80f10061a8482d8c938264af15436faf0234bada101fa0a42d62ef
3754+
checksum: 88e8a420022a9228a09271f7b7e5ddc15f2bab9f9cf4e11541364a4060d8907ebdee2174efe0ecbbbdfa56d649fda25380e7a0f9d6dbe4d3486b3c0ab2e55a4c
37553755
languageName: node
37563756
linkType: hard
37573757

0 commit comments

Comments
 (0)