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 { constructor( public dataLoader: WidgetDataLoaderInterface, public type: string, ) {} async render( widgetParams: any, dataLoaderParams: any, dashboardParams: any, ): Promise> { const data = await this.dataLoader.load(dataLoaderParams, dashboardParams); return data.error ? fail(data.error) : success(data.result); } } export function createInteractiveWidget( dataLoader: WidgetDataLoaderInterface, type: string, ): WidgetInterface { return new InteractiveWidget(dataLoader, type); }