mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-25 11:51:07 +00:00
Compare commits
14 Commits
cloudshell
...
users/aisa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
228f412406 | ||
|
|
cad718acc4 | ||
|
|
0559ec5cb1 | ||
|
|
ca641b2ff5 | ||
|
|
53836a93cd | ||
|
|
c38e42e44b | ||
|
|
6032b39058 | ||
|
|
23852dcd69 | ||
|
|
81bd0f635e | ||
|
|
3efbc57617 | ||
|
|
aee8249ffa | ||
|
|
14db9e819a | ||
|
|
f9e18cf28c | ||
|
|
4708722d1a |
@@ -2,8 +2,9 @@
|
|||||||
* @module SelfServe/Decorators
|
* @module SelfServe/Decorators
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { TFunction } from "i18next";
|
||||||
import { ChoiceItem, Description, Info, NumberUiType, OnChangeCallback, RefreshParams } from "./SelfServeTypes";
|
import { ChoiceItem, Description, Info, NumberUiType, OnChangeCallback, RefreshParams } from "./SelfServeTypes";
|
||||||
import { addPropertyToMap, buildSmartUiDescriptor, DecoratorProperties } from "./SelfServeUtils";
|
import { addPropertyToMap, buildSmartUiDescriptor, DecoratorProperties, SelfServeType } from "./SelfServeUtils";
|
||||||
|
|
||||||
type ValueOf<T> = T[keyof T];
|
type ValueOf<T> = T[keyof T];
|
||||||
interface Decorator {
|
interface Decorator {
|
||||||
@@ -128,8 +129,9 @@ const isDescriptionDisplayOptions = (inputOptions: InputOptions): inputOptions i
|
|||||||
};
|
};
|
||||||
|
|
||||||
const addToMap = (...decorators: Decorator[]): PropertyDecorator => {
|
const addToMap = (...decorators: Decorator[]): PropertyDecorator => {
|
||||||
return (target, property) => {
|
console.log(decorators);
|
||||||
let className = target.constructor.name;
|
return async (target, property) => {
|
||||||
|
let className: string = getTargetName(target);
|
||||||
const propertyName = property.toString();
|
const propertyName = property.toString();
|
||||||
if (className === "Function") {
|
if (className === "Function") {
|
||||||
//eslint-disable-next-line @typescript-eslint/ban-types
|
//eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
@@ -138,6 +140,7 @@ const addToMap = (...decorators: Decorator[]): PropertyDecorator => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const propertyType = (Reflect.getMetadata("design:type", target, property)?.name as string)?.toLowerCase();
|
const propertyType = (Reflect.getMetadata("design:type", target, property)?.name as string)?.toLowerCase();
|
||||||
|
console.log(propertyType);
|
||||||
addPropertyToMap(target, propertyName, className, "type", propertyType);
|
addPropertyToMap(target, propertyName, className, "type", propertyType);
|
||||||
addPropertyToMap(target, propertyName, className, "dataFieldName", propertyName);
|
addPropertyToMap(target, propertyName, className, "dataFieldName", propertyName);
|
||||||
|
|
||||||
@@ -205,7 +208,8 @@ export const Values = (inputOptions: InputOptions): PropertyDecorator => {
|
|||||||
*/
|
*/
|
||||||
export const IsDisplayable = (): ClassDecorator => {
|
export const IsDisplayable = (): ClassDecorator => {
|
||||||
return (target) => {
|
return (target) => {
|
||||||
buildSmartUiDescriptor(target.name, target.prototype);
|
let targetName: string = getTargetName(target);
|
||||||
|
buildSmartUiDescriptor(targetName, target.prototype);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -215,7 +219,26 @@ export const IsDisplayable = (): ClassDecorator => {
|
|||||||
* how often the auto refresh of the page occurs.
|
* how often the auto refresh of the page occurs.
|
||||||
*/
|
*/
|
||||||
export const RefreshOptions = (refreshParams: RefreshParams): ClassDecorator => {
|
export const RefreshOptions = (refreshParams: RefreshParams): ClassDecorator => {
|
||||||
|
console.log(refreshParams);
|
||||||
return (target) => {
|
return (target) => {
|
||||||
addPropertyToMap(target.prototype, "root", target.name, "refreshParams", refreshParams);
|
let targetName: string = getTargetName(target);
|
||||||
|
addPropertyToMap(target.prototype, "root", targetName, "refreshParams", refreshParams);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getTargetName = (target: TFunction | Object): string => {
|
||||||
|
const targetString: string = target.toString();
|
||||||
|
let targetName: string;
|
||||||
|
if (targetString.includes(SelfServeType.example)) {
|
||||||
|
targetName = SelfServeType.example;
|
||||||
|
} else if (targetString.includes(SelfServeType.graphapicompute)) {
|
||||||
|
targetName = SelfServeType.graphapicompute;
|
||||||
|
} else if (targetString.includes(SelfServeType.materializedviewsbuilder)) {
|
||||||
|
targetName = SelfServeType.materializedviewsbuilder;
|
||||||
|
} else if (targetString.includes(SelfServeType.sqlx)) {
|
||||||
|
targetName = SelfServeType.sqlx;
|
||||||
|
} else {
|
||||||
|
targetName = target.constructor.name;
|
||||||
|
}
|
||||||
|
return targetName;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { SelfServeType } from "SelfServe/SelfServeUtils";
|
||||||
import { IsDisplayable, OnChange, PropertyInfo, RefreshOptions, Values } from "../Decorators";
|
import { IsDisplayable, OnChange, PropertyInfo, RefreshOptions, Values } from "../Decorators";
|
||||||
import { selfServeTraceStart, selfServeTraceSuccess } from "../SelfServeTelemetryProcessor";
|
import { selfServeTraceStart, selfServeTraceSuccess } from "../SelfServeTelemetryProcessor";
|
||||||
import {
|
import {
|
||||||
@@ -168,6 +169,10 @@ export default class SelfServeExample extends SelfServeBaseClass {
|
|||||||
return defaults;
|
return defaults;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public getSelfServeType = (): SelfServeType => {
|
||||||
|
return SelfServeType.example;
|
||||||
|
};
|
||||||
|
|
||||||
@Values({
|
@Values({
|
||||||
labelTKey: "DescriptionLabel",
|
labelTKey: "DescriptionLabel",
|
||||||
description: {
|
description: {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
|
|
||||||
import type { ChoiceItem } from "../SelfServeTypes";
|
import type { ChoiceItem } from "../SelfServeTypes";
|
||||||
|
|
||||||
import { BladeType, generateBladeLink } from "../SelfServeUtils";
|
import { BladeType, generateBladeLink, SelfServeType } from "../SelfServeUtils";
|
||||||
import {
|
import {
|
||||||
deleteComputeResource,
|
deleteComputeResource,
|
||||||
getCurrentProvisioningState,
|
getCurrentProvisioningState,
|
||||||
@@ -360,6 +360,10 @@ export default class GraphAPICompute extends SelfServeBaseClass {
|
|||||||
return defaults;
|
return defaults;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public getSelfServeType = (): SelfServeType => {
|
||||||
|
return SelfServeType.graphapicompute;
|
||||||
|
};
|
||||||
|
|
||||||
@Values({
|
@Values({
|
||||||
isDynamicDescription: true,
|
isDynamicDescription: true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
|
|
||||||
import type { ChoiceItem } from "../SelfServeTypes";
|
import type { ChoiceItem } from "../SelfServeTypes";
|
||||||
|
|
||||||
import { BladeType, generateBladeLink } from "../SelfServeUtils";
|
import { BladeType, generateBladeLink, SelfServeType } from "../SelfServeUtils";
|
||||||
import {
|
import {
|
||||||
deleteMaterializedViewsBuilderResource,
|
deleteMaterializedViewsBuilderResource,
|
||||||
getCurrentProvisioningState,
|
getCurrentProvisioningState,
|
||||||
@@ -359,6 +359,10 @@ export default class MaterializedViewsBuilder extends SelfServeBaseClass {
|
|||||||
return defaults;
|
return defaults;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public getSelfServeType = (): SelfServeType => {
|
||||||
|
return SelfServeType.materializedviewsbuilder;
|
||||||
|
};
|
||||||
|
|
||||||
@Values({
|
@Values({
|
||||||
isDynamicDescription: true,
|
isDynamicDescription: true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
* @module SelfServe/SelfServeTypes
|
* @module SelfServe/SelfServeTypes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SelfServeType } from "SelfServe/SelfServeUtils";
|
||||||
import { TelemetryData } from "../Shared/Telemetry/TelemetryProcessor";
|
import { TelemetryData } from "../Shared/Telemetry/TelemetryProcessor";
|
||||||
|
|
||||||
interface BaseInput {
|
interface BaseInput {
|
||||||
@@ -120,9 +121,11 @@ export abstract class SelfServeBaseClass {
|
|||||||
*/
|
*/
|
||||||
public abstract onRefresh: () => Promise<RefreshResult>;
|
public abstract onRefresh: () => Promise<RefreshResult>;
|
||||||
|
|
||||||
|
public abstract getSelfServeType: () => SelfServeType;
|
||||||
|
public test: string = "hello";
|
||||||
/**@internal */
|
/**@internal */
|
||||||
public toSelfServeDescriptor(): SelfServeDescriptor {
|
public toSelfServeDescriptor(): SelfServeDescriptor {
|
||||||
const className = this.constructor.name;
|
const className: string = this.getSelfServeType();
|
||||||
const selfServeDescriptor = Reflect.getMetadata(className, this) as SelfServeDescriptor;
|
const selfServeDescriptor = Reflect.getMetadata(className, this) as SelfServeDescriptor;
|
||||||
|
|
||||||
if (!this.initialize) {
|
if (!this.initialize) {
|
||||||
|
|||||||
@@ -1,42 +1,60 @@
|
|||||||
import { NumberUiType, OnSaveResult, RefreshResult, SelfServeBaseClass, SmartUiInput } from "./SelfServeTypes";
|
import { NumberUiType, OnSaveResult, RefreshResult, SelfServeBaseClass, SmartUiInput } from "./SelfServeTypes";
|
||||||
import { DecoratorProperties, mapToSmartUiDescriptor, updateContextWithDecorator } from "./SelfServeUtils";
|
import {
|
||||||
|
DecoratorProperties,
|
||||||
|
mapToSmartUiDescriptor,
|
||||||
|
SelfServeType,
|
||||||
|
updateContextWithDecorator,
|
||||||
|
} from "./SelfServeUtils";
|
||||||
|
|
||||||
describe("SelfServeUtils", () => {
|
describe("SelfServeUtils", () => {
|
||||||
|
const getSelfServeTypeExample = (): SelfServeType => {
|
||||||
|
return SelfServeType.example;
|
||||||
|
};
|
||||||
|
|
||||||
it("initialize should be declared for self serve classes", () => {
|
it("initialize should be declared for self serve classes", () => {
|
||||||
class Test extends SelfServeBaseClass {
|
class SelfServeExample extends SelfServeBaseClass {
|
||||||
public initialize: () => Promise<Map<string, SmartUiInput>>;
|
public initialize: () => Promise<Map<string, SmartUiInput>>;
|
||||||
public onSave: (currentValues: Map<string, SmartUiInput>) => Promise<OnSaveResult>;
|
public onSave: (currentValues: Map<string, SmartUiInput>) => Promise<OnSaveResult>;
|
||||||
public onRefresh: () => Promise<RefreshResult>;
|
public onRefresh: () => Promise<RefreshResult>;
|
||||||
|
public getSelfServeType = (): SelfServeType => getSelfServeTypeExample();
|
||||||
}
|
}
|
||||||
expect(() => new Test().toSelfServeDescriptor()).toThrow("initialize() was not declared for the class 'Test'");
|
expect(() => new SelfServeExample().toSelfServeDescriptor()).toThrow(
|
||||||
|
"initialize() was not declared for the class 'SelfServeExample'",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("onSave should be declared for self serve classes", () => {
|
it("onSave should be declared for self serve classes", () => {
|
||||||
class Test extends SelfServeBaseClass {
|
class SelfServeExample extends SelfServeBaseClass {
|
||||||
public initialize = jest.fn();
|
public initialize = jest.fn();
|
||||||
public onSave: () => Promise<OnSaveResult>;
|
public onSave: () => Promise<OnSaveResult>;
|
||||||
public onRefresh: () => Promise<RefreshResult>;
|
public onRefresh: () => Promise<RefreshResult>;
|
||||||
|
public getSelfServeType = (): SelfServeType => getSelfServeTypeExample();
|
||||||
}
|
}
|
||||||
expect(() => new Test().toSelfServeDescriptor()).toThrow("onSave() was not declared for the class 'Test'");
|
expect(() => new SelfServeExample().toSelfServeDescriptor()).toThrow(
|
||||||
|
"onSave() was not declared for the class 'SelfServeExample'",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("onRefresh should be declared for self serve classes", () => {
|
it("onRefresh should be declared for self serve classes", () => {
|
||||||
class Test extends SelfServeBaseClass {
|
class SelfServeExample extends SelfServeBaseClass {
|
||||||
public initialize = jest.fn();
|
public initialize = jest.fn();
|
||||||
public onSave = jest.fn();
|
public onSave = jest.fn();
|
||||||
public onRefresh: () => Promise<RefreshResult>;
|
public onRefresh: () => Promise<RefreshResult>;
|
||||||
|
public getSelfServeType = (): SelfServeType => getSelfServeTypeExample();
|
||||||
}
|
}
|
||||||
expect(() => new Test().toSelfServeDescriptor()).toThrow("onRefresh() was not declared for the class 'Test'");
|
expect(() => new SelfServeExample().toSelfServeDescriptor()).toThrow(
|
||||||
|
"onRefresh() was not declared for the class 'SelfServeExample'",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("@IsDisplayable decorator must be present for self serve classes", () => {
|
it("@IsDisplayable decorator must be present for self serve classes", () => {
|
||||||
class Test extends SelfServeBaseClass {
|
class SelfServeExample extends SelfServeBaseClass {
|
||||||
public initialize = jest.fn();
|
public initialize = jest.fn();
|
||||||
public onSave = jest.fn();
|
public onSave = jest.fn();
|
||||||
public onRefresh = jest.fn();
|
public onRefresh = jest.fn();
|
||||||
|
public getSelfServeType = (): SelfServeType => getSelfServeTypeExample();
|
||||||
}
|
}
|
||||||
expect(() => new Test().toSelfServeDescriptor()).toThrow(
|
expect(() => new SelfServeExample().toSelfServeDescriptor()).toThrow(
|
||||||
"@IsDisplayable decorator was not declared for the class 'Test'",
|
"@IsDisplayable decorator was not declared for the class 'SelfServeExample'",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -141,6 +141,9 @@ export const updateContextWithDecorator = <T extends keyof DecoratorProperties,
|
|||||||
descriptorName: keyof DecoratorProperties,
|
descriptorName: keyof DecoratorProperties,
|
||||||
descriptorValue: K,
|
descriptorValue: K,
|
||||||
): void => {
|
): void => {
|
||||||
|
console.log(context);
|
||||||
|
console.log(propertyName);
|
||||||
|
console.log(className);
|
||||||
if (!(context instanceof Map)) {
|
if (!(context instanceof Map)) {
|
||||||
throw new Error(`@IsDisplayable should be the first decorator for the class '${className}'.`);
|
throw new Error(`@IsDisplayable should be the first decorator for the class '${className}'.`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
|
|
||||||
import type { ChoiceItem } from "../SelfServeTypes";
|
import type { ChoiceItem } from "../SelfServeTypes";
|
||||||
|
|
||||||
import { BladeType, generateBladeLink } from "../SelfServeUtils";
|
import { BladeType, generateBladeLink, SelfServeType } from "../SelfServeUtils";
|
||||||
import {
|
import {
|
||||||
deleteDedicatedGatewayResource,
|
deleteDedicatedGatewayResource,
|
||||||
getCurrentProvisioningState,
|
getCurrentProvisioningState,
|
||||||
@@ -396,6 +396,10 @@ export default class SqlX extends SelfServeBaseClass {
|
|||||||
return defaults;
|
return defaults;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public getSelfServeType = (): SelfServeType => {
|
||||||
|
return SelfServeType.sqlx;
|
||||||
|
};
|
||||||
|
|
||||||
@Values({
|
@Values({
|
||||||
isDynamicDescription: true,
|
isDynamicDescription: true,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user