From 381a747b623f877db5f58970e2c72838c54691d1 Mon Sep 17 00:00:00 2001 From: Anthony Dresser Date: Tue, 16 Jun 2020 12:10:05 -0700 Subject: [PATCH] fix export for remote (#10934) --- src/sql/workbench/common/workspaceActions.ts | 32 --------- .../browser/outputs/gridOutput.component.ts | 5 +- .../services/query/common/resultSerializer.ts | 66 ++++--------------- 3 files changed, 17 insertions(+), 86 deletions(-) delete mode 100644 src/sql/workbench/common/workspaceActions.ts diff --git a/src/sql/workbench/common/workspaceActions.ts b/src/sql/workbench/common/workspaceActions.ts deleted file mode 100644 index 0f997b44d9..0000000000 --- a/src/sql/workbench/common/workspaceActions.ts +++ /dev/null @@ -1,32 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the Source EULA. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { Action } from 'vs/base/common/actions'; -import { IOpenerService } from 'vs/platform/opener/common/opener'; -import { URI } from 'vs/base/common/uri'; -// eslint-disable-next-line code-layering,code-import-patterns -import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron'; - -export class ShowFileInFolderAction extends Action { - - constructor(private path: string, label: string, @IElectronService private electronService: IElectronService) { - super('showItemInFolder.action.id', label); - } - - run(): Promise { - return this.electronService.showItemInFolder(this.path); - } -} - -export class OpenFileInFolderAction extends Action { - - constructor(private path: string, label: string, @IOpenerService private openerService: IOpenerService) { - super('openItemInFolder.action.id', label); - } - - run() { - return this.openerService.open(URI.file(this.path), { openExternal: true }); - } -} diff --git a/src/sql/workbench/contrib/notebook/browser/outputs/gridOutput.component.ts b/src/sql/workbench/contrib/notebook/browser/outputs/gridOutput.component.ts index 552502763e..13233953d8 100644 --- a/src/sql/workbench/contrib/notebook/browser/outputs/gridOutput.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/outputs/gridOutput.component.ts @@ -40,6 +40,7 @@ import { Orientation } from 'vs/base/browser/ui/splitview/splitview'; import { ToggleableAction } from 'sql/workbench/contrib/notebook/browser/notebookActions'; import { IInsightOptions } from 'sql/workbench/common/editor/query/chartState'; import { NotebookChangeType } from 'sql/workbench/services/notebook/common/contracts'; +import { URI } from 'vs/base/common/uri'; @Component({ selector: GridOutputComponent.SELECTOR, @@ -308,7 +309,7 @@ class DataResourceDataProvider implements IGridDataProvider { return serializer.handleSerialization(this.documentUri, format, (filePath) => this.doSerialize(serializer, filePath, format, selection)); } - private doSerialize(serializer: ResultSerializer, filePath: string, format: SaveFormat, selection: Slick.Range[]): Promise { + private doSerialize(serializer: ResultSerializer, filePath: URI, format: SaveFormat, selection: Slick.Range[]): Promise { if (!this.canSerialize) { return Promise.resolve(undefined); } @@ -346,7 +347,7 @@ class DataResourceDataProvider implements IGridDataProvider { let serializeRequestParams: SerializeDataParams = assign(serializer.getBasicSaveParameters(format), >{ saveFormat: format, columns: columns, - filePath: filePath, + filePath: filePath.fsPath, getRowRange: (rowStart, numberOfRows) => getRows(rowStart, numberOfRows), rowCount: rowLength }); diff --git a/src/sql/workbench/services/query/common/resultSerializer.ts b/src/sql/workbench/services/query/common/resultSerializer.ts index 448f31c33e..363f8158e4 100644 --- a/src/sql/workbench/services/query/common/resultSerializer.ts +++ b/src/sql/workbench/services/query/common/resultSerializer.ts @@ -13,15 +13,12 @@ import * as nls from 'vs/nls'; import Severity from 'vs/base/common/severity'; import { INotificationService, INotification } from 'vs/platform/notification/common/notification'; -import { getBaseLabel } from 'vs/base/common/labels'; -import { ShowFileInFolderAction, OpenFileInFolderAction } from 'sql/workbench/common/workspaceActions'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { getRootPath, resolveCurrentDirectory, resolveFilePath } from 'sql/platform/common/pathUtilities'; +import { getRootPath, resolveCurrentDirectory } from 'sql/platform/common/pathUtilities'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IFileDialogService, FileFilter } from 'vs/platform/dialogs/common/dialogs'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -let prevSavePath: string; +let prevSavePath: URI; export interface ISaveRequest { format: SaveFormat; @@ -56,7 +53,6 @@ export enum SaveFormat { } const msgSaveFailed = nls.localize('msgSaveFailed', "Failed to save results. "); -const msgSaveSucceeded = nls.localize('msgSaveSucceeded', "Successfully saved results to "); /** * Handles save results request from the context menu of slickGrid @@ -70,8 +66,7 @@ export class ResultSerializer { @IEditorService private _editorService: IEditorService, @IWorkspaceContextService private _contextService: IWorkspaceContextService, @IFileDialogService private readonly fileDialogService: IFileDialogService, - @INotificationService private _notificationService: INotificationService, - @IInstantiationService private readonly _instantiationService: IInstantiationService + @INotificationService private _notificationService: INotificationService ) { } /** @@ -81,9 +76,6 @@ export class ResultSerializer { const self = this; return this.promptForFilepath(saveRequest.format, uri).then(filePath => { if (filePath) { - if (!path.isAbsolute(filePath)) { - filePath = resolveFilePath(uri, filePath, this.rootPath)!; - } let saveResultsParams = this.getParameters(uri, filePath, saveRequest.batchIndex, saveRequest.resultSetNumber, saveRequest.format, saveRequest.selection ? saveRequest.selection[0] : undefined); let sendRequest = () => this.sendSaveRequestToService(saveResultsParams); return self.doSave(filePath, saveRequest.format, sendRequest); @@ -103,14 +95,11 @@ export class ResultSerializer { /** * Handle save request by getting filename from user and sending request to service */ - public handleSerialization(uri: string, format: SaveFormat, sendRequest: ((filePath: string) => Promise)): Thenable { + public handleSerialization(uri: string, format: SaveFormat, sendRequest: ((filePath: URI) => Promise)): Thenable { const self = this; return this.promptForFilepath(format, uri).then(filePath => { if (filePath) { - if (!path.isAbsolute(filePath)) { - filePath = resolveFilePath(uri, filePath, this.rootPath)!; - } - return self.doSave(filePath, format, () => sendRequest(filePath!)); + return self.doSave(filePath, format, () => sendRequest(filePath)); } return Promise.resolve(); }); @@ -120,8 +109,8 @@ export class ResultSerializer { return getRootPath(this._contextService); } - private promptForFilepath(format: SaveFormat, resourceUri: string): Promise { - let filepathPlaceHolder = prevSavePath ? path.dirname(prevSavePath) : resolveCurrentDirectory(resourceUri, this.rootPath); + private promptForFilepath(format: SaveFormat, resourceUri: string): Promise { + let filepathPlaceHolder = prevSavePath ? path.dirname(prevSavePath.fsPath) : resolveCurrentDirectory(resourceUri, this.rootPath); if (filepathPlaceHolder) { filepathPlaceHolder = path.join(filepathPlaceHolder, this.getResultsDefaultFilename(format)); } @@ -132,8 +121,8 @@ export class ResultSerializer { filters: this.getResultsFileExtension(format) }).then(filePath => { if (filePath) { - prevSavePath = filePath.fsPath; - return filePath.fsPath; + prevSavePath = filePath; + return filePath; } return undefined; }); @@ -271,9 +260,9 @@ export class ResultSerializer { } - private getParameters(uri: string, filePath: string, batchIndex: number, resultSetNo: number, format: string, selection?: Slick.Range): SaveResultsRequestParams { + private getParameters(uri: string, filePath: URI, batchIndex: number, resultSetNo: number, format: string, selection?: Slick.Range): SaveResultsRequestParams { let saveResultsParams = this.getBasicSaveParameters(format); - saveResultsParams.filePath = filePath; + saveResultsParams.filePath = filePath.fsPath; saveResultsParams.ownerUri = uri; saveResultsParams.resultSetIndex = resultSetNo; saveResultsParams.batchIndex = batchIndex; @@ -293,35 +282,10 @@ export class ResultSerializer { return !!(selection && !((selection.fromCell === selection.toCell) && (selection.fromRow === selection.toRow))); } - - private promptFileSavedNotification(savedFilePath: string) { - let label = getBaseLabel(path.dirname(savedFilePath)); - - this._notificationService.prompt( - Severity.Info, - msgSaveSucceeded + savedFilePath, - [{ - label: nls.localize('openLocation', "Open file location"), - run: () => { - let action = this._instantiationService.createInstance(ShowFileInFolderAction, savedFilePath, label || path.sep); - action.run(); - action.dispose(); - } - }, { - label: nls.localize('openFile', "Open file"), - run: () => { - let action = this._instantiationService.createInstance(OpenFileInFolderAction, savedFilePath, label || path.sep); - action.run(); - action.dispose(); - } - }] - ); - } - /** * Send request to sql tools service to save a result set */ - private async doSave(filePath: string, format: string, sendRequest: () => Promise): Promise { + private async doSave(filePath: URI, format: string, sendRequest: () => Promise): Promise { const saveNotification: INotification = { severity: Severity.Info, @@ -341,7 +305,6 @@ export class ResultSerializer { message: msgSaveFailed + (result ? result.messages : '') }); } else { - this.promptFileSavedNotification(filePath); this.openSavedFile(filePath, format); } // TODO telemetry for save results @@ -360,10 +323,9 @@ export class ResultSerializer { /** * Open the saved file in a new vscode editor pane */ - private openSavedFile(filePath: string, format: string): void { + private openSavedFile(filePath: URI, format: string): void { if (format !== SaveFormat.EXCEL) { - let uri = URI.file(filePath); - this._editorService.openEditor({ resource: uri }).then((result) => { + this._editorService.openEditor({ resource: filePath }).then((result) => { }, (error: any) => { this._notificationService.notify({