Skip to content

Commit b20cb15

Browse files
authored
Simplify REST debug webview (#1487)
1 parent 1cfa9ab commit b20cb15

File tree

1 file changed

+11
-77
lines changed

1 file changed

+11
-77
lines changed

src/commands/restDebugPanel.ts

+11-77
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import axios from "axios";
22
import * as httpsModule from "https";
3-
43
import * as vscode from "vscode";
54
import { AtelierAPI } from "../api";
6-
import { cspAppsForUri, handleError } from "../utils";
5+
import { handleError } from "../utils";
76
import { iscIcon } from "../extension";
87

98
interface WebviewMessage {
@@ -83,24 +82,6 @@ export class RESTDebugPanel {
8382
return;
8483
}
8584

86-
// Build the list of all non-CSP web apps
87-
const cspWebApps: string[] = cspAppsForUri(openEditor.document.uri);
88-
const allWebApps: string[] | null = await api
89-
.actionQuery("CALL %CSP.Apps_CSPAppList()", [])
90-
.then((data) => data.result.content.map((obj) => obj.AppUrl))
91-
.catch((error) => {
92-
handleError(error, "Failed to fetch the list of web applications from the server.");
93-
return null;
94-
});
95-
if (allWebApps == null) {
96-
return;
97-
}
98-
const restWebApps = allWebApps.filter((app) => !cspWebApps.includes(app));
99-
if (restWebApps.length == 0) {
100-
vscode.window.showErrorMessage("No REST web applications are configured in the server's namespace.", "Dismiss");
101-
return;
102-
}
103-
10485
if (this.currentPanel !== undefined) {
10586
// Can only have one panel open at once
10687
if (!this.currentPanel._panel.visible) {
@@ -133,10 +114,10 @@ export class RESTDebugPanel {
133114
panel.iconPath = iscIcon;
134115

135116
this._file = openEditor.document.uri;
136-
this.currentPanel = new RESTDebugPanel(panel, webviewFolderUri, api, restWebApps);
117+
this.currentPanel = new RESTDebugPanel(panel, webviewFolderUri, api);
137118
}
138119

139-
private constructor(panel: vscode.WebviewPanel, webviewFolderUri: vscode.Uri, api: AtelierAPI, webApps: string[]) {
120+
private constructor(panel: vscode.WebviewPanel, webviewFolderUri: vscode.Uri, api: AtelierAPI) {
140121
this._panel = panel;
141122
const serverInfo = `${api.config.https ? "https" : "http"}://${api.config.host}:${api.config.port}${
142123
api.config.pathPrefix
@@ -153,12 +134,7 @@ export class RESTDebugPanel {
153134
vscode.Uri.joinPath(webviewFolderUri, "elements-1.6.3.js")
154135
)}"></script>
155136
<title>${RESTDebugPanel._viewTitle}</title>
156-
<style>
157-
.path-grid {
158-
display: grid;
159-
grid-template-columns: 1fr 20fr;
160-
column-gap: 0.5rem;
161-
}
137+
<style>
162138
.component-container > * {
163139
margin: 0.5rem 0;
164140
}
@@ -168,15 +144,6 @@ export class RESTDebugPanel {
168144
vscode-tabs {
169145
display: contents;
170146
}
171-
.path-grid-container {
172-
display: flex;
173-
flex-direction: row;
174-
align-items: flex-start;
175-
justify-content: flex-start;
176-
}
177-
#webApp {
178-
max-width: 45vw;
179-
}
180147
#button {
181148
margin-top: 0.5rem;
182149
}
@@ -198,15 +165,8 @@ export class RESTDebugPanel {
198165
<vscode-tab-header id="bodyTab">BODY</vscode-tab-header>
199166
<vscode-tab-panel id="methodPathView">
200167
<section class="component-container">
201-
<p>
202-
Select a method for this request, then select the web application
203-
to use from the dropdown and enter the rest of the path in the input field
204-
next to the dropdown.
205-
</p>
206-
<p>
207-
The connection information of the server definition
208-
is shown for clarity but it cannot be edited.
209-
</p>
168+
<p>Select a method for this request, then enter the path in the bottom input field.</p>
169+
<p>The connection information of the server definition is shown, but it cannot be edited.</p>
210170
<vscode-radio-group id="method" name="method">
211171
<vscode-radio value="GET" name="method" checked>GET</vscode-radio>
212172
<vscode-radio value="POST" name="method">POST</vscode-radio>
@@ -217,14 +177,7 @@ export class RESTDebugPanel {
217177
<vscode-radio value="OPTIONS" name="method">OPTIONS</vscode-radio>
218178
</vscode-radio-group>
219179
<vscode-textfield readonly id="serverInfo"></vscode-textfield>
220-
<section class="path-grid">
221-
<section class="path-grid-container">
222-
<vscode-single-select id="webApp" name="webApp" position="below"></vscode-single-select>
223-
</section>
224-
<section class="path-grid-container">
225-
<vscode-textfield id="path" name="path" placeholder="/path" pattern="^/.*$" required></vscode-textfield>
226-
</section>
227-
</section>
180+
<vscode-textfield id="path" name="path" placeholder="/path" pattern="^/.*$" required></vscode-textfield>
228181
</section>
229182
</vscode-tab-panel>
230183
<vscode-tab-panel id="headersView">
@@ -271,13 +224,12 @@ export class RESTDebugPanel {
271224
const bodyType = document.getElementById("bodyType");
272225
const bodyContent = document.getElementById("bodyContent");
273226
const button = document.getElementById("button");
274-
const webApp = document.getElementById("webApp");
275-
const formFields = [method, serverInfo, path, headersText, paramsText, bodyType, bodyContent, webApp];
227+
const formFields = [method, serverInfo, path, headersText, paramsText, bodyType, bodyContent];
276228
const sendData = (submitted) => {
277229
const data = Object.fromEntries(new FormData(form));
278230
if (
279231
Object.keys(data).length == (formFields.length - 1) &&
280-
data.webApp != "" && data.method != "" && data.bodyType != "" &&
232+
data.method != "" && data.bodyType != "" &&
281233
(!submitted || (submitted && path.checkValidity()))
282234
) {
283235
vscode.postMessage({
@@ -290,24 +242,7 @@ export class RESTDebugPanel {
290242
window.onmessage = (event) => {
291243
const data = event.data, currentVals = new FormData(form);
292244
formFields.forEach((field) => {
293-
if (field.id == "webApp" && webApp.children.length == 0) {
294-
// Create options and set the initial value
295-
const initIdx = data.webApps.findIndex((e) => e == data.webApp) ?? 0;
296-
data.webApps.forEach((webAppStr, idx) => {
297-
const option = document.createElement("vscode-option");
298-
option.innerText = webAppStr;
299-
option.setAttribute("value",webAppStr);
300-
if (idx == initIdx) {
301-
option.selected = true;
302-
}
303-
webApp.appendChild(option);
304-
});
305-
// Update width of dropdown
306-
const longest = data.webApps.reduce((a,b) => a.length > b.length ? a : b);
307-
const context = document.createElement("canvas").getContext("2d");
308-
context.font = window.getComputedStyle(webApp,null).getPropertyValue("font");
309-
webApp.style.width = Math.ceil(context.measureText(longest).width*(4/3)) + "px";
310-
} else if (data[field.id] != undefined && currentVals.get(field.id) != data[field.id]) {
245+
if (data[field.id] != undefined && currentVals.get(field.id) != data[field.id]) {
311246
if (["method","bodyType"].includes(field.id)) {
312247
// Check the correct radio
313248
for (const c of field.children) {
@@ -341,7 +276,7 @@ export class RESTDebugPanel {
341276
// Bubble change events up to the form
342277
bodyContent.onchange = headersText.onchange =
343278
paramsText.onchange = path.onchange =
344-
webApp.onchange = () => form.dispatchEvent(new Event("change"));
279+
() => form.dispatchEvent(new Event("change"));
345280
</script>
346281
</body>
347282
</html>`;
@@ -460,7 +395,6 @@ export class RESTDebugPanel {
460395
// Restore the content
461396
this._panel.webview.postMessage({
462397
serverInfo,
463-
webApps,
464398
...RESTDebugPanel._cache,
465399
});
466400
}

0 commit comments

Comments
 (0)