add ability for md + text reports (#18667)

* add ability for md + text reports

* change report type

* re add types for ads

* match fields and add enum for mimetype

* rename preview report

* update type

* rename generate report type

* fix comment
This commit is contained in:
Aditya Bist
2022-03-09 15:48:21 -08:00
committed by GitHub
parent e50bded5d1
commit 822199c9be
8 changed files with 31 additions and 12 deletions

View File

@@ -1108,7 +1108,7 @@ export namespace TableDesignerGenerateScriptRequest {
} }
export namespace TableDesignerGenerateChangePreviewReportRequest { export namespace TableDesignerGenerateChangePreviewReportRequest {
export const type = new RequestType<azdata.designers.TableInfo, string, void, void>('tabledesigner/generatepreviewreport'); export const type = new RequestType<azdata.designers.TableInfo, azdata.designers.GeneratePreviewReportResult, void, void>('tabledesigner/generatepreviewreport');
} }
export namespace DisposeTableDesignerRequest { export namespace DisposeTableDesignerRequest {
export const type = new RequestType<azdata.designers.TableInfo, void, void, void>('tabledesigner/dispose'); export const type = new RequestType<azdata.designers.TableInfo, void, void, void>('tabledesigner/dispose');

View File

@@ -1151,7 +1151,7 @@ export class TableDesignerFeature extends SqlOpsFeature<undefined> {
} }
}; };
const generatePreviewReport = (tableInfo: azdata.designers.TableInfo): Thenable<string> => { const generatePreviewReport = (tableInfo: azdata.designers.TableInfo): Thenable<azdata.designers.GeneratePreviewReportResult> => {
try { try {
return client.sendRequest(contracts.TableDesignerGenerateChangePreviewReportRequest.type, tableInfo); return client.sendRequest(contracts.TableDesignerGenerateChangePreviewReportRequest.type, tableInfo);
} }

View File

@@ -1099,7 +1099,7 @@ declare module 'azdata' {
* Generate preview report describing the changes to be made. * Generate preview report describing the changes to be made.
* @param table the table information * @param table the table information
*/ */
generatePreviewReport(table: TableInfo): Thenable<string>; generatePreviewReport(table: TableInfo): Thenable<GeneratePreviewReportResult>;
/** /**
* Notify the provider that the table designer has been closed. * Notify the provider that the table designer has been closed.
@@ -1515,6 +1515,17 @@ declare module 'azdata' {
*/ */
view: TableDesignerView; view: TableDesignerView;
} }
export interface GeneratePreviewReportResult {
/**
* Report generated for generate preview
*/
report: string;
/**
* Format (mimeType) of the report
*/
mimeType: string;
}
} }
export interface ExecutionPlanGraph { export interface ExecutionPlanGraph {

View File

@@ -525,7 +525,7 @@ export class MainThreadDataProtocol extends Disposable implements MainThreadData
generateScript(tableInfo: azdata.designers.TableInfo): Thenable<string> { generateScript(tableInfo: azdata.designers.TableInfo): Thenable<string> {
return self._proxy.$generateScriptForTableDesigner(handle, tableInfo); return self._proxy.$generateScriptForTableDesigner(handle, tableInfo);
}, },
generatePreviewReport(tableInfo: azdata.designers.TableInfo): Thenable<string> { generatePreviewReport(tableInfo: azdata.designers.TableInfo): Thenable<azdata.designers.GeneratePreviewReportResult> {
return self._proxy.$generatePreviewReportForTableDesigner(handle, tableInfo); return self._proxy.$generatePreviewReportForTableDesigner(handle, tableInfo);
}, },
disposeTableDesigner(tableInfo: azdata.designers.TableInfo): Thenable<void> { disposeTableDesigner(tableInfo: azdata.designers.TableInfo): Thenable<void> {

View File

@@ -909,7 +909,7 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape {
return this._resolveProvider<azdata.designers.TableDesignerProvider>(handle).generateScript(table); return this._resolveProvider<azdata.designers.TableDesignerProvider>(handle).generateScript(table);
} }
public override $generatePreviewReportForTableDesigner(handle: number, table: azdata.designers.TableInfo): Thenable<string> { public override $generatePreviewReportForTableDesigner(handle: number, table: azdata.designers.TableInfo): Thenable<azdata.designers.GeneratePreviewReportResult> {
return this._resolveProvider<azdata.designers.TableDesignerProvider>(handle).generatePreviewReport(table); return this._resolveProvider<azdata.designers.TableDesignerProvider>(handle).generatePreviewReport(table);
} }

View File

@@ -556,7 +556,7 @@ export abstract class ExtHostDataProtocolShape {
/** /**
* Generate preview report. * Generate preview report.
*/ */
$generatePreviewReportForTableDesigner(handle: number, table: azdata.designers.TableInfo): Thenable<string> { throw ni(); } $generatePreviewReportForTableDesigner(handle: number, table: azdata.designers.TableInfo): Thenable<azdata.designers.GeneratePreviewReportResult> { throw ni(); }
/** /**
* Dispose the table designer. * Dispose the table designer.

View File

@@ -178,10 +178,10 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
sticky: true sticky: true
}); });
let report; let previewReportResult: azdata.designers.GeneratePreviewReportResult;
try { try {
this.updateState(this.valid, this.dirty, 'generateReport'); this.updateState(this.valid, this.dirty, 'generateReport');
report = await this._provider.generatePreviewReport(this.tableInfo); previewReportResult = await this._provider.generatePreviewReport(this.tableInfo);
reportNotificationHandle.close(); reportNotificationHandle.close();
this.updateState(this.valid, this.dirty); this.updateState(this.valid, this.dirty);
} catch (error) { } catch (error) {
@@ -190,7 +190,7 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
return; return;
} }
const dialog = this._instantiationService.createInstance(TableDesignerPublishDialog); const dialog = this._instantiationService.createInstance(TableDesignerPublishDialog);
const result = await dialog.open(<any>report.report); const result = await dialog.open(previewReportResult.report, previewReportResult.mimeType);
if (result === TableDesignerPublishDialogResult.GenerateScript) { if (result === TableDesignerPublishDialogResult.GenerateScript) {
await this.generateScript(); await this.generateScript();
} else if (result === TableDesignerPublishDialogResult.UpdateDatabase) { } else if (result === TableDesignerPublishDialogResult.UpdateDatabase) {

View File

@@ -20,6 +20,7 @@ import { attachModalDialogStyler } from 'sql/workbench/common/styler';
import { ILayoutService } from 'vs/platform/layout/browser/layoutService'; import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { MarkdownRenderer } from 'vs/editor/browser/core/markdownRenderer'; import { MarkdownRenderer } from 'vs/editor/browser/core/markdownRenderer';
import { Mimes } from 'vs/base/common/mime';
const OkText: string = localize('tableDesigner.UpdateDatabase', "Update Database"); const OkText: string = localize('tableDesigner.UpdateDatabase', "Update Database");
const CancelText: string = localize('tableDesigner.cancel', "Cancel"); const CancelText: string = localize('tableDesigner.cancel', "Cancel");
@@ -34,6 +35,7 @@ export enum TableDesignerPublishDialogResult {
export class TableDesignerPublishDialog extends Modal { export class TableDesignerPublishDialog extends Modal {
private _report?: string; private _report?: string;
private _mimeType: string = Mimes.text;
private _okButton?: Button; private _okButton?: Button;
private _generateScriptButton?: Button; private _generateScriptButton?: Button;
private _cancelButton?: Button; private _cancelButton?: Button;
@@ -54,8 +56,9 @@ export class TableDesignerPublishDialog extends Modal {
this._markdownRenderer = instantiationService.createInstance(MarkdownRenderer, {}); this._markdownRenderer = instantiationService.createInstance(MarkdownRenderer, {});
} }
public open(report: string): Promise<TableDesignerPublishDialogResult> { public open(report: string, mimeType: string = Mimes.text): Promise<TableDesignerPublishDialogResult> {
this._report = report; this._report = report;
this._mimeType = mimeType;
this.render(); this.render();
this.show(); this.show();
const promise = new Promise<TableDesignerPublishDialogResult>((resolve) => { const promise = new Promise<TableDesignerPublishDialogResult>((resolve) => {
@@ -78,8 +81,13 @@ export class TableDesignerPublishDialog extends Modal {
protected renderBody(container: HTMLElement) { protected renderBody(container: HTMLElement) {
const body = DOM.append(container, DOM.$('.table-designer-publish-dialog')); const body = DOM.append(container, DOM.$('.table-designer-publish-dialog'));
const markdownElement = this._markdownRenderer.render({ value: this._report }).element; if (this._mimeType === Mimes.markdown) {
DOM.append(body, markdownElement); const markdownElement = this._markdownRenderer.render({ value: this._report }).element;
DOM.append(body, markdownElement);
} else {
// default to plain text
body.innerText = this._report;
}
} }
protected layout(height?: number): void { protected layout(height?: number): void {