mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-05-11 10:54:30 +01:00
Changed to dialog box
This commit is contained in:
parent
32adf7fde6
commit
323ba64e90
@ -283,41 +283,55 @@ export default class Explorer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public openInVsCode(): void {
|
public openInVsCode(): void {
|
||||||
|
const openVSCodeDialogProps: DialogProps = {
|
||||||
|
linkProps: {
|
||||||
|
linkText: "Download Visual Studio Code",
|
||||||
|
linkUrl: "https://code.visualstudio.com/download",
|
||||||
|
},
|
||||||
|
isModal: true,
|
||||||
|
title: `Open your Cosmos DB account in Visual Studio Code`,
|
||||||
|
subText: `Please ensure Visual Studio Code is installed on your device.
|
||||||
|
If you don't have it installed, please download it from the link below.`,
|
||||||
|
primaryButtonText: "Open in VS Code",
|
||||||
|
secondaryButtonText: "Cancel",
|
||||||
|
|
||||||
|
onPrimaryButtonClick: () => {
|
||||||
|
TelemetryProcessor.traceStart(Action.OpenVSCode);
|
||||||
|
|
||||||
const activeTab = useTabs.getState().activeTab;
|
const activeTab = useTabs.getState().activeTab;
|
||||||
const resourceId = encodeURIComponent(userContext.databaseAccount.id);
|
const resourceId = encodeURIComponent(userContext.databaseAccount.id);
|
||||||
const database = encodeURIComponent(activeTab?.collection?.databaseId);
|
const database = encodeURIComponent(activeTab?.collection?.databaseId);
|
||||||
const container = encodeURIComponent(activeTab?.collection?.id());
|
const container = encodeURIComponent(activeTab?.collection?.id());
|
||||||
const downloadUrl = "https://code.visualstudio.com/download";
|
|
||||||
|
|
||||||
const baseUrl = `vscode://ms-azuretools.vscode-cosmosdb?resourceId=${resourceId}`;
|
const baseUrl = `vscode://ms-azuretools.vscode-cosmosdb?resourceId=${resourceId}`;
|
||||||
const vscodeUrl = activeTab ? `${baseUrl}&database=${database}&container=${container}` : baseUrl;
|
const vscodeUrl = activeTab ? `${baseUrl}&database=${database}&container=${container}` : baseUrl;
|
||||||
|
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
let hasRedirected = false;
|
let hasRedirected = false;
|
||||||
|
|
||||||
const iframe = document.createElement("iframe");
|
|
||||||
iframe.style.display = "none";
|
|
||||||
document.body.appendChild(iframe);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!hasRedirected && Date.now() - startTime < 2500) {
|
if (!hasRedirected && Date.now() - startTime < 1200) {
|
||||||
hasRedirected = true;
|
hasRedirected = true;
|
||||||
window.open(downloadUrl, "_blank");
|
logConsoleInfo(
|
||||||
logConsoleInfo("VS Code not detected. Opening download page.");
|
"Visual Studio Code not detected. Please download it from: https://code.visualstudio.com/download",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, 2500);
|
}, 1000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
iframe.src = vscodeUrl;
|
|
||||||
window.location.href = vscodeUrl;
|
window.location.href = vscodeUrl;
|
||||||
logConsoleInfo("Opening VS Code");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!hasRedirected) {
|
if (!hasRedirected) {
|
||||||
hasRedirected = true;
|
hasRedirected = true;
|
||||||
window.open(downloadUrl, "_blank");
|
|
||||||
logConsoleError(`Failed to open VS Code: ${getErrorMessage(error)}`);
|
logConsoleError(`Failed to open VS Code: ${getErrorMessage(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onSecondaryButtonClick: () => {
|
||||||
|
useDialog.getState().closeDialog();
|
||||||
|
TelemetryProcessor.traceCancel(Action.OpenVSCode);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
useDialog.getState().openDialog(openVSCodeDialogProps);
|
||||||
|
TelemetryProcessor.traceStart(Action.OpenVSCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async openCESCVAFeedbackBlade(): Promise<void> {
|
public async openCESCVAFeedbackBlade(): Promise<void> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user