From 8a570069f882c2ef75b55d00a17be713f75e81f3 Mon Sep 17 00:00:00 2001 From: kenvanhyning Date: Thu, 18 Oct 2018 12:58:07 -0700 Subject: [PATCH] Kenvh/editdatatabname (#2906) * Remove unnecessary string encoding on edit data naming * Cleaning up duplication in the naming methods. * fix typo in method name --- .../query/services/queryEditorService.ts | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/sql/parts/query/services/queryEditorService.ts b/src/sql/parts/query/services/queryEditorService.ts index 557e46d981..a5e7378884 100644 --- a/src/sql/parts/query/services/queryEditorService.ts +++ b/src/sql/parts/query/services/queryEditorService.ts @@ -124,7 +124,7 @@ export class QueryEditorService implements IQueryEditorService { try { // Create file path and file URI let objectName = schemaName ? schemaName + '.' + tableName : tableName; - let filePath = this.createEditDataFileName(objectName); + let filePath = this.createPrefixedSqlFilePath(objectName); let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath }); // Create a sql document pane with accoutrements @@ -265,45 +265,26 @@ export class QueryEditorService implements IQueryEditorService { ////// Private functions private createUntitledSqlFilePath(): string { - let sqlFileName = (counter: number): string => { - return `${untitledFilePrefix}${counter}`; - }; - - let counter = 1; - // Get document name and check if it exists - let filePath = sqlFileName(counter); - while (fs.existsSync(filePath)) { - counter++; - filePath = sqlFileName(counter); - } - - // check if this document name already exists in any open documents - let untitledEditors = this._untitledEditorService.getAll(); - while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) { - counter++; - filePath = sqlFileName(counter); - } - - return filePath; + return this.createPrefixedSqlFilePath(untitledFilePrefix); } - private createEditDataFileName(tableName: string): string { - let editDataFileName = (counter: number): string => { - return encodeURIComponent(`${tableName}_${counter}`); + private createPrefixedSqlFilePath(prefix: string): string { + let prefixFileName = (counter: number): string => { + return `${prefix}_${counter}`; }; let counter = 1; // Get document name and check if it exists - let filePath = editDataFileName(counter); + let filePath = prefixFileName(counter); while (fs.existsSync(filePath)) { counter++; - filePath = editDataFileName(counter); + filePath = prefixFileName(counter); } let untitledEditors = this._untitledEditorService.getAll(); while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) { counter++; - filePath = editDataFileName(counter); + filePath = prefixFileName(counter); } return filePath;