mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 17:23:40 -05:00
Inital platform relayering (#6385)
* moving test files and inital refactoring * relayer extension host code * fix imports * make insights work * relayer dashboard * relayer notebooks * moveing more code around * formatting * accept angular as browser * fix serializer * add missing files * remove declarations from extensions * fix build errors * more relayering * change urls to relative to help code relayering * remove layering to prep for merge * fix hygiene errors * fix hygiene errors * fix tests
This commit is contained in:
183
src/sql/platform/dashboard/browser/dashboardRegistry.ts
Normal file
183
src/sql/platform/dashboard/browser/dashboardRegistry.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IConfigurationRegistry, Extensions as ConfigurationExtension } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
|
||||
import * as nls from 'vs/nls';
|
||||
import { IExtensionPointUser, ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||
|
||||
import { ProviderProperties } from 'sql/workbench/parts/dashboard/browser/widgets/properties/propertiesWidget.component';
|
||||
import { DATABASE_DASHBOARD_TABS } from 'sql/workbench/parts/dashboard/browser/pages/databaseDashboardPage.contribution';
|
||||
import { SERVER_DASHBOARD_TABS } from 'sql/workbench/parts/dashboard/browser/pages/serverDashboardPage.contribution';
|
||||
import { DASHBOARD_CONFIG_ID, DASHBOARD_TABS_KEY_PROPERTY } from 'sql/workbench/parts/dashboard/browser/pages/dashboardPageContribution';
|
||||
|
||||
export const Extensions = {
|
||||
DashboardContributions: 'dashboard.contributions'
|
||||
};
|
||||
|
||||
export interface IDashboardTab {
|
||||
id: string;
|
||||
title: string;
|
||||
provider: string | string[];
|
||||
publisher: string;
|
||||
description?: string;
|
||||
container?: object;
|
||||
when?: string;
|
||||
alwaysShow?: boolean;
|
||||
isHomeTab?: boolean;
|
||||
}
|
||||
|
||||
export interface IDashboardRegistry {
|
||||
registerDashboardProvider(id: string, properties: ProviderProperties): void;
|
||||
getProperties(id: string): ProviderProperties;
|
||||
registerTab(tab: IDashboardTab): void;
|
||||
tabs: Array<IDashboardTab>;
|
||||
}
|
||||
|
||||
class DashboardRegistry implements IDashboardRegistry {
|
||||
private _properties = new Map<string, ProviderProperties>();
|
||||
private _tabs = new Array<IDashboardTab>();
|
||||
private _configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtension.Configuration);
|
||||
private _dashboardTabContentSchemaProperties: IJSONSchemaMap = {};
|
||||
|
||||
/**
|
||||
* Register a dashboard widget
|
||||
* @param id id of the widget
|
||||
*/
|
||||
public registerDashboardProvider(id: string, properties: ProviderProperties): void {
|
||||
this._properties.set(id, properties);
|
||||
}
|
||||
|
||||
public getProperties(id: string): ProviderProperties {
|
||||
return this._properties.get(id);
|
||||
}
|
||||
|
||||
public registerTab(tab: IDashboardTab): void {
|
||||
this._tabs.push(tab);
|
||||
let dashboardConfig = this._configurationRegistry.getConfigurations().find(c => c.id === DASHBOARD_CONFIG_ID);
|
||||
|
||||
if (dashboardConfig) {
|
||||
let dashboardDatabaseTabProperty = (<IJSONSchema>dashboardConfig.properties[DATABASE_DASHBOARD_TABS].items).properties[DASHBOARD_TABS_KEY_PROPERTY];
|
||||
dashboardDatabaseTabProperty.enum.push(tab.id);
|
||||
dashboardDatabaseTabProperty.enumDescriptions.push(tab.description || '');
|
||||
|
||||
let dashboardServerTabProperty = (<IJSONSchema>dashboardConfig.properties[SERVER_DASHBOARD_TABS].items).properties[DASHBOARD_TABS_KEY_PROPERTY];
|
||||
dashboardServerTabProperty.enum.push(tab.id);
|
||||
dashboardServerTabProperty.enumDescriptions.push(tab.description || '');
|
||||
|
||||
this._configurationRegistry.notifyConfigurationSchemaUpdated(dashboardConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public get tabs(): Array<IDashboardTab> {
|
||||
return this._tabs;
|
||||
}
|
||||
}
|
||||
|
||||
const dashboardRegistry = new DashboardRegistry();
|
||||
Registry.add(Extensions.DashboardContributions, dashboardRegistry);
|
||||
|
||||
export function registerTab(tab: IDashboardTab): void {
|
||||
dashboardRegistry.registerTab(tab);
|
||||
}
|
||||
|
||||
const dashboardPropertiesPropertyContrib: IJSONSchema = {
|
||||
description: nls.localize('dashboard.properties.property', "Defines a property to show on the dashboard"),
|
||||
type: 'object',
|
||||
properties: {
|
||||
displayName: {
|
||||
description: nls.localize('dashboard.properties.property.displayName', "What value to use as a label for the property"),
|
||||
type: 'string'
|
||||
},
|
||||
value: {
|
||||
description: nls.localize('dashboard.properties.property.value', "What value in the object to access for the value"),
|
||||
type: 'string'
|
||||
},
|
||||
ignore: {
|
||||
description: nls.localize('dashboard.properties.property.ignore', "Specify values to be ignored"),
|
||||
type: 'array',
|
||||
items: { type: 'string' }
|
||||
},
|
||||
default: {
|
||||
description: nls.localize('dashboard.properties.property.default', "Default value to show if ignored or no value"),
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const dashboardPropertyFlavorContrib: IJSONSchema = {
|
||||
description: nls.localize('dashboard.properties.flavor', "A flavor for defining dashboard properties"),
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
description: nls.localize('dashboard.properties.flavor.id', 'Id of the flavor'),
|
||||
type: 'string'
|
||||
},
|
||||
condition: {
|
||||
description: nls.localize('dashboard.properties.flavor.condition', "Condition to use this flavor"),
|
||||
type: 'object',
|
||||
properties: {
|
||||
field: {
|
||||
description: nls.localize('dashboard.properties.flavor.condition.field', "Field to compare to"),
|
||||
type: 'string'
|
||||
},
|
||||
operator: {
|
||||
description: nls.localize('dashboard.properties.flavor.condition.operator', "Which operator to use for comparison"),
|
||||
type: 'string',
|
||||
enum: ['==', '<=', '>=', '!=']
|
||||
},
|
||||
value: {
|
||||
description: nls.localize('dashboard.properties.flavor.condition.value', "Value to compare the field to"),
|
||||
type: ['string', 'boolean']
|
||||
}
|
||||
}
|
||||
},
|
||||
databaseProperties: {
|
||||
description: nls.localize('dashboard.properties.databaseProperties', "Properties to show for database page"),
|
||||
type: 'array',
|
||||
items: dashboardPropertiesPropertyContrib
|
||||
},
|
||||
serverProperties: {
|
||||
description: nls.localize('dashboard.properties.serverProperties', "Properties to show for server page"),
|
||||
type: 'array',
|
||||
items: dashboardPropertiesPropertyContrib
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const dashboardContrib: IJSONSchema = {
|
||||
description: nls.localize('carbon.extension.dashboard', "Defines that this provider supports the dashboard"),
|
||||
type: 'object',
|
||||
properties: {
|
||||
provider: {
|
||||
description: nls.localize('dashboard.id', "Provider id (ex. MSSQL)"),
|
||||
type: 'string'
|
||||
},
|
||||
flavors: {
|
||||
description: nls.localize('dashboard.properties', "Property values to show on dashboard"),
|
||||
type: 'array',
|
||||
items: dashboardPropertyFlavorContrib
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ExtensionsRegistry.registerExtensionPoint<ProviderProperties | ProviderProperties[]>({ extensionPoint: 'dashboard', jsonSchema: dashboardContrib }).setHandler(extensions => {
|
||||
|
||||
function handleCommand(contrib: ProviderProperties, extension: IExtensionPointUser<any>) {
|
||||
dashboardRegistry.registerDashboardProvider(contrib.provider, contrib);
|
||||
}
|
||||
|
||||
for (let extension of extensions) {
|
||||
const { value } = extension;
|
||||
if (Array.isArray<ProviderProperties>(value)) {
|
||||
for (let command of value) {
|
||||
handleCommand(command, extension);
|
||||
}
|
||||
} else {
|
||||
handleCommand(value, extension);
|
||||
}
|
||||
}
|
||||
});
|
||||
126
src/sql/platform/dashboard/browser/insightRegistry.ts
Normal file
126
src/sql/platform/dashboard/browser/insightRegistry.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Type } from '@angular/core';
|
||||
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||
import * as nls from 'vs/nls';
|
||||
import { IInsightData } from 'sql/workbench/parts/charts/browser/interfaces';
|
||||
|
||||
export type InsightIdentifier = string;
|
||||
|
||||
export const Extensions = {
|
||||
InsightContribution: 'dashboard.contributions.insights'
|
||||
};
|
||||
|
||||
export interface IInsightsConfig {
|
||||
cacheId?: string;
|
||||
type: any;
|
||||
name?: string;
|
||||
when?: string;
|
||||
gridItemConfig?: ISize;
|
||||
query?: string | Array<string>;
|
||||
queryFile?: string;
|
||||
details?: IInsightsConfigDetails;
|
||||
autoRefreshInterval?: number;
|
||||
}
|
||||
|
||||
export interface IInsightsLabel {
|
||||
column: string;
|
||||
icon?: string;
|
||||
state?: Array<IStateCondition>;
|
||||
}
|
||||
|
||||
export interface IStateCondition {
|
||||
condition: {
|
||||
if: string,
|
||||
equals?: string
|
||||
};
|
||||
color?: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface IInsightsConfigDetails {
|
||||
query?: string | Array<string>;
|
||||
queryFile?: string;
|
||||
label?: string | IInsightsLabel;
|
||||
value?: string;
|
||||
actions?: {
|
||||
types: Array<string>;
|
||||
database?: string;
|
||||
server?: string;
|
||||
user?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ISize {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export interface IInsightsView {
|
||||
data: IInsightData;
|
||||
setConfig?: (config: { [key: string]: any }) => void;
|
||||
init?: () => void;
|
||||
}
|
||||
|
||||
export interface IInsightRegistry {
|
||||
insightSchema: IJSONSchema;
|
||||
registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier;
|
||||
registerExtensionInsight(id: string, val: IInsightsConfig): void;
|
||||
getRegisteredExtensionInsights(id: string): IInsightsConfig;
|
||||
getCtorFromId(id: string): Type<IInsightsView>;
|
||||
getAllCtors(): Array<Type<IInsightsView>>;
|
||||
getAllIds(): Array<string>;
|
||||
}
|
||||
|
||||
class InsightRegistry implements IInsightRegistry {
|
||||
private _insightSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets.InsightsRegistry', 'Widget used in the dashboards'), properties: {}, additionalProperties: false };
|
||||
private _extensionInsights: { [x: string]: IInsightsConfig } = {};
|
||||
private _idToCtor: { [x: string]: Type<IInsightsView> } = {};
|
||||
|
||||
/**
|
||||
* Register a dashboard widget
|
||||
* @param id id of the widget
|
||||
* @param description description of the widget
|
||||
* @param schema config schema of the widget
|
||||
*/
|
||||
public registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier {
|
||||
this._insightSchema.properties[id] = schema;
|
||||
this._idToCtor[id] = ctor;
|
||||
return id;
|
||||
}
|
||||
|
||||
public registerExtensionInsight(id: string, val: IInsightsConfig): void {
|
||||
this._extensionInsights[id] = val;
|
||||
}
|
||||
|
||||
public getRegisteredExtensionInsights(id: string): IInsightsConfig {
|
||||
return this._extensionInsights[id];
|
||||
}
|
||||
|
||||
public getCtorFromId(id: string): Type<IInsightsView> {
|
||||
return this._idToCtor[id];
|
||||
}
|
||||
|
||||
public getAllCtors(): Array<Type<IInsightsView>> {
|
||||
return Object.values(this._idToCtor);
|
||||
}
|
||||
|
||||
public getAllIds(): Array<string> {
|
||||
return Object.keys(this._idToCtor);
|
||||
}
|
||||
|
||||
public get insightSchema(): IJSONSchema {
|
||||
return this._insightSchema;
|
||||
}
|
||||
}
|
||||
|
||||
const insightRegistry = new InsightRegistry();
|
||||
platform.Registry.add(Extensions.InsightContribution, insightRegistry);
|
||||
|
||||
export function registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier {
|
||||
return insightRegistry.registerInsight(id, description, schema, ctor);
|
||||
}
|
||||
63
src/sql/platform/dashboard/browser/modelComponentRegistry.ts
Normal file
63
src/sql/platform/dashboard/browser/modelComponentRegistry.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Type } from '@angular/core';
|
||||
import { ModelComponentTypes } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
import { IComponent } from 'sql/workbench/browser/modelComponents/interfaces';
|
||||
|
||||
export type ComponentIdentifier = string;
|
||||
|
||||
export const Extensions = {
|
||||
ComponentContribution: 'dashboard.contributions.components'
|
||||
};
|
||||
|
||||
export interface IComponentRegistry {
|
||||
registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: Type<IComponent>): ComponentIdentifier;
|
||||
getIdForTypeMapping(typeMapping: ModelComponentTypes): string;
|
||||
getCtorForType(typeMapping: ModelComponentTypes): Type<IComponent>;
|
||||
getCtorFromId(id: string): Type<IComponent>;
|
||||
getAllCtors(): Array<Type<IComponent>>;
|
||||
getAllIds(): Array<string>;
|
||||
}
|
||||
|
||||
class ComponentRegistry implements IComponentRegistry {
|
||||
private _idToCtor: { [x: string]: Type<IComponent> } = {};
|
||||
private _typeNameToId: { [x: string]: string } = {};
|
||||
|
||||
registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: Type<IComponent>): string {
|
||||
this._idToCtor[id] = ctor;
|
||||
this._typeNameToId[ModelComponentTypes[typeMapping]] = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public getIdForTypeMapping(typeMapping: ModelComponentTypes): string {
|
||||
return this._typeNameToId[ModelComponentTypes[typeMapping]];
|
||||
}
|
||||
|
||||
public getCtorForType(typeMapping: ModelComponentTypes): Type<IComponent> {
|
||||
let id = this.getIdForTypeMapping(typeMapping);
|
||||
return id ? this._idToCtor[id] : undefined;
|
||||
}
|
||||
public getCtorFromId(id: string): Type<IComponent> {
|
||||
return this._idToCtor[id];
|
||||
}
|
||||
|
||||
public getAllCtors(): Array<Type<IComponent>> {
|
||||
return Object.values(this._idToCtor);
|
||||
}
|
||||
|
||||
public getAllIds(): Array<string> {
|
||||
return Object.keys(this._idToCtor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const componentRegistry = new ComponentRegistry();
|
||||
platform.Registry.add(Extensions.ComponentContribution, componentRegistry);
|
||||
|
||||
export function registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: Type<IComponent>): ComponentIdentifier {
|
||||
return componentRegistry.registerComponentType(id, typeMapping, ctor);
|
||||
}
|
||||
112
src/sql/platform/dashboard/browser/widgetRegistry.ts
Normal file
112
src/sql/platform/dashboard/browser/widgetRegistry.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
|
||||
import * as nls from 'vs/nls';
|
||||
import { IInsightsConfig } from 'sql/platform/dashboard/browser/insightRegistry';
|
||||
|
||||
export type WidgetIdentifier = string;
|
||||
|
||||
export const Extensions = {
|
||||
DashboardWidgetContribution: 'dashboard.contributions.widgets'
|
||||
};
|
||||
|
||||
export interface IDashboardRegistryOptions {
|
||||
extensionOnly: boolean;
|
||||
}
|
||||
|
||||
export interface CustomIJSONSchema extends IJSONSchema {
|
||||
extensionProperties: IJSONSchemaMap;
|
||||
}
|
||||
|
||||
export interface IDashboardWidgetRegistry {
|
||||
databaseWidgetSchema: CustomIJSONSchema;
|
||||
serverWidgetSchema: CustomIJSONSchema;
|
||||
allSchema: CustomIJSONSchema;
|
||||
registerWidget(id: string, description: string, schema: IJSONSchema, context?: 'database' | 'server'): WidgetIdentifier;
|
||||
registerNonCustomDashboardWidget(id: string, description: string, val: IInsightsConfig, context?: 'database' | 'server', options?: IDashboardRegistryOptions): WidgetIdentifier;
|
||||
}
|
||||
|
||||
class DashboardWidgetRegistry implements IDashboardWidgetRegistry {
|
||||
private _allSchema: CustomIJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets.all', 'Widget used in the dashboards'), properties: {}, extensionProperties: {}, additionalProperties: false };
|
||||
private _dashboardWidgetSchema: CustomIJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets.database', 'Widget used in the dashboards'), properties: {}, extensionProperties: {}, additionalProperties: false };
|
||||
private _serverWidgetSchema: CustomIJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets.server', 'Widget used in the dashboards'), properties: {}, extensionProperties: {}, additionalProperties: false };
|
||||
|
||||
/**
|
||||
* Register a dashboard widget
|
||||
* @param id id of the widget
|
||||
* @param description description of the widget
|
||||
* @param schema config schema of the widget
|
||||
* @param context either 'database' or 'server' for what page to register for; if not specified, will register for both
|
||||
*/
|
||||
public registerWidget(id: string, description: string, schema: IJSONSchema, context?: 'database' | 'server', options?: IDashboardRegistryOptions): WidgetIdentifier {
|
||||
if (options && options.extensionOnly) {
|
||||
if (context === undefined || context === 'database') {
|
||||
this._dashboardWidgetSchema.extensionProperties[id] = schema;
|
||||
}
|
||||
|
||||
if (context === undefined || context === 'server') {
|
||||
this._serverWidgetSchema.extensionProperties[id] = schema;
|
||||
}
|
||||
|
||||
this._allSchema.extensionProperties[id] = schema;
|
||||
} else {
|
||||
if (context === undefined || context === 'database') {
|
||||
this._dashboardWidgetSchema.properties[id] = schema;
|
||||
}
|
||||
|
||||
if (context === undefined || context === 'server') {
|
||||
this._serverWidgetSchema.properties[id] = schema;
|
||||
}
|
||||
|
||||
this._allSchema.properties[id] = schema;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a non custom dashboard widget
|
||||
* @param id id of the widget
|
||||
* @param description description of the widget
|
||||
* @param val cal for default
|
||||
* @param context either 'database' or 'server' for what page to register for; if not specified, will register for both
|
||||
*/
|
||||
public registerNonCustomDashboardWidget(id: string, description: string, val: IInsightsConfig, context?: 'database' | 'server'): WidgetIdentifier {
|
||||
if (context === undefined || context === 'database') {
|
||||
this._dashboardWidgetSchema.properties[id] = { type: 'null', default: null };
|
||||
}
|
||||
|
||||
if (context === undefined || context === 'server') {
|
||||
this._serverWidgetSchema.properties[id] = { type: 'null', default: null };
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public get databaseWidgetSchema(): CustomIJSONSchema {
|
||||
return this._dashboardWidgetSchema;
|
||||
}
|
||||
|
||||
public get serverWidgetSchema(): CustomIJSONSchema {
|
||||
return this._serverWidgetSchema;
|
||||
}
|
||||
|
||||
public get allSchema(): CustomIJSONSchema {
|
||||
return this._allSchema;
|
||||
}
|
||||
}
|
||||
|
||||
const dashboardWidgetRegistry = new DashboardWidgetRegistry();
|
||||
platform.Registry.add(Extensions.DashboardWidgetContribution, dashboardWidgetRegistry);
|
||||
|
||||
export function registerDashboardWidget(id: string, description: string, schema: IJSONSchema, context?: 'database' | 'server', options?: IDashboardRegistryOptions): WidgetIdentifier {
|
||||
return dashboardWidgetRegistry.registerWidget(id, description, schema, context, options);
|
||||
}
|
||||
|
||||
export function registerNonCustomDashboardWidget(id: string, description: string, val: IInsightsConfig): WidgetIdentifier {
|
||||
return dashboardWidgetRegistry.registerNonCustomDashboardWidget(id, description, val);
|
||||
}
|
||||
Reference in New Issue
Block a user