mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-30 22:48:32 +01:00
* added recursion and inition decorators * working version * added todo comment and removed console.log * Added Recursive add * removed type requirement * proper resolution of promises * added custom element and base class * Made selfServe standalone page * Added custom renderer as async type * Added overall defaults * added inital open from data explorer * removed landingpage * added feature for self serve type * renamed sqlx->example and added invalid type * Added comments for Example * removed unnecessary changes * Resolved PR comments Added tests Moved onSubmt and initialize inside base class Moved testExplorer to separate folder made fields of SelfServe Class non static * fixed lint errors * fixed compilation errors * Removed reactbinding changes * renamed dropdown -> choice * Added SelfServeComponent * Addressed PR comments * added toggle, visibility, text display,commandbar * added sqlx example * added onRefrssh * formatting changes * rmoved radioswitch display * updated smartui tests * Added more tests * onSubmit -> onSave * Resolved PR comments
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
/**
|
|
* This adapter is responsible to render the React component
|
|
* If the component signals a change through the callback passed in the properties, it must render the React component when appropriate
|
|
* and update any knockout observables passed from the parent.
|
|
*/
|
|
import * as ko from "knockout";
|
|
import * as React from "react";
|
|
import { ReactAdapter } from "../Bindings/ReactBindingHandler";
|
|
import Explorer from "../Explorer/Explorer";
|
|
import { SelfServeComponent } from "./SelfServeComponent";
|
|
import { SelfServeDescriptor } from "./SelfServeTypes";
|
|
import { SelfServeType } from "./SelfServeUtils";
|
|
|
|
export class SelfServeComponentAdapter implements ReactAdapter {
|
|
public parameters: ko.Observable<SelfServeDescriptor>;
|
|
public container: Explorer;
|
|
|
|
constructor(container: Explorer) {
|
|
this.container = container;
|
|
this.parameters = ko.observable(undefined);
|
|
this.container.selfServeType.subscribe(() => {
|
|
this.triggerRender();
|
|
});
|
|
}
|
|
|
|
public static getDescriptor = async (selfServeType: SelfServeType): Promise<SelfServeDescriptor> => {
|
|
switch (selfServeType) {
|
|
case SelfServeType.example: {
|
|
const SelfServeExample = await import(/* webpackChunkName: "SelfServeExample" */ "./Example/SelfServeExample");
|
|
return new SelfServeExample.default().toSelfServeDescriptor();
|
|
}
|
|
case SelfServeType.sqlx: {
|
|
const SqlX = await import(/* webpackChunkName: "SqlX" */ "./SqlX/SqlX");
|
|
return new SqlX.default().toSelfServeDescriptor();
|
|
}
|
|
default:
|
|
return undefined;
|
|
}
|
|
};
|
|
|
|
public renderComponent(): JSX.Element {
|
|
if (this.container.selfServeType() === SelfServeType.invalid) {
|
|
return <h1>Invalid self serve type!</h1>;
|
|
}
|
|
const smartUiDescriptor = this.parameters();
|
|
return smartUiDescriptor ? <SelfServeComponent descriptor={smartUiDescriptor} /> : <></>;
|
|
}
|
|
|
|
private triggerRender() {
|
|
window.requestAnimationFrame(async () => {
|
|
const selfServeType = this.container.selfServeType();
|
|
const smartUiDescriptor = await SelfServeComponentAdapter.getDescriptor(selfServeType);
|
|
this.parameters(smartUiDescriptor);
|
|
});
|
|
}
|
|
}
|