mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 17:01:13 +00:00
[BUG] Prevent dialog from opening if VS Code is open (#2145)
* master pull * Reverting .npmrc file * Removed logging userContext * Prettier run * Added support for opening CosmosDB Account without clicking database tab * Reverting change in settings.json * Prettier run * Added check if the link closed * Added check if the link didn't closed * Check if VS Code was opened, if not popup with download button link * Prettier run * Redirect to Download VS Code if not opened * Added error message to VS Code timeout and redirect * Fixing baseUrl from testing * Increased timeout for when user is asked to open VS Code * switched to iframe for redirects * Fixed VS Code url * Removed insider url * Added log messages * Added link to vCore data explorer dashboard * Increased timeout to 2.5 secs to see if that helps with VS Code open popup * Changed to dialog box * Changed param name * Increase startTime for extra popup * Changed to dialog box only when no VS Code detected * Fixed vscode url * Changed title back to Open CosmosDB in VS Code * Added text on required extensions * Removed text on required extensions as it will prompt by default * Fixed wording and Primary Button timeout * Spelled out VS Code * Removed console log of timeout * Updated snapshots and lowered timeout * Remove VS Code button from Gremlin * Prettier run on CommandBarComponentButtonFactory * Changed from referencing location to a link * Prettier run * Reverting back to popup for opening * Updated unit test snapshots * Added vscode: to Content Security Policy * Reverting back to popup only if opening times out * Corrected misspelled url * Corrected url * Added event listener to check if DE is in focus or not, to prevent showing dialog when VS Code is opened * Prettier and url fix * Moved closeDialog before removing event listener * Changed handleFocus to a const rather than function * Changed listener to document * Decreased timeout time * Reverting back to popup by default as too many factors are present using a timeout
This commit is contained in:
@@ -284,43 +284,12 @@ export default class Explorer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public openInVsCode(): void {
|
public openInVsCode(): void {
|
||||||
TelemetryProcessor.traceStart(Action.OpenVSCode);
|
|
||||||
this.openVsCodeButtonClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
private openVsCodeButtonClick(): void {
|
|
||||||
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 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();
|
|
||||||
let vsCodeNotOpened = false;
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
const timeOutTime = Date.now() - startTime;
|
|
||||||
if (!vsCodeNotOpened && timeOutTime < 1050) {
|
|
||||||
vsCodeNotOpened = true;
|
|
||||||
useDialog.getState().openDialog(openVSCodeDialogProps);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
const link = document.createElement("a");
|
|
||||||
link.href = vscodeUrl;
|
|
||||||
link.rel = "noopener noreferrer";
|
|
||||||
document.body.appendChild(link);
|
|
||||||
|
|
||||||
try {
|
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
|
||||||
TelemetryProcessor.traceStart(Action.OpenVSCode);
|
|
||||||
} catch (error) {
|
|
||||||
if (!vsCodeNotOpened) {
|
|
||||||
vsCodeNotOpened = true;
|
|
||||||
logConsoleError(`Failed to open VS Code: ${getErrorMessage(error)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const openVSCodeDialogProps: DialogProps = {
|
const openVSCodeDialogProps: DialogProps = {
|
||||||
linkProps: {
|
linkProps: {
|
||||||
@@ -335,15 +304,19 @@ export default class Explorer {
|
|||||||
secondaryButtonText: "Cancel",
|
secondaryButtonText: "Cancel",
|
||||||
|
|
||||||
onPrimaryButtonClick: () => {
|
onPrimaryButtonClick: () => {
|
||||||
vsCodeNotOpened = false;
|
try {
|
||||||
this.openVsCodeButtonClick();
|
window.location.href = vscodeUrl;
|
||||||
useDialog.getState().closeDialog();
|
TelemetryProcessor.traceStart(Action.OpenVSCode);
|
||||||
|
} catch (error) {
|
||||||
|
logConsoleError(`Failed to open VS Code: ${getErrorMessage(error)}`);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onSecondaryButtonClick: () => {
|
onSecondaryButtonClick: () => {
|
||||||
useDialog.getState().closeDialog();
|
useDialog.getState().closeDialog();
|
||||||
TelemetryProcessor.traceCancel(Action.OpenVSCode);
|
TelemetryProcessor.traceCancel(Action.OpenVSCode);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
useDialog.getState().openDialog(openVSCodeDialogProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async openCESCVAFeedbackBlade(): Promise<void> {
|
public async openCESCVAFeedbackBlade(): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user