diff --git a/extensions/import/src/wizard/flatFileWizard.ts b/extensions/import/src/wizard/flatFileWizard.ts index 3954ab2e9d..c509ba314d 100644 --- a/extensions/import/src/wizard/flatFileWizard.ts +++ b/extensions/import/src/wizard/flatFileWizard.ts @@ -99,24 +99,17 @@ export class FlatFileWizard { this.importAnotherFileButton.hidden = true; this.wizard.customButtons = [this.importAnotherFileButton]; - this.wizard.onPageChanged(async (event) => { - let idx = event.newPage; - - let page = pages.get(idx); - - if (page) { - page.setupNavigationValidator(); - page.onPageEnter(); + let newPageIdx = event.newPage; + let lastPageIdx = event.lastPage; + let newPage = pages.get(newPageIdx); + let lastPage = pages.get(lastPageIdx); + if (lastPage) { + await lastPage.onPageLeave(); } - }); - - this.wizard.onPageChanged(async (event) => { - let idx = event.lastPage; - - let page = pages.get(idx); - if (page) { - page.onPageLeave(); + if (newPage) { + newPage.setupNavigationValidator(); + await newPage.onPageEnter(); } }); diff --git a/extensions/import/src/wizard/pages/modifyColumnsPage.ts b/extensions/import/src/wizard/pages/modifyColumnsPage.ts index 02fc85bedb..b2ea8f23ba 100644 --- a/extensions/import/src/wizard/pages/modifyColumnsPage.ts +++ b/extensions/import/src/wizard/pages/modifyColumnsPage.ts @@ -127,7 +127,7 @@ export class ModifyColumnsPage extends ImportPage { public setupNavigationValidator() { this.instance.registerNavigationValidator((info) => { - return !this.loading.loading; + return !this.loading.loading && this.table.data && this.table.data.length > 0; }); } diff --git a/extensions/import/src/wizard/pages/prosePreviewPage.ts b/extensions/import/src/wizard/pages/prosePreviewPage.ts index f82e508255..f97d9f8b9f 100644 --- a/extensions/import/src/wizard/pages/prosePreviewPage.ts +++ b/extensions/import/src/wizard/pages/prosePreviewPage.ts @@ -11,14 +11,21 @@ import { ImportDataModel } from '../api/models'; import { ImportPage } from '../api/importPage'; import { FlatFileProvider } from '../../services/contracts'; import { FlatFileWizard } from '../flatFileWizard'; +import { PerformanceObserver } from 'perf_hooks'; const localize = nls.loadMessageBundle(); export class ProsePreviewPage extends ImportPage { + + private readonly successTitle: string = localize('flatFileImport.prosePreviewMessage', 'This operation analyzed the input file structure to generate the preview below for up to the first 50 rows.'); + private readonly failureTitle: string = localize('flatFileImport.prosePreviewMessageFail', 'This operation was unsuccessful. Please try a different input file.'); + private table: azdata.TableComponent; private loading: azdata.LoadingComponent; private form: azdata.FormContainer; private refresh: azdata.ButtonComponent; + private resultTextComponent: azdata.TextComponent; + private isSuccess: boolean; public constructor(instance: FlatFileWizard, wizardPage: azdata.window.WizardPage, model: ImportDataModel, view: azdata.ModelView, provider: FlatFileProvider) { super(instance, wizardPage, model, view, provider); @@ -32,15 +39,24 @@ export class ProsePreviewPage extends ImportPage { }).component(); this.refresh.onDidClick(async () => { - this.onPageEnter(); + await this.onPageEnter(); }); this.loading = this.view.modelBuilder.loadingComponent().component(); + this.resultTextComponent = this.view.modelBuilder.text() + .withProperties({ + value: this.isSuccess ? this.successTitle : this.failureTitle + }).component(); + this.form = this.view.modelBuilder.formContainer().withFormItems([ + { + component: this.resultTextComponent, + title: '' + }, { component: this.table, - title: localize('flatFileImport.prosePreviewMessage', 'This operation analyzed the input file structure to generate the preview below for up to the first 50 rows.'), + title: '', actions: [this.refresh] } ]).component(); @@ -54,11 +70,23 @@ export class ProsePreviewPage extends ImportPage { async onPageEnter(): Promise { this.loading.loading = true; - await this.handleProse(); - await this.populateTable(this.model.proseDataPreview, this.model.proseColumns.map(c => c.columnName)); + let proseResult = await this.handleProse(); this.loading.loading = false; - - return true; + if (proseResult) { + await this.populateTable(this.model.proseDataPreview, this.model.proseColumns.map(c => c.columnName)); + this.isSuccess = true; + if (this.form) { + this.resultTextComponent.value = this.successTitle; + } + return true; + } else { + await this.populateTable([], []); + this.isSuccess = false; + if (this.form) { + this.resultTextComponent.value = this.failureTitle; + } + return false; + } } async onPageLeave(): Promise { @@ -73,27 +101,42 @@ export class ProsePreviewPage extends ImportPage { public setupNavigationValidator() { this.instance.registerNavigationValidator((info) => { + if (info) { + // Prose Preview to Modify Columns + if (info.lastPage === 1 && info.newPage === 2) { + return !this.loading.loading && this.table.data && this.table.data.length > 0; + } + } return !this.loading.loading; }); } - private async handleProse() { - await this.provider.sendPROSEDiscoveryRequest({ + private async handleProse(): Promise { + return this.provider.sendPROSEDiscoveryRequest({ filePath: this.model.filePath, tableName: this.model.table, schemaName: this.model.schema, fileType: this.model.fileType }).then((result) => { - this.model.proseDataPreview = result.dataPreview; - this.model.proseColumns = []; - result.columnInfo.forEach((column) => { - this.model.proseColumns.push({ - columnName: column.name, - dataType: column.sqlType, - primaryKey: false, - nullable: column.isNullable - }); - }); + if (result) { + this.model.proseDataPreview = null; + if (result.dataPreview) { + this.model.proseDataPreview = result.dataPreview; + } + this.model.proseColumns = []; + if (result.columnInfo) { + result.columnInfo.forEach((column) => { + this.model.proseColumns.push({ + columnName: column.name, + dataType: column.sqlType, + primaryKey: false, + nullable: column.isNullable + }); + }); + return true; + } + } + return false; }); } @@ -119,5 +162,4 @@ export class ProsePreviewPage extends ImportPage { private async emptyTable() { this.table.updateProperties([]); } - }