Files
azuredatastudio/src/sql/platform/dashboard/common/modelComponentRegistry.ts
Kevin Cunnane b2c70e9301 Feat/model backed ui (#1145)
This is an initial PR for a new model-driven UI where extensions can provide definitions of the components & how they're laid out using Containers.
#1140, #1141, #1142, #1143 and #1144 are all tracking additional work needed to improve the initial implementation and fix some issues with the implementation.

Features:
- Supports defining a FlexContainer that maps to a flexbox-based layout.
- Supports creating a card component, which is a key-value pair based control that will lay out simple information to a user. Eventually this will have an optional set of actions associated with it.
- Has a sample project which shows how to use the API and was used for verification
2018-04-13 15:59:18 -07:00

66 lines
2.5 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* 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 { IJSONSchema } from 'vs/base/common/jsonSchema';
import * as nls from 'vs/nls';
import { IComponent } from 'sql/parts/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);
}