Skip to content

Commit fdaef85

Browse files
committed
feat: switch mr overview.
1 parent f7502e3 commit fdaef85

File tree

8 files changed

+29
-78
lines changed

8 files changed

+29
-78
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
"@risingstack/react-easy-state": "^6.3.0",
115115
"got": "^11.7.0",
116116
"keytar": "^7.0.0",
117-
"ky": "^0.24.0",
118117
"nanoid": "^3.1.16",
119118
"react": "^17.0.0",
120119
"react-dom": "^17.0.0"

src/codingServer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class CodingServer {
322322
}
323323
}
324324

325-
public async getMRDetail(iid: number) {
325+
public async getMRDetail(iid: string) {
326326
try {
327327
const repoInfo = this._context.workspaceState.get(`repoInfo`) as IRepoInfo;
328328
if (!repoInfo?.team) {
@@ -339,9 +339,11 @@ export class CodingServer {
339339
},
340340
)
341341
.json();
342+
342343
if (diff.code) {
343344
return Promise.reject(diff);
344345
}
346+
345347
return diff;
346348
} catch (err) {
347349
return Promise.reject(err);

src/extension.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ export async function activate(context: vscode.ExtensionContext) {
4747

4848
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
4949
context.subscriptions.push(
50-
vscode.commands.registerCommand('codingPlugin.showMROverview', (data: IMRWebViewDetail) => {
51-
Panel.createOrShow(context, data);
52-
Panel.currentPanel?.broadcast(`action.UPDATE_CURRENT_MR`, data);
50+
vscode.commands.registerCommand('codingPlugin.showMROverview', async (mr: IMRWebViewDetail) => {
51+
Panel.createOrShow(context);
52+
const resp = await codingSrv.getMRDetail(mr.iid);
53+
mr.data = resp.data.merge_request;
54+
Panel.currentPanel?.broadcast(`action.UPDATE_CURRENT_MR`, {
55+
...mr,
56+
data: resp.data.merge_request,
57+
});
5358
}),
5459
);
5560
context.subscriptions.push(

src/panel.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as vscode from 'vscode';
2-
import * as path from 'path';
32

4-
import { IMRWebViewDetail } from './typings/commonTypes';
53
import { getNonce } from './common/utils';
64

75
export class Panel {
@@ -17,7 +15,7 @@ export class Panel {
1715
private readonly _extensionPath: string;
1816
private _disposables: vscode.Disposable[] = [];
1917

20-
public static createOrShow(context: vscode.ExtensionContext, data: IMRWebViewDetail) {
18+
public static createOrShow(context: vscode.ExtensionContext) {
2119
const { extensionUri, extensionPath } = context;
2220
const column = vscode.window.activeTextEditor
2321
? vscode.window.activeTextEditor.viewColumn
@@ -42,7 +40,7 @@ export class Panel {
4240
},
4341
);
4442

45-
Panel.currentPanel = new Panel(panel, extensionUri, extensionPath, data);
43+
Panel.currentPanel = new Panel(panel, extensionUri, extensionPath);
4644
}
4745

4846
public static revive(
@@ -53,13 +51,13 @@ export class Panel {
5351
Panel.currentPanel = new Panel(panel, extensionUri, extensionPath);
5452
}
5553

56-
private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri, extensionPath: string, mr?: IMRWebViewDetail) {
54+
private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri, extensionPath: string) {
5755
this._panel = panel;
5856
this._extensionUri = extensionUri;
5957
this._extensionPath = extensionPath;
6058

6159
// Set the webview's initial html content
62-
this._update(mr);
60+
this._update();
6361

6462
// Listen for when the panel is disposed
6563
// This happens when the user closes the panel or when the panel is closed programatically
@@ -117,28 +115,28 @@ export class Panel {
117115
}
118116
}
119117

120-
private _update(data?: IMRWebViewDetail) {
118+
private _update() {
121119
const webview = this._panel.webview;
122120

123121
// Vary the webview's content based on where it is located in the editor.
124122
switch (this._panel.viewColumn) {
125123
case vscode.ViewColumn.Two:
126-
this._updateForCat(webview, data);
124+
this._updateForCat(webview);
127125
return;
128126

129127
case vscode.ViewColumn.Three:
130-
this._updateForCat(webview, data);
128+
this._updateForCat(webview);
131129
return;
132130

133131
case vscode.ViewColumn.One:
134132
default:
135-
this._updateForCat(webview, data);
133+
this._updateForCat(webview);
136134
return;
137135
}
138136
}
139137

140-
private _updateForCat(webview: vscode.Webview, data?: IMRWebViewDetail) {
141-
this._panel.title = `Merge Request ${data?.iid || ``}`;
138+
private _updateForCat(webview: vscode.Webview) {
139+
this._panel.title = `Merge Request`;
142140
this._panel.webview.html = this._getHtmlForWebview(webview);
143141
}
144142

@@ -154,7 +152,7 @@ export class Panel {
154152
<title>Merge Request Overview</title>
155153
<meta name="viewport" content="width=device-width, initial-scale=1.0">
156154
<meta http-equiv="Content-Security-Policy"
157-
content="default-src 'unsafe-eval'; style-src vscode-resource: 'unsafe-inline' http: https: data:;; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'unsafe-eval'; connect-src https:">
155+
content="default-src 'none'; style-src vscode-resource: 'unsafe-inline' http: https: data:;; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'unsafe-eval'; connect-src https:">
158156
</head>
159157
<body>
160158
<div id="root"></div>

webviews/App.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@ import React, { useEffect } from 'react';
33
import { view } from '@risingstack/react-easy-state';
44
import appStore from './store/appStore';
55
import { actions } from './store/constants';
6-
import { fetchMRDetail } from './service';
76

87
function App() {
9-
const { currentMR, switchMR, setMRDetail } = appStore;
8+
const { currentMR, updateCurrentMR } = appStore;
109

1110
useEffect(() => {
1211
window.addEventListener(`message`, async (ev) => {
1312
const { type, value } = ev.data;
1413
switch (type) {
1514
case actions.UPDATE_CURRENT_MR: {
16-
switchMR(value);
15+
updateCurrentMR(value);
1716
break;
1817
}
1918
default:
2019
console.log(type, value);
2120
break;
2221
}
2322
});
24-
}, [switchMR]);
23+
}, [updateCurrentMR]);
2524

26-
useEffect(() => {
27-
fetchMRDetail(currentMR.repoInfo, currentMR.iid, currentMR.accessToken).then(r => {
28-
setMRDetail(r.merge_request);
29-
});
30-
}, [currentMR.iid]);
25+
if (!currentMR.iid) {
26+
return <div>Loading...</div>
27+
}
3128

3229
return (
3330
<>

webviews/service.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

webviews/store/appStore.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { store } from '@risingstack/react-easy-state';
22
import { IMRWebViewDetail } from '../../src/typings/commonTypes';
3-
import { IMRDetail } from '../../src/typings/respResult';
43

54
const appStore = store({
65
currentMR: {} as IMRWebViewDetail,
7-
switchMR(data: IMRWebViewDetail) {
6+
updateCurrentMR(data: IMRWebViewDetail) {
87
appStore.currentMR = data;
98
},
10-
setMRDetail(data: IMRDetail) {
11-
appStore.currentMR.data = data;
12-
}
139
});
1410

1511
export default appStore;

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,11 +4161,6 @@ kind-of@^6.0.0, kind-of@^6.0.2:
41614161
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
41624162
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==
41634163

4164-
ky@^0.24.0:
4165-
version "0.24.0"
4166-
resolved "https://registry.yarnpkg.com/ky/-/ky-0.24.0.tgz#337e534a7f47c12476988eef3cb968daef318349"
4167-
integrity sha512-/vpuQguwV30jErrqLpoaU/YJAFALrUkqqWLILnSoBOj5/O/LKzro/pPNtxbLgY6m4w5XNM6YZ3v7/or8qLlFuw==
4168-
41694164
lazy-cache@^2.0.1:
41704165
version "2.0.2"
41714166
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-2.0.2.tgz#b9190a4f913354694840859f8a8f7084d8822264"

0 commit comments

Comments
 (0)