respect include header option (#17134)

* respect include header option

* use correct option for copying

* check for setting when copying

* add dependency injection

* use instantiation service

Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
Aditya Bist
2021-11-01 12:36:19 -07:00
committed by GitHub
parent 9bbe39e9e2
commit 6dda9392e0
4 changed files with 28 additions and 26 deletions

View File

@@ -8,6 +8,8 @@ import { DataService } from 'sql/workbench/services/query/common/dataService';
import { GridActionProvider } from 'sql/workbench/contrib/editData/browser/gridActions';
import { localize } from 'vs/nls';
import { IAction, Action } from 'vs/base/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
export class EditDataGridActionProvider extends GridActionProvider {
@@ -15,9 +17,11 @@ export class EditDataGridActionProvider extends GridActionProvider {
dataService: DataService,
selectAllCallback: (index: number) => void,
private _deleteRowCallback: (index: number) => void,
private _revertRowCallback: () => void
private _revertRowCallback: () => void,
@IConfigurationService configurationService: IConfigurationService,
@IInstantiationService instantiationService: IInstantiationService
) {
super(dataService, selectAllCallback);
super(dataService, selectAllCallback, instantiationService, configurationService);
}
/**
* Return actions given a click on an edit data grid

View File

@@ -9,6 +9,8 @@ import { DataService } from 'sql/workbench/services/query/common/dataService';
import { localize } from 'vs/nls';
import { IAction, Action } from 'vs/base/common/actions';
import { SaveFormat } from 'sql/workbench/services/query/common/resultSerializer';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
export const GRID_SAVECSV_ID = 'grid.saveAsCsv';
export const GRID_SAVEJSON_ID = 'grid.saveAsJson';
@@ -30,7 +32,9 @@ export class GridActionProvider {
constructor(
protected _dataService: DataService,
protected _selectAllCallback: (index: number) => void
protected _selectAllCallback: (index: number) => void,
@IInstantiationService protected _instantiationService: IInstantiationService,
@IConfigurationService protected _configurationService: IConfigurationService,
) {
}
@@ -40,13 +44,13 @@ export class GridActionProvider {
*/
public getGridActions(): IAction[] {
const actions: IAction[] = [];
actions.push(new SaveResultAction(SaveResultAction.SAVECSV_ID, SaveResultAction.SAVECSV_LABEL, SaveFormat.CSV, this._dataService));
actions.push(new SaveResultAction(SaveResultAction.SAVEJSON_ID, SaveResultAction.SAVEJSON_LABEL, SaveFormat.JSON, this._dataService));
actions.push(new SaveResultAction(SaveResultAction.SAVEEXCEL_ID, SaveResultAction.SAVEEXCEL_LABEL, SaveFormat.EXCEL, this._dataService));
actions.push(new SaveResultAction(SaveResultAction.SAVEXML_ID, SaveResultAction.SAVEXML_LABEL, SaveFormat.XML, this._dataService));
actions.push(new SelectAllGridAction(SelectAllGridAction.ID, SelectAllGridAction.LABEL, this._selectAllCallback));
actions.push(new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false, this._dataService));
actions.push(new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true, this._dataService));
actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVECSV_ID, SaveResultAction.SAVECSV_LABEL, SaveFormat.CSV, this._dataService));
actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVEJSON_ID, SaveResultAction.SAVEJSON_LABEL, SaveFormat.JSON, this._dataService));
actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVEEXCEL_ID, SaveResultAction.SAVEEXCEL_LABEL, SaveFormat.EXCEL, this._dataService));
actions.push(this._instantiationService.createInstance(SaveResultAction, SaveResultAction.SAVEXML_ID, SaveResultAction.SAVEXML_LABEL, SaveFormat.XML, this._dataService));
actions.push(this._instantiationService.createInstance(SelectAllGridAction, SelectAllGridAction.ID, SelectAllGridAction.LABEL, this._selectAllCallback));
actions.push(this._instantiationService.createInstance(CopyResultAction, CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false, this._dataService));
actions.push(this._instantiationService.createInstance(CopyResultAction, CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true, this._dataService));
return actions;
}
@@ -95,13 +99,15 @@ class CopyResultAction extends Action {
id: string,
label: string,
private copyHeader: boolean,
private dataService: DataService
private dataService: DataService,
@IConfigurationService private configurationService: IConfigurationService
) {
super(id, label);
}
public override async run(gridInfo: IGridInfo): Promise<void> {
this.dataService.copyResults(gridInfo.selection, gridInfo.batchIndex, gridInfo.resultSetNumber, this.copyHeader);
const includeHeader = this.configurationService.getValue<boolean>('queryEditor.results.copyIncludeHeaders') || this.copyHeader;
this.dataService.copyResults(gridInfo.selection, gridInfo.batchIndex, gridInfo.resultSetNumber, includeHeader);
}
}

View File

@@ -105,6 +105,7 @@ export class CopyResultAction extends Action {
constructor(
id: string,
label: string,
private configurationService: IConfigurationService,
private copyHeader: boolean,
private accountForNumberColumn = true
) {
@@ -113,7 +114,8 @@ export class CopyResultAction extends Action {
public override async run(context: IGridActionContext): Promise<void> {
const selection = this.accountForNumberColumn ? mapForNumberColumn(context.selection) : context.selection;
await context.gridDataProvider.copyResults(selection, this.copyHeader, context.table.getData());
const includeHeader = this.configurationService.getValue<boolean>('queryEditor.results.copyIncludeHeaders') || this.copyHeader;
await context.gridDataProvider.copyResults(selection, includeHeader, context.table.getData());
}
}

View File

@@ -388,7 +388,6 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
super();
this.options = { ...defaultGridTableOptions, ...options };
let config = this.configurationService.getValue<{ rowHeight: number }>('resultsGrid');
this.rowHeight = config && config.rowHeight ? config.rowHeight : ROW_HEIGHT;
this.state = state;
@@ -479,7 +478,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
this.rowNumberColumn = new RowNumberColumn({ numberOfRows: this.resultSet.rowCount });
let copyHandler = new CopyKeybind<T>();
copyHandler.onCopy(e => {
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false).run(this.generateContext());
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, this.configurationService, false).run(this.generateContext());
});
this.columns.unshift(this.rowNumberColumn.getColumnDefinition());
let tableOptions: Slick.GridOptions<T> = {
@@ -815,8 +814,8 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
actions.push(new Separator());
}
actions.push(
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false),
new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, true)
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, this.configurationService, false),
new CopyResultAction(CopyResultAction.COPYWITHHEADERS_ID, CopyResultAction.COPYWITHHEADERS_LABEL, this.configurationService, true)
);
if (this.state.canBeMaximized) {
@@ -840,16 +839,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
}
private renderGridDataRowsRange(startIndex: number, count: number): void {
// let editor = this.table.getCellEditor();
// let oldValue = editor ? editor.getValue() : undefined;
// let wasValueChanged = editor ? editor.isValueChanged() : false;
this.invalidateRange(startIndex, startIndex + count);
// let activeCell = this._grid.getActiveCell();
// if (editor && activeCell.row >= startIndex && activeCell.row < startIndex + count) {
// if (oldValue && wasValueChanged) {
// editor.setValue(oldValue);
// }
// }
}
private invalidateRange(start: number, end: number): void {