mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 17:22:45 -05:00
Table Designer - Save Changes feature and Editor related features (#17335)
* table designer add/remove row support * save changes and editor support * address comments * fix build error * including missing change * lower case request name
This commit is contained in:
@@ -4,18 +4,39 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { DesignerData, DesignerEdit, DesignerEditResult, DesignerComponentInput, DesignerView, DesignerTab, DesignerDataPropertyInfo, DropDownProperties, DesignerTableProperties } from 'sql/base/browser/ui/designer/interfaces';
|
||||
import { DesignerData, DesignerEdit, DesignerEditResult, DesignerComponentInput, DesignerView, DesignerTab, DesignerDataPropertyInfo, DropDownProperties, DesignerTableProperties, DesignerState } from 'sql/base/browser/ui/designer/interfaces';
|
||||
import { TableDesignerProvider } from 'sql/workbench/services/tableDesigner/common/interface';
|
||||
import { localize } from 'vs/nls';
|
||||
import { designers } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
||||
|
||||
export class TableDesignerComponentInput implements DesignerComponentInput {
|
||||
|
||||
private _data: DesignerData;
|
||||
private _view: DesignerView;
|
||||
private _valid: boolean = true;
|
||||
private _dirty: boolean = false;
|
||||
private _saving: boolean = false;
|
||||
private _onStateChange = new Emitter<DesignerState>();
|
||||
|
||||
public readonly onStateChange: Event<DesignerState> = this._onStateChange.event;
|
||||
|
||||
constructor(private readonly _provider: TableDesignerProvider,
|
||||
private _tableInfo: azdata.designers.TableInfo) {
|
||||
private _tableInfo: azdata.designers.TableInfo,
|
||||
@INotificationService private readonly _notificationService: INotificationService) {
|
||||
}
|
||||
|
||||
get valid(): boolean {
|
||||
return this._valid;
|
||||
}
|
||||
|
||||
get dirty(): boolean {
|
||||
return this._dirty;
|
||||
}
|
||||
|
||||
get saving(): boolean {
|
||||
return this._saving;
|
||||
}
|
||||
|
||||
get objectTypeDisplayName(): string {
|
||||
@@ -41,12 +62,47 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
|
||||
if (result.isValid) {
|
||||
this._data = result.data;
|
||||
}
|
||||
this.updateState(result.isValid, true, this.saving);
|
||||
return {
|
||||
isValid: result.isValid,
|
||||
errors: result.errors
|
||||
};
|
||||
}
|
||||
|
||||
async save(): Promise<void> {
|
||||
const notificationHandle = this._notificationService.notify({
|
||||
severity: Severity.Info,
|
||||
message: localize('tableDesigner.savingChanges', "Saving table designer changes...")
|
||||
});
|
||||
try {
|
||||
this.updateState(this.valid, this.dirty, true);
|
||||
await this._provider.saveTable(this._tableInfo, this._data);
|
||||
this.updateState(true, false, false);
|
||||
notificationHandle.updateMessage(localize('tableDesigner.savedChangeSuccess', "The changes have been successfully saved."));
|
||||
} catch (error) {
|
||||
notificationHandle.updateSeverity(Severity.Error);
|
||||
notificationHandle.updateMessage(localize('tableDesigner.saveChangeError', "An error occured while saving changes: {0}", error?.message ?? error));
|
||||
this.updateState(this.valid, this.dirty, false);
|
||||
}
|
||||
}
|
||||
|
||||
async revert(): Promise<void> {
|
||||
this.updateState(true, false, false);
|
||||
}
|
||||
|
||||
private updateState(valid: boolean, dirty: boolean, saving: boolean): void {
|
||||
if (this._dirty !== dirty || this._valid !== valid || this._saving !== saving) {
|
||||
this._dirty = dirty;
|
||||
this._valid = valid;
|
||||
this._saving = saving;
|
||||
this._onStateChange.fire({
|
||||
valid: this._valid,
|
||||
dirty: this._dirty,
|
||||
saving: this._saving
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async initialize(): Promise<void> {
|
||||
const designerInfo = await this._provider.getTableDesignerInfo(this._tableInfo);
|
||||
|
||||
@@ -115,6 +171,12 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
|
||||
componentProperties: {
|
||||
title: localize('tableDesigner.columnAllowNullTitle', "Allow Nulls"),
|
||||
}
|
||||
}, {
|
||||
componentType: 'checkbox',
|
||||
propertyName: designers.TableColumnProperty.IsPrimaryKey,
|
||||
componentProperties: {
|
||||
title: localize('tableDesigner.columnIsPrimaryKeyTitle', "Primary Key"),
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -135,7 +197,8 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
|
||||
designers.TableColumnProperty.Type,
|
||||
designers.TableColumnProperty.Length,
|
||||
designers.TableColumnProperty.DefaultValue,
|
||||
designers.TableColumnProperty.AllowNulls
|
||||
designers.TableColumnProperty.AllowNulls,
|
||||
designers.TableColumnProperty.IsPrimaryKey
|
||||
],
|
||||
itemProperties: columnProperties,
|
||||
objectTypeDisplayName: localize('tableDesigner.columnTypeName', "Column")
|
||||
|
||||
@@ -8,10 +8,12 @@ import { invalidProvider } from 'sql/base/common/errors';
|
||||
import * as azdata from 'azdata';
|
||||
import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { TableDesignerInput } from 'sql/workbench/browser/editor/tableDesigner/tableDesignerInput';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export class TableDesignerService implements ITableDesignerService {
|
||||
|
||||
constructor(@IEditorService private _editorService: IEditorService) { }
|
||||
constructor(@IEditorService private _editorService: IEditorService,
|
||||
@IInstantiationService private _instantiationService: IInstantiationService) { }
|
||||
|
||||
public _serviceBrand: undefined;
|
||||
private _providers = new Map<string, TableDesignerProvider>();
|
||||
@@ -40,7 +42,7 @@ export class TableDesignerService implements ITableDesignerService {
|
||||
|
||||
public async openTableDesigner(providerId: string, tableInfo: azdata.designers.TableInfo): Promise<void> {
|
||||
const provider = this.getProvider(providerId);
|
||||
const tableDesignerInput = new TableDesignerInput(provider, tableInfo);
|
||||
const tableDesignerInput = this._instantiationService.createInstance(TableDesignerInput, provider, tableInfo);
|
||||
await this._editorService.openEditor(tableDesignerInput, { pinned: true }, ACTIVE_GROUP);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user