mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 01:25:38 -05:00
query results filtering and sorting (#14833)
* query results filtering and sorting (#14589) * enable filter * attach button style * add hybrid data provider * make filter and sort work * fix editor switch issue * configuration * fix sort and filter * add more specific selector * fix hidden items issue * update text * revert text change * fix copy results issue * put feature behind preview flag * comments * fix tslint error
This commit is contained in:
@@ -16,6 +16,16 @@ export class GridPanelState {
|
||||
}
|
||||
}
|
||||
|
||||
export interface GridColumnFilter {
|
||||
field: string;
|
||||
filterValues: string[];
|
||||
}
|
||||
|
||||
export interface GridSortState {
|
||||
field: string;
|
||||
sortAsc: boolean;
|
||||
}
|
||||
|
||||
export class GridTableState extends Disposable {
|
||||
|
||||
private _maximized?: boolean;
|
||||
@@ -28,6 +38,9 @@ export class GridTableState extends Disposable {
|
||||
|
||||
private _canBeMaximized?: boolean;
|
||||
|
||||
private _columnFilters: GridColumnFilter[] | undefined;
|
||||
private _sortState: GridSortState | undefined;
|
||||
|
||||
/* The top row of the current scroll */
|
||||
public scrollPositionY = 0;
|
||||
public scrollPositionX = 0;
|
||||
@@ -62,4 +75,20 @@ export class GridTableState extends Disposable {
|
||||
this._maximized = val;
|
||||
this._onMaximizedChange.fire(val);
|
||||
}
|
||||
|
||||
public get columnFilters(): GridColumnFilter[] | undefined {
|
||||
return this._columnFilters;
|
||||
}
|
||||
|
||||
public set columnFilters(value: GridColumnFilter[] | undefined) {
|
||||
this._columnFilters = value;
|
||||
}
|
||||
|
||||
public get sortState(): GridSortState | undefined {
|
||||
return this._sortState;
|
||||
}
|
||||
|
||||
public set sortState(value: GridSortState | undefined) {
|
||||
this._sortState = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,7 +981,7 @@ export class EditDataGridPanel extends GridParentComponent {
|
||||
|| (changes['blurredColumns'] && !equals(changes['blurredColumns'].currentValue, changes['blurredColumns'].previousValue))
|
||||
|| (changes['columnsLoading'] && !equals(changes['columnsLoading'].currentValue, changes['columnsLoading'].previousValue))) {
|
||||
this.setCallbackOnDataRowsChanged();
|
||||
this.table.rerenderGrid(0, this.dataSet.dataRows.getLength());
|
||||
this.table.rerenderGrid();
|
||||
hasGridStructureChanges = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import { ICellModel } from 'sql/workbench/services/notebook/browser/models/model
|
||||
import { MimeModel } from 'sql/workbench/services/notebook/browser/outputs/mimemodel';
|
||||
import { GridTableState } from 'sql/workbench/common/editor/query/gridTableState';
|
||||
import { GridTableBase } from 'sql/workbench/contrib/query/browser/gridPanel';
|
||||
import { getErrorMessage } from 'vs/base/common/errors';
|
||||
import { getErrorMessage, onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { ISerializationService, SerializeDataParams } from 'sql/platform/serialization/common/serializationService';
|
||||
import { SaveResultAction, IGridActionContext } from 'sql/workbench/contrib/query/browser/actions';
|
||||
import { SaveFormat, ResultSerializer, SaveResultsResponse } from 'sql/workbench/services/query/common/resultSerializer';
|
||||
@@ -43,6 +43,7 @@ import { URI } from 'vs/base/common/uri';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { QueryResultId } from 'sql/workbench/services/notebook/browser/models/cell';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
import { IDisposableDataProvider } from 'sql/base/common/dataProvider';
|
||||
@Component({
|
||||
selector: GridOutputComponent.SELECTOR,
|
||||
template: `<div #output class="notebook-cellTable"></div>`
|
||||
@@ -71,7 +72,7 @@ export class GridOutputComponent extends AngularDisposable implements IMimeCompo
|
||||
@Input() set bundleOptions(value: MimeModel.IOptions) {
|
||||
this._bundleOptions = value;
|
||||
if (this._initialized) {
|
||||
this.renderGrid();
|
||||
this.renderGrid().catch(onUnexpectedError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ export class GridOutputComponent extends AngularDisposable implements IMimeCompo
|
||||
@Input() set cellModel(value: ICellModel) {
|
||||
this._cellModel = value;
|
||||
if (this._initialized) {
|
||||
this.renderGrid();
|
||||
this.renderGrid().catch(onUnexpectedError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ export class GridOutputComponent extends AngularDisposable implements IMimeCompo
|
||||
this._cellOutput = value;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
async ngOnInit() {
|
||||
if (this.cellModel) {
|
||||
let outputId: QueryResultId = this.cellModel.getOutputId(this._cellOutput);
|
||||
if (outputId) {
|
||||
@@ -109,10 +110,10 @@ export class GridOutputComponent extends AngularDisposable implements IMimeCompo
|
||||
}
|
||||
}));
|
||||
}
|
||||
this.renderGrid();
|
||||
await this.renderGrid();
|
||||
}
|
||||
|
||||
renderGrid(): void {
|
||||
async renderGrid(): Promise<void> {
|
||||
if (!this._bundleOptions || !this._cellModel || !this.mimeType) {
|
||||
return;
|
||||
}
|
||||
@@ -124,7 +125,7 @@ export class GridOutputComponent extends AngularDisposable implements IMimeCompo
|
||||
let outputElement = <HTMLElement>this.output.nativeElement;
|
||||
outputElement.appendChild(this._table.element);
|
||||
this._register(attachTableStyler(this._table, this.themeService));
|
||||
this._table.onDidInsert();
|
||||
await this._table.onDidInsert();
|
||||
this.layout();
|
||||
this._initialized = true;
|
||||
}
|
||||
@@ -200,9 +201,13 @@ class DataResourceTable extends GridTableBase<any> {
|
||||
@IEditorService editorService: IEditorService,
|
||||
@IUntitledTextEditorService untitledEditorService: IUntitledTextEditorService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@IQueryModelService queryModelService: IQueryModelService
|
||||
@IQueryModelService queryModelService: IQueryModelService,
|
||||
@IThemeService themeService: IThemeService
|
||||
) {
|
||||
super(state, createResultSet(source), { actionOrientation: ActionsOrientation.HORIZONTAL }, contextMenuService, instantiationService, editorService, untitledEditorService, configurationService, queryModelService);
|
||||
super(state, createResultSet(source), {
|
||||
actionOrientation: ActionsOrientation.HORIZONTAL,
|
||||
inMemoryDataProcessing: true
|
||||
}, contextMenuService, instantiationService, editorService, untitledEditorService, configurationService, queryModelService, themeService);
|
||||
this._gridDataProvider = this.instantiationService.createInstance(DataResourceDataProvider, source, this.resultSet, this.cellModel);
|
||||
this._chart = this.instantiationService.createInstance(ChartView, false);
|
||||
|
||||
@@ -352,13 +357,13 @@ export class DataResourceDataProvider implements IGridDataProvider {
|
||||
return Promise.resolve(resultSubset);
|
||||
}
|
||||
|
||||
async copyResults(selection: Slick.Range[], includeHeaders?: boolean): Promise<void> {
|
||||
return this.copyResultsAsync(selection, includeHeaders);
|
||||
async copyResults(selection: Slick.Range[], includeHeaders?: boolean, tableView?: IDisposableDataProvider<Slick.SlickData>): Promise<void> {
|
||||
return this.copyResultsAsync(selection, includeHeaders, tableView);
|
||||
}
|
||||
|
||||
private async copyResultsAsync(selection: Slick.Range[], includeHeaders?: boolean): Promise<void> {
|
||||
private async copyResultsAsync(selection: Slick.Range[], includeHeaders?: boolean, tableView?: IDisposableDataProvider<Slick.SlickData>): Promise<void> {
|
||||
try {
|
||||
let results = await getResultsString(this, selection, includeHeaders);
|
||||
let results = await getResultsString(this, selection, includeHeaders, tableView);
|
||||
this._clipboardService.writeText(results);
|
||||
} catch (error) {
|
||||
this._notificationService.error(localize('copyFailed', "Copy failed with error {0}", getErrorMessage(error)));
|
||||
|
||||
@@ -110,15 +110,10 @@ export class CopyResultAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(context: IGridActionContext): Promise<boolean> {
|
||||
if (this.accountForNumberColumn) {
|
||||
context.gridDataProvider.copyResults(
|
||||
mapForNumberColumn(context.selection),
|
||||
this.copyHeader);
|
||||
} else {
|
||||
context.gridDataProvider.copyResults(context.selection, this.copyHeader);
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
public async run(context: IGridActionContext): Promise<boolean> {
|
||||
const selection = this.accountForNumberColumn ? mapForNumberColumn(context.selection) : context.selection;
|
||||
context.gridDataProvider.copyResults(selection, this.copyHeader, context.table.getData());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
import 'vs/css!./media/gridPanel';
|
||||
|
||||
import { ITableStyles, ITableMouseEvent } from 'sql/base/browser/ui/table/interfaces';
|
||||
import { ITableStyles, ITableMouseEvent, FilterableColumn } from 'sql/base/browser/ui/table/interfaces';
|
||||
import { attachTableStyler } from 'sql/platform/theme/common/styler';
|
||||
import QueryRunner, { QueryGridDataProvider } from 'sql/workbench/services/query/common/queryRunner';
|
||||
import { ResultSetSummary, IColumn } from 'sql/workbench/services/query/common/query';
|
||||
import { VirtualizedCollection, AsyncDataProvider } from 'sql/base/browser/ui/table/asyncDataView';
|
||||
import { ResultSetSummary, IColumn, ICellValue } from 'sql/workbench/services/query/common/query';
|
||||
import { VirtualizedCollection } from 'sql/base/browser/ui/table/asyncDataView';
|
||||
import { Table } from 'sql/base/browser/ui/table/table';
|
||||
import { MouseWheelSupport } from 'sql/base/browser/ui/table/plugins/mousewheelTableScroll.plugin';
|
||||
import { AutoColumnSize } from 'sql/base/browser/ui/table/plugins/autoSizeColumns.plugin';
|
||||
@@ -49,6 +49,9 @@ import { ScrollableView, IView } from 'sql/base/browser/ui/scrollableView/scroll
|
||||
import { IQueryEditorConfiguration } from 'sql/platform/query/common/query';
|
||||
import { Orientation } from 'vs/base/browser/ui/splitview/splitview';
|
||||
import { IQueryModelService } from 'sql/workbench/services/query/common/queryModel';
|
||||
import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
|
||||
import { attachButtonStyler } from 'vs/platform/theme/common/styler';
|
||||
import { HybridDataProvider } from 'sql/base/browser/ui/table/hybridDataProvider';
|
||||
|
||||
const ROW_HEIGHT = 29;
|
||||
const HEADER_HEIGHT = 26;
|
||||
@@ -322,6 +325,8 @@ export interface IDataSet {
|
||||
|
||||
export interface IGridTableOptions {
|
||||
actionOrientation: ActionsOrientation;
|
||||
inMemoryDataProcessing: boolean;
|
||||
inMemoryDataCountThreshold?: number;
|
||||
}
|
||||
|
||||
export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
@@ -331,7 +336,8 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
private selectionModel = new CellSelectionModel<T>();
|
||||
private styles: ITableStyles;
|
||||
private currentHeight: number;
|
||||
private dataProvider: AsyncDataProvider<T>;
|
||||
private dataProvider: HybridDataProvider<T>;
|
||||
private filterPlugin: HeaderFilter<T>;
|
||||
|
||||
private columns: Slick.Column<T>[];
|
||||
|
||||
@@ -369,13 +375,17 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
constructor(
|
||||
state: GridTableState,
|
||||
protected _resultSet: ResultSetSummary,
|
||||
private readonly options: IGridTableOptions = { actionOrientation: ActionsOrientation.VERTICAL },
|
||||
private readonly options: IGridTableOptions = {
|
||||
inMemoryDataProcessing: false,
|
||||
actionOrientation: ActionsOrientation.VERTICAL
|
||||
},
|
||||
@IContextMenuService private readonly contextMenuService: IContextMenuService,
|
||||
@IInstantiationService protected readonly instantiationService: IInstantiationService,
|
||||
@IEditorService private readonly editorService: IEditorService,
|
||||
@IUntitledTextEditorService private readonly untitledEditorService: IUntitledTextEditorService,
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService,
|
||||
@IQueryModelService private readonly queryModelService: IQueryModelService
|
||||
@IQueryModelService private readonly queryModelService: IQueryModelService,
|
||||
@IThemeService private readonly themeService: IThemeService
|
||||
) {
|
||||
super();
|
||||
let config = this.configurationService.getValue<{ rowHeight: number }>('resultsGrid');
|
||||
@@ -405,7 +415,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
return this._resultSet;
|
||||
}
|
||||
|
||||
public onDidInsert() {
|
||||
public async onDidInsert() {
|
||||
if (!this.table) {
|
||||
this.build();
|
||||
}
|
||||
@@ -421,7 +431,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
});
|
||||
this.dataProvider.dataRows = collection;
|
||||
this.table.updateRowCount();
|
||||
this.setupState();
|
||||
await this.setupState();
|
||||
}
|
||||
|
||||
public onDidRemove() {
|
||||
@@ -476,7 +486,15 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
forceFitColumns: false,
|
||||
defaultColumnWidth: 120
|
||||
};
|
||||
this.dataProvider = new AsyncDataProvider(collection);
|
||||
this.dataProvider = new HybridDataProvider(collection,
|
||||
(offset, count) => { return this.loadData(offset, count); },
|
||||
undefined,
|
||||
undefined,
|
||||
(data: ICellValue) => { return data?.displayValue; },
|
||||
{
|
||||
inMemoryDataProcessing: this.options.inMemoryDataProcessing,
|
||||
inMemoryDataCountThreshold: this.options.inMemoryDataCountThreshold
|
||||
});
|
||||
this.table = this._register(new Table(this.tableContainer, { dataProvider: this.dataProvider, columns: this.columns }, tableOptions));
|
||||
this.table.setTableTitle(localize('resultsGrid', "Results grid"));
|
||||
this.table.setSelectionModel(this.selectionModel);
|
||||
@@ -485,11 +503,33 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
this.table.registerPlugin(copyHandler);
|
||||
this.table.registerPlugin(this.rowNumberColumn);
|
||||
this.table.registerPlugin(new AdditionalKeyBindings());
|
||||
this._register(this.dataProvider.onFilterStateChange(() => { this.layout(); }));
|
||||
this._register(this.table.onContextMenu(this.contextMenu, this));
|
||||
this._register(this.table.onClick(this.onTableClick, this));
|
||||
//This listener is used for correcting auto-scroling when clicking on the header for reszing.
|
||||
this._register(this.table.onHeaderClick(this.onHeaderClick, this));
|
||||
|
||||
this._register(this.dataProvider.onFilterStateChange(() => {
|
||||
const columns = this.table.columns as FilterableColumn<T>[];
|
||||
this.state.columnFilters = columns.filter((column) => column.filterValues?.length > 0).map(column => {
|
||||
return {
|
||||
filterValues: column.filterValues,
|
||||
field: column.field
|
||||
};
|
||||
});
|
||||
this.table.rerenderGrid();
|
||||
}));
|
||||
this._register(this.dataProvider.onSortComplete((args: Slick.OnSortEventArgs<T>) => {
|
||||
this.state.sortState = {
|
||||
field: args.sortCol.field,
|
||||
sortAsc: args.sortAsc
|
||||
};
|
||||
this.table.rerenderGrid();
|
||||
}));
|
||||
if (this.configurationService.getValue<boolean>('workbench')['enablePreviewFeatures']) {
|
||||
this.filterPlugin = new HeaderFilter();
|
||||
attachButtonStyler(this.filterPlugin, this.themeService);
|
||||
this.table.registerPlugin(this.filterPlugin);
|
||||
}
|
||||
if (this.styles) {
|
||||
this.table.style(this.styles);
|
||||
}
|
||||
@@ -558,7 +598,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
}
|
||||
}
|
||||
|
||||
private setupState() {
|
||||
private async setupState() {
|
||||
// change actionbar on maximize change
|
||||
this._register(this.state.onMaximizedChange(this.rebuildActionBar, this));
|
||||
|
||||
@@ -578,6 +618,25 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
if (savedSelection) {
|
||||
this.selectionModel.setSelectedRanges(savedSelection);
|
||||
}
|
||||
|
||||
if (this.state.sortState) {
|
||||
await this.dataProvider.sort({
|
||||
multiColumnSort: false,
|
||||
grid: this.table.grid,
|
||||
sortAsc: this.state.sortState.sortAsc,
|
||||
sortCol: this.columns.find((column) => column.field === this.state.sortState.field)
|
||||
});
|
||||
}
|
||||
|
||||
if (this.state.columnFilters) {
|
||||
this.columns.forEach(column => {
|
||||
const idx = this.state.columnFilters.findIndex(filter => filter.field === column.field);
|
||||
if (idx !== -1) {
|
||||
(<FilterableColumn<T>>column).filterValues = this.state.columnFilters[idx].filterValues;
|
||||
}
|
||||
});
|
||||
await this.dataProvider.filter(this.columns);
|
||||
}
|
||||
}
|
||||
|
||||
public get state(): GridTableState {
|
||||
@@ -627,6 +686,9 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
|
||||
public updateResult(resultSet: ResultSetSummary) {
|
||||
this._resultSet = resultSet;
|
||||
if (this.table && this.visible) {
|
||||
if (this.configurationService.getValue<boolean>('workbench')['enablePreviewFeatures'] && this.options.inMemoryDataProcessing && this.options.inMemoryDataCountThreshold < resultSet.rowCount) {
|
||||
this.filterPlugin.enabled = false;
|
||||
}
|
||||
this.dataProvider.length = resultSet.rowCount;
|
||||
this.table.updateRowCount();
|
||||
}
|
||||
@@ -787,9 +849,14 @@ class GridTable<T> extends GridTableBase<T> {
|
||||
@IEditorService editorService: IEditorService,
|
||||
@IUntitledTextEditorService untitledEditorService: IUntitledTextEditorService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@IQueryModelService queryModelService: IQueryModelService
|
||||
@IQueryModelService queryModelService: IQueryModelService,
|
||||
@IThemeService themeService: IThemeService
|
||||
) {
|
||||
super(state, resultSet, undefined, contextMenuService, instantiationService, editorService, untitledEditorService, configurationService, queryModelService);
|
||||
super(state, resultSet, {
|
||||
actionOrientation: ActionsOrientation.VERTICAL,
|
||||
inMemoryDataProcessing: true,
|
||||
inMemoryDataCountThreshold: configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.inMemoryDataProcessingThreshold,
|
||||
}, contextMenuService, instantiationService, editorService, untitledEditorService, configurationService, queryModelService, themeService);
|
||||
this._gridDataProvider = this.instantiationService.createInstance(QueryGridDataProvider, this._runner, resultSet.batchId, resultSet.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -391,6 +391,11 @@ const queryEditorConfiguration: IConfigurationNode = {
|
||||
'description': localize('queryEditor.results.optimizedTable', "(Experimental) Use a optimized table in the results out. Some functionality might be missing and in the works."),
|
||||
'default': false
|
||||
},
|
||||
'queryEditor.results.inMemoryDataProcessingThreshold': {
|
||||
'type': 'number',
|
||||
'default': 2000,
|
||||
'description': localize('queryEditor.inMemoryDataProcessingThreshold', "Controls the max number of rows allowed to do filtering and sorting in memory. If the number is exceeded, sorting and filtering will be disabled.")
|
||||
},
|
||||
'queryEditor.messages.showBatchTime': {
|
||||
'type': 'boolean',
|
||||
'description': localize('queryEditor.messages.showBatchTime', "Should execution time be shown for individual batches"),
|
||||
|
||||
@@ -11,10 +11,10 @@ import { RowSelectionModel } from 'sql/base/browser/ui/table/plugins/rowSelectio
|
||||
|
||||
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { HyperlinkCellValue, isHyperlinkCellValue, TextCellValue } from 'sql/base/browser/ui/table/formatters';
|
||||
import { HeaderFilter, CommandEventArgs, IExtendedColumn } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
|
||||
import { HeaderFilter, CommandEventArgs } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { TableDataView } from 'sql/base/browser/ui/table/tableDataView';
|
||||
import { ITableMouseEvent } from 'sql/base/browser/ui/table/interfaces';
|
||||
import { FilterableColumn, ITableMouseEvent } from 'sql/base/browser/ui/table/interfaces';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { isString } from 'vs/base/common/types';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
@@ -127,7 +127,7 @@ export class ResourceViewerTable extends Disposable {
|
||||
const columns = this._resourceViewerTable.grid.getColumns();
|
||||
let value = true;
|
||||
for (let i = 0; i < columns.length; i++) {
|
||||
const col: IExtendedColumn<Slick.SlickData> = columns[i];
|
||||
const col: FilterableColumn<Slick.SlickData> = columns[i];
|
||||
if (!col.field) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import { Table } from 'sql/base/browser/ui/table/table';
|
||||
import { CopyInsightDialogSelectionAction } from 'sql/workbench/services/insights/browser/insightDialogActions';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService';
|
||||
import { IDisposableDataProvider } from 'sql/base/browser/ui/table/interfaces';
|
||||
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
@@ -50,6 +49,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { IInsightsConfigDetails } from 'sql/platform/extensions/common/extensions';
|
||||
import { attachButtonStyler } from 'vs/platform/theme/common/styler';
|
||||
import { IDisposableDataProvider } from 'sql/base/common/dataProvider';
|
||||
|
||||
const labelDisplay = nls.localize("insights.item", "Item");
|
||||
const valueDisplay = nls.localize("insights.value", "Value");
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import * as types from 'vs/base/common/types';
|
||||
import { SaveFormat } from 'sql/workbench/services/query/common/resultSerializer';
|
||||
import { ResultSetSubset } from 'sql/workbench/services/query/common/query';
|
||||
import { IDisposableDataProvider } from 'sql/base/common/dataProvider';
|
||||
|
||||
export interface IGridDataProvider {
|
||||
|
||||
@@ -19,11 +20,10 @@ export interface IGridDataProvider {
|
||||
/**
|
||||
* Sends a copy request to copy data to the clipboard
|
||||
* @param selection The selection range to copy
|
||||
* @param batchId The batch id of the result to copy from
|
||||
* @param resultId The result id of the result to copy from
|
||||
* @param includeHeaders [Optional]: Should column headers be included in the copy selection
|
||||
* @param tableView [Optional]: The data view associated with the table component
|
||||
*/
|
||||
copyResults(selection: Slick.Range[], includeHeaders?: boolean): Promise<void>;
|
||||
copyResults(selection: Slick.Range[], includeHeaders?: boolean, tableView?: IDisposableDataProvider<Slick.SlickData>): Promise<void>;
|
||||
|
||||
/**
|
||||
* Gets the EOL terminator to use for this data type.
|
||||
@@ -42,7 +42,7 @@ export interface IGridDataProvider {
|
||||
|
||||
}
|
||||
|
||||
export async function getResultsString(provider: IGridDataProvider, selection: Slick.Range[], includeHeaders?: boolean): Promise<string> {
|
||||
export async function getResultsString(provider: IGridDataProvider, selection: Slick.Range[], includeHeaders?: boolean, tableView?: IDisposableDataProvider<Slick.SlickData>): Promise<string> {
|
||||
let headers: Map<number, string> = new Map(); // Maps a column index -> header
|
||||
let rows: Map<number, Map<number, string>> = new Map(); // Maps row index -> column index -> actual row value
|
||||
const eol = provider.getEolString();
|
||||
@@ -52,8 +52,14 @@ export async function getResultsString(provider: IGridDataProvider, selection: S
|
||||
return async (): Promise<void> => {
|
||||
let startCol = range.fromCell;
|
||||
let startRow = range.fromRow;
|
||||
|
||||
const result = await provider.getRowData(range.fromRow, range.toRow - range.fromRow + 1);
|
||||
let result;
|
||||
if (tableView && tableView.isDataInMemory) {
|
||||
// If the data is sorted/filtered in memory, we need to get the data that is currently being displayed
|
||||
const tableData = await tableView.getRangeAsync(range.fromRow, range.toRow - range.fromRow + 1);
|
||||
result = tableData.map(item => Object.keys(item).map(key => item[key]));
|
||||
} else {
|
||||
result = (await provider.getRowData(range.fromRow, range.toRow - range.fromRow + 1)).rows;
|
||||
}
|
||||
// If there was a previous selection separate it with a line break. Currently
|
||||
// when there are multiple selections they are never on the same line
|
||||
let columnHeaders = provider.getColumnHeaders(range);
|
||||
@@ -65,8 +71,8 @@ export async function getResultsString(provider: IGridDataProvider, selection: S
|
||||
}
|
||||
}
|
||||
// Iterate over the rows to paste into the copy string
|
||||
for (let rowIndex: number = 0; rowIndex < result.rows.length; rowIndex++) {
|
||||
let row = result.rows[rowIndex];
|
||||
for (let rowIndex: number = 0; rowIndex < result.length; rowIndex++) {
|
||||
let row = result[rowIndex];
|
||||
let cellObjects = row.slice(range.fromCell, (range.toCell + 1));
|
||||
// Remove newlines if requested
|
||||
let cells = provider.shouldRemoveNewLines()
|
||||
|
||||
@@ -26,6 +26,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IRange, Range } from 'vs/editor/common/core/range';
|
||||
import { BatchSummary, IQueryMessage, ResultSetSummary, QueryExecuteSubsetParams, CompleteBatchSummary, IResultMessage, ResultSetSubset, BatchStartSummary } from './query';
|
||||
import { IQueryEditorConfiguration } from 'sql/platform/query/common/query';
|
||||
import { IDisposableDataProvider } from 'sql/base/common/dataProvider';
|
||||
|
||||
/*
|
||||
* Query Runner class which handles running a query, reports the results to the content manager,
|
||||
@@ -501,18 +502,19 @@ export class QueryGridDataProvider implements IGridDataProvider {
|
||||
return this.queryRunner.getQueryRows(rowStart, numberOfRows, this.batchId, this.resultSetId);
|
||||
}
|
||||
|
||||
copyResults(selection: Slick.Range[], includeHeaders?: boolean): Promise<void> {
|
||||
return this.copyResultsAsync(selection, includeHeaders);
|
||||
copyResults(selection: Slick.Range[], includeHeaders?: boolean, tableView?: IDisposableDataProvider<Slick.SlickData>): Promise<void> {
|
||||
return this.copyResultsAsync(selection, includeHeaders, tableView);
|
||||
}
|
||||
|
||||
private async copyResultsAsync(selection: Slick.Range[], includeHeaders?: boolean): Promise<void> {
|
||||
private async copyResultsAsync(selection: Slick.Range[], includeHeaders?: boolean, tableView?: IDisposableDataProvider<Slick.SlickData>): Promise<void> {
|
||||
try {
|
||||
let results = await getResultsString(this, selection, includeHeaders);
|
||||
const results = await getResultsString(this, selection, includeHeaders, tableView);
|
||||
await this._clipboardService.writeText(results);
|
||||
} catch (error) {
|
||||
this._notificationService.error(nls.localize('copyFailed', "Copy failed with error {0}", getErrorMessage(error)));
|
||||
}
|
||||
}
|
||||
|
||||
getEolString(): string {
|
||||
return getEolString(this._textResourcePropertiesService, this.queryRunner.uri);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user