mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -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:
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);
|
||||
}
|
||||
Reference in New Issue
Block a user