28 lines
891 B
TypeScript
28 lines
891 B
TypeScript
import { Result, AppError, fail, success } from '../utils/result';
|
|
import { WidgetDataLoaderInterface } from './widget-data-loader-interface';
|
|
import { WidgetInterface } from './widget-interface';
|
|
|
|
export class InteractiveWidget
|
|
implements WidgetInterface<any, any, any, any, any>
|
|
{
|
|
constructor(
|
|
public dataLoader: WidgetDataLoaderInterface<any, any, any>,
|
|
public type: string,
|
|
) {}
|
|
|
|
async render(
|
|
widgetParams: any,
|
|
dataLoaderParams: any,
|
|
dashboardParams: any,
|
|
): Promise<Result<any, AppError>> {
|
|
const data = await this.dataLoader.load(dataLoaderParams, dashboardParams);
|
|
return data.error ? fail(data.error) : success(data.result);
|
|
}
|
|
}
|
|
|
|
export function createInteractiveWidget(
|
|
dataLoader: WidgetDataLoaderInterface<any, any, any>,
|
|
type: string,
|
|
): WidgetInterface<any, any, any, any, any> {
|
|
return new InteractiveWidget(dataLoader, type);
|
|
}
|