From 9aa821b3cc5bc67da7632f4f04d699eb4c76bcd0 Mon Sep 17 00:00:00 2001 From: Wroud Date: Sun, 3 May 2020 21:58:07 +0300 Subject: [PATCH] fix: after merge --- .../packages/core/src/blocks/StaticImage.tsx | 2 +- .../queries/DataTransfer/asyncTaskStatus.gql | 16 +++++ webapp/packages/core/src/sdk/sdk.ts | 32 ++++++++++ .../src/DataExportMenuService.ts | 7 --- .../src/DataExportService.ts | 1 + .../src/Dialog/DataExportController.ts | 58 +++++++++++-------- .../src/Dialog/DataExportDialog.tsx | 4 +- .../src/Dialog/ProcessorConfigureDialog.tsx | 5 +- .../src/ExportFromContainerProcess.ts | 4 +- .../src/ExportFromResultsProcess.ts | 4 +- 10 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 webapp/packages/core/src/queries/DataTransfer/asyncTaskStatus.gql diff --git a/webapp/packages/core/src/blocks/StaticImage.tsx b/webapp/packages/core/src/blocks/StaticImage.tsx index 8a1f6385ff..a846f152b8 100644 --- a/webapp/packages/core/src/blocks/StaticImage.tsx +++ b/webapp/packages/core/src/blocks/StaticImage.tsx @@ -30,5 +30,5 @@ export function StaticImage({ const url = icon[0] === '/' ? icon : `${staticEndpoint}/images/${icon}`; - return {icon}/; + return ; } diff --git a/webapp/packages/core/src/queries/DataTransfer/asyncTaskStatus.gql b/webapp/packages/core/src/queries/DataTransfer/asyncTaskStatus.gql new file mode 100644 index 0000000000..d835660f77 --- /dev/null +++ b/webapp/packages/core/src/queries/DataTransfer/asyncTaskStatus.gql @@ -0,0 +1,16 @@ +mutation asyncExportTaskStatus( + $taskId: String! +) { + taskInfo: asyncTaskStatus( + id: $taskId + ) { + id + running + taskResult + error { + message + errorCode + stackTrace + } + } +} diff --git a/webapp/packages/core/src/sdk/sdk.ts b/webapp/packages/core/src/sdk/sdk.ts index d2a4c10401..dd953b2bee 100644 --- a/webapp/packages/core/src/sdk/sdk.ts +++ b/webapp/packages/core/src/sdk/sdk.ts @@ -852,6 +852,16 @@ export type ChangeSessionLanguageMutation = Pick< "changeSessionLanguage" >; +export type AsyncExportTaskStatusMutationVariables = { + taskId: Scalars["String"]; +}; + +export type AsyncExportTaskStatusMutation = { + taskInfo: Pick & { + error: Maybe>; + }; +}; + export type ExportDataFromContainerQueryVariables = { connectionId: Scalars["ID"]; containerNodePath: Scalars["ID"]; @@ -1485,6 +1495,20 @@ export const ChangeSessionLanguageDocument = gql` changeSessionLanguage(locale: $locale) } `; +export const AsyncExportTaskStatusDocument = gql` + mutation asyncExportTaskStatus($taskId: String!) { + taskInfo: asyncTaskStatus(id: $taskId) { + id + running + taskResult + error { + message + errorCode + stackTrace + } + } + } +`; export const ExportDataFromContainerDocument = gql` query exportDataFromContainer( $connectionId: ID! @@ -2040,6 +2064,14 @@ export function getSdk(client: GraphQLClient) { variables, ); }, + asyncExportTaskStatus( + variables: AsyncExportTaskStatusMutationVariables, + ): Promise { + return client.request( + print(AsyncExportTaskStatusDocument), + variables, + ); + }, exportDataFromContainer( variables: ExportDataFromContainerQueryVariables, ): Promise { diff --git a/webapp/packages/data-export-plugin/src/DataExportMenuService.ts b/webapp/packages/data-export-plugin/src/DataExportMenuService.ts index a602c34a25..f6469d864f 100644 --- a/webapp/packages/data-export-plugin/src/DataExportMenuService.ts +++ b/webapp/packages/data-export-plugin/src/DataExportMenuService.ts @@ -36,13 +36,6 @@ export class DataExportMenuService { } private exportData(context: IMenuContext) { - console.log({ - connectionId: context.data.connectionId, - contextId: context.data.executionContext?.contextId, - containerNodePath: context.data.containerNodePath, - resultId: context.data.resultId, - sourceName: context.data.sourceName, - }); this.commonDialogService.open(DataExportDialog, { connectionId: context.data.connectionId, contextId: context.data.executionContext?.contextId, diff --git a/webapp/packages/data-export-plugin/src/DataExportService.ts b/webapp/packages/data-export-plugin/src/DataExportService.ts index c34c26956b..8fa42dd286 100644 --- a/webapp/packages/data-export-plugin/src/DataExportService.ts +++ b/webapp/packages/data-export-plugin/src/DataExportService.ts @@ -72,6 +72,7 @@ export class DataExportService { const taskId = await process.start(connectionId, containerNodePath, parameters); if (taskId) { this.exportProcesses.set(taskId, process); + // this.notificationService.logInfo({ title: 'We prepare your file for export. Please wait' }); await process.promise; window.open(this.download(taskId), '_blank'); return taskId; diff --git a/webapp/packages/data-export-plugin/src/Dialog/DataExportController.ts b/webapp/packages/data-export-plugin/src/Dialog/DataExportController.ts index a8168907f1..b012976d1c 100644 --- a/webapp/packages/data-export-plugin/src/Dialog/DataExportController.ts +++ b/webapp/packages/data-export-plugin/src/Dialog/DataExportController.ts @@ -25,8 +25,9 @@ export enum DataExportStep { export class DataExportController implements IInitializableController { @observable step = DataExportStep.DataTransferProcessor get isLoading() { - return !this.dataExportService.processors.isLoaded(); + return this.dataExportService.processors.isLoading(); } + @observable isExporting = false @observable processor: DataTransferProcessorInfo | null = null @computed get processors(): DataTransferProcessorInfo[] { @@ -41,41 +42,52 @@ export class DataExportController implements IInitializableController { @observable properties: IProperty[] = [] private context!: IExportContext; + private close!: () => void; constructor( private dataExportService: DataExportService, private notificationService: NotificationService ) { } - init(context: IExportContext) { + init(context: IExportContext, close: () => void) { this.context = context; + this.close = close; this.loadProcessors(); } - export = () => { - if (!this.processor) { + export = async () => { + if (!this.processor || this.isExporting) { return; } + this.isExporting = true; - if (this.context.containerNodePath) { - this.dataExportService.exportFromContainer( - this.context.connectionId, - this.context.containerNodePath, - { - processorId: this.processor.id, - processorProperties: this.processorProperties, - } - ); - } else if (this.context.contextId && this.context.resultId) { - this.dataExportService.exportFromResults( - this.context.connectionId, - this.context.contextId, - this.context.resultId, - { - processorId: this.processor.id, - processorProperties: this.processorProperties, - } - ); + try { + if (this.context.containerNodePath) { + await this.dataExportService.exportFromContainer( + this.context.connectionId, + this.context.containerNodePath, + { + processorId: this.processor.id, + processorProperties: this.processorProperties, + } + ); + } else if (this.context.contextId && this.context.resultId) { + await this.dataExportService.exportFromResults( + this.context.connectionId, + this.context.contextId, + this.context.resultId, + { + processorId: this.processor.id, + processorProperties: this.processorProperties, + } + ); + } + this.close(); + } catch (exception) { + this.notificationService.logException(exception, 'Can\'t export'); + } finally { + this.isExporting = false; + close(); } } diff --git a/webapp/packages/data-export-plugin/src/Dialog/DataExportDialog.tsx b/webapp/packages/data-export-plugin/src/Dialog/DataExportDialog.tsx index 99e4cec900..61d7634569 100644 --- a/webapp/packages/data-export-plugin/src/Dialog/DataExportDialog.tsx +++ b/webapp/packages/data-export-plugin/src/Dialog/DataExportDialog.tsx @@ -18,7 +18,7 @@ import { ProcessorSelectDialog } from './ProcessorSelectDialog'; export const DataExportDialog: DialogComponent = observer( function DataExportDialog(props) { - const controller = useController(DataExportController, props.payload); + const controller = useController(DataExportController, props.payload, props.rejectDialog); if (controller.step === DataExportStep.Configure && controller.processor) { return ( @@ -26,7 +26,7 @@ export const DataExportDialog: DialogComponent = observer( processor={controller.processor} properties={controller.properties} processorProperties={controller.processorProperties} - isExporting={false} + isExporting={controller.isExporting} onBack={() => controller.setStep(DataExportStep.DataTransferProcessor)} onClose={props.rejectDialog} onExport={controller.export} diff --git a/webapp/packages/data-export-plugin/src/Dialog/ProcessorConfigureDialog.tsx b/webapp/packages/data-export-plugin/src/Dialog/ProcessorConfigureDialog.tsx index ded114d760..5b7f952cc8 100644 --- a/webapp/packages/data-export-plugin/src/Dialog/ProcessorConfigureDialog.tsx +++ b/webapp/packages/data-export-plugin/src/Dialog/ProcessorConfigureDialog.tsx @@ -24,6 +24,9 @@ const styles = css` PropertiesTable { flex: 1; } + message { + margin: auto; + } `; type ProcessorSelectDialogProps = { @@ -62,7 +65,7 @@ export const ProcessorConfigureDialog = observer( } onReject={onClose} > - {isExporting && } + {isExporting && We prepare your file for export. Please wait...} {!isExporting && ( { } } catch (e) { this.onError(e); - return; + throw e; } this.statusUpdateProcess(); @@ -80,7 +80,7 @@ export class ExportFromContainerProcess extends Deferred { } // run the first check immediately because usually the query execution is fast try { - const { taskInfo } = await this.graphQLService.gql.asyncTaskStatus({ taskId: this.taskId }); + const { taskInfo } = await this.graphQLService.gql.asyncExportTaskStatus({ taskId: this.taskId }); this.applyResult(taskInfo); if (this.isFinished) { return; diff --git a/webapp/packages/data-export-plugin/src/ExportFromResultsProcess.ts b/webapp/packages/data-export-plugin/src/ExportFromResultsProcess.ts index 06b1b4f709..d8b184b8d0 100644 --- a/webapp/packages/data-export-plugin/src/ExportFromResultsProcess.ts +++ b/webapp/packages/data-export-plugin/src/ExportFromResultsProcess.ts @@ -49,7 +49,7 @@ export class ExportFromResultsProcess extends Deferred { } } catch (e) { this.onError(e); - return; + throw e; } this.statusUpdateProcess(); @@ -82,7 +82,7 @@ export class ExportFromResultsProcess extends Deferred { } // run the first check immediately because usually the query execution is fast try { - const { taskInfo } = await this.graphQLService.gql.asyncTaskStatus({ taskId: this.taskId }); + const { taskInfo } = await this.graphQLService.gql.asyncExportTaskStatus({ taskId: this.taskId }); this.applyResult(taskInfo); if (this.isFinished) { return;