mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
Add Data Grid Provider API (#12097)
* Add RegisterResourceDataProvider API * Change to data grid provider * fixes * updates
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||
import { IDataGridProviderService } from 'sql/workbench/services/dataGridProvider/common/dataGridProviderService';
|
||||
import { invalidProvider } from 'sql/base/common/errors';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/common/telemetryKeys';
|
||||
|
||||
export class DataGridProviderService implements IDataGridProviderService {
|
||||
|
||||
public _serviceBrand: undefined;
|
||||
private _providers = new Map<string, azdata.DataGridProvider>();
|
||||
|
||||
constructor(
|
||||
@IAdsTelemetryService private _telemetryService: IAdsTelemetryService
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Register a data grid provider
|
||||
*/
|
||||
public registerProvider(providerId: string, provider: azdata.DataGridProvider): void {
|
||||
if (this._providers.has(providerId)) {
|
||||
throw new Error(`A DataGridProvider with id "${providerId}" is already registered`);
|
||||
}
|
||||
this._providers.set(providerId, provider);
|
||||
}
|
||||
|
||||
public unregisterProvider(providerId: string): void {
|
||||
this._providers.delete(providerId);
|
||||
}
|
||||
|
||||
public async getDataGridItems(providerId: string): Promise<azdata.DataGridItem[]> {
|
||||
const provider = this._providers.get(providerId);
|
||||
if (provider) {
|
||||
this._telemetryService.createActionEvent(TelemetryKeys.TelemetryView.Shell, TelemetryKeys.GetDataGridItems)
|
||||
.withAdditionalProperties({
|
||||
provider: providerId
|
||||
}).send();
|
||||
return provider.getDataGridItems();
|
||||
}
|
||||
throw invalidProvider(providerId);
|
||||
}
|
||||
|
||||
public async getDataGridColumns(providerId: string): Promise<azdata.DataGridColumn[]> {
|
||||
const provider = this._providers.get(providerId);
|
||||
if (provider) {
|
||||
this._telemetryService.createActionEvent(TelemetryKeys.TelemetryView.Shell, TelemetryKeys.GetDataGridColumns)
|
||||
.withAdditionalProperties({
|
||||
provider: providerId
|
||||
}).send();
|
||||
return provider.getDataGridColumns();
|
||||
}
|
||||
throw invalidProvider(providerId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export const SERVICE_ID = 'dataGridProviderService';
|
||||
export const IDataGridProviderService = createDecorator<IDataGridProviderService>(SERVICE_ID);
|
||||
|
||||
export interface IDataGridProviderService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
/**
|
||||
* Register a data grid provider
|
||||
*/
|
||||
registerProvider(providerId: string, provider: azdata.DataGridProvider): void;
|
||||
|
||||
/**
|
||||
* Unregister a resource data provider
|
||||
*/
|
||||
unregisterProvider(providerId: string): void;
|
||||
|
||||
/**
|
||||
* Gets a list of data grid items from the specified provider
|
||||
*/
|
||||
getDataGridItems(providerId: string): Promise<azdata.DataGridItem[]>;
|
||||
|
||||
/**
|
||||
* Gets a list of data grid columns from the specified provider
|
||||
*/
|
||||
getDataGridColumns(providerId: string): Promise<azdata.DataGridColumn[]>;
|
||||
}
|
||||
Reference in New Issue
Block a user