Skip to content

Commit

Permalink
wire up new interaction events
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Dec 14, 2023
1 parent 8931e5e commit f1dc657
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 7 additions & 9 deletions libs/vscode/graph-base/src/lib/load-graph-base-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ export async function loadGraphBaseHtml(webview: Webview): Promise<string> {
if (type.startsWith('request') && id && pendingRequests.has(id)) {
const payloadParsed = JSON.parse(payload);
console.log('payload', payloadParsed)
const resolve = pendingRequests.get(id);
resolve(payloadParsed);
pendingRequests.delete(id);
}
});
function sendRequest(type) {
function sendRequest(type, payload) {
return new Promise((resolve) => {
const id = generateUniqueId();
pendingRequests.set(id, resolve);
vscode.postMessage({ type, id });
vscode.postMessage({ type, id, payload });
});
}
Expand All @@ -89,13 +90,10 @@ export async function loadGraphBaseHtml(webview: Webview): Promise<string> {
window.externalApi.loadSourceMaps = () => sendRequest('requestSourceMaps');
// set up interaction events (open project config, file click, ...)
if(!window.externalApi.graphInteractionEventListeners) {
window.externalApi.graphInteractionEventListeners = []
}
window.externalApi.graphInteractionEventListeners.push((message) => {
console.log('graph interaction', message)
vscode.postMessage(message)
})
window.externalApi.graphInteractionEventListener = (message) => {
console.log('graph interaction', message)
vscode.postMessage(message)
}
window.environment = "nx-console"
Expand Down
8 changes: 6 additions & 2 deletions libs/vscode/graph-base/src/lib/nx-graph-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export class NxGraphServer implements Disposable {

constructor(private startPort: number, private affected = false) {}

async handleWebviewRequest(request: { type: string; id: string }): Promise<
async handleWebviewRequest(request: {
type: string;
id: string;
payload: string;
}): Promise<
| {
type: string;
id: string;
Expand All @@ -59,7 +63,7 @@ export class NxGraphServer implements Disposable {
url += 'task-graph.json';
break;
case 'requestExpandedTaskInputs':
url += `expanded-task-inputs.json`;
url += `task-inputs.json?taskId=${request.payload}`;
break;
case 'requestSourceMaps':
url += 'source-maps.json';
Expand Down

0 comments on commit f1dc657

Please sign in to comment.