-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickPicks.ts
81 lines (79 loc) · 2.59 KB
/
quickPicks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { window, commands, ExtensionContext, ThemeIcon } from 'vscode';
import { readFileSync, writeFileSync } from 'fs';
import { Subgraph } from './Subgraph';
export const selectUrl = (rootPath: string, subgraph: Subgraph, context: ExtensionContext) => {
const urlSelector = window.createQuickPick();
urlSelector.items = [
{
label: 'Use Local Url',
description: subgraph.local,
buttons: [
{
iconPath: new ThemeIcon('edit'),
tooltip: 'Edit Url',
},
],
},
{
label: 'Use Apollo Studio Url',
description: subgraph.dev,
buttons: [
{
iconPath: new ThemeIcon('edit'),
tooltip: 'Edit Url',
},
],
},
];
urlSelector.onDidChangeSelection(() => {
const label = urlSelector.selectedItems[0].label || '';
if (!label) {
return;
}
subgraph.setUrl(label === 'Use Local Url' ? 'localUrl' : 'devUrl');
context.workspaceState.update(subgraph.label + 'currentUrl', label === 'Use Local Url' ? 'localUrl' : 'devUrl');
commands.executeCommand('subgraphsList.refreshEntry');
urlSelector.dispose();
});
urlSelector.onDidTriggerItemButton((item) => {
const placeHolder = item.item.label === 'Use Local Url' ? subgraph.local : subgraph.dev;
window
.showInputBox({
ignoreFocusOut: true,
prompt: `Please insert the new url`,
title: `Set ${item.item.label.split(/\s(.*)/s)[1]}`,
placeHolder: context.workspaceState.get(item.item.label, placeHolder),
})
.then((inp) => {
if (!inp) {
return;
}
const filePath = `${rootPath}/.rover-runner/${context.workspaceState.get(
'Supergraph Configuration Filename',
'supergraph.json'
)}`;
const supergraphJson = JSON.parse(readFileSync(filePath, 'utf-8'));
const urlKey: string = item.item.label === 'Use Local Url' ? 'localUrl' : 'devUrl';
supergraphJson.subgraphs[subgraph.label][urlKey] = inp;
writeFileSync(filePath, JSON.stringify(supergraphJson, null, 2), 'utf-8');
if (urlKey === 'localUrl') {
subgraph.setLocal(inp);
} else {
subgraph.setDev(inp);
}
});
});
urlSelector.onDidHide(() => {
urlSelector.dispose();
});
urlSelector.show();
};
/**
* A QuickPick for deciding to run a subgraph normally or in the debugger
*/
export const shouldRunDebug = () =>
window.showQuickPick(['Run Normally', 'Run in Debug Mode'], {
placeHolder: 'Do you want to run in normal or debug mode?',
canPickMany: false,
ignoreFocusOut: true,
});