From f02174eb7e63d4ffd7b638e511c2592b5657a92b Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Wed, 9 Mar 2022 16:03:02 -0800 Subject: [PATCH] (core) Fix error when canceling import Summary: If cancel was clicked while a transform section was still being generated in the Importer, an error was thrown. This refactors the cancelImportFiles API action to take in the file upload id in place of the entire DataSourceTransformed parameter, which contains other values that are irrelevant to canceling. One of those values, the transform section id, was causing the error to be thrown since it was momentarily null. Test Plan: Tested manually. Reviewers: alexmojaki Reviewed By: alexmojaki Differential Revision: https://phab.getgrist.com/D3317 --- app/client/components/Importer.ts | 4 +--- app/common/ActiveDocAPI.ts | 2 +- app/server/lib/ActiveDoc.ts | 4 ++-- app/server/lib/ActiveDocImport.ts | 6 +++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/client/components/Importer.ts b/app/client/components/Importer.ts index 895a33ad..7cabed28 100644 --- a/app/client/components/Importer.ts +++ b/app/client/components/Importer.ts @@ -446,10 +446,8 @@ export class Importer extends DisposableWithEvents { this._resetImportDiffState(); // Formula editor cleanup needs to happen before the hidden tables are removed. this._formulaEditorHolder.dispose(); - if (this._uploadResult) { - await this._docComm.cancelImportFiles( - this._getTransformedDataSource(this._uploadResult), this._getHiddenTableIds()); + await this._docComm.cancelImportFiles(this._uploadResult.uploadId, this._getHiddenTableIds()); } this._screen.close(); this.dispose(); diff --git a/app/common/ActiveDocAPI.ts b/app/common/ActiveDocAPI.ts index acafc2bb..b81b7928 100644 --- a/app/common/ActiveDocAPI.ts +++ b/app/common/ActiveDocAPI.ts @@ -209,7 +209,7 @@ export interface ActiveDocAPI { /** * Cancels import files, cleans up temporary hidden tables and uploads. */ - cancelImportFiles(dataSource: DataSourceTransformed, prevTableIds: string[]): Promise; + cancelImportFiles(uploadId: number, prevTableIds: string[]): Promise; /** * Returns a diff of changes that will be applied to the destination table from `transformRule` diff --git a/app/server/lib/ActiveDoc.ts b/app/server/lib/ActiveDoc.ts index 345a75ec..0d777f30 100644 --- a/app/server/lib/ActiveDoc.ts +++ b/app/server/lib/ActiveDoc.ts @@ -544,9 +544,9 @@ export class ActiveDoc extends EventEmitter { * Param `prevTableIds` is an array of hiddenTableIds as received from previous `importFiles` * call, or empty if there was no previous call. */ - public cancelImportFiles(docSession: DocSession, dataSource: DataSourceTransformed, + public cancelImportFiles(docSession: DocSession, uploadId: number, prevTableIds: string[]): Promise { - return this._activeDocImport.cancelImportFiles(docSession, dataSource, prevTableIds); + return this._activeDocImport.cancelImportFiles(docSession, uploadId, prevTableIds); } /** diff --git a/app/server/lib/ActiveDocImport.ts b/app/server/lib/ActiveDocImport.ts index 93e253dd..0f39ee74 100644 --- a/app/server/lib/ActiveDocImport.ts +++ b/app/server/lib/ActiveDocImport.ts @@ -97,17 +97,17 @@ export class ActiveDocImport { * Cancels import files, removes temporary hidden tables and temporary uploaded files * * @param {ActiveDoc} activeDoc: Instance of ActiveDoc. - * @param {DataSourceTransformed} dataSource: an array of DataSource + * @param {number} uploadId: Identifier for the temporary uploaded file(s) to clean up. * @param {Array} prevTableIds: Array of tableIds as received from previous `importFiles` * call when re-importing with changed `parseOptions`. * @returns {Promise} Promise that's resolved when all actions are applied successfully. */ public async cancelImportFiles(docSession: DocSession, - dataSource: DataSourceTransformed, + uploadId: number, prevTableIds: string[]): Promise { await this._removeHiddenTables(docSession, prevTableIds); this._activeDoc.stopBundleUserActions(docSession); - await globalUploadSet.cleanup(dataSource.uploadId); + await globalUploadSet.cleanup(uploadId); } /**