Statoscope Package Custom Reports
Statoscope extension to store custom reports in stats.
A custom report is:
export type Report<TData, TContext> = {
id: string;
name?: string;
compilation?: string | null;
data?: TData | (() => Promise<TData> | TData);
view: string | ViewConfig<TData, TContext>;
};
View as a script
Sometimes we need to make a report with more complex view (e.g. with event handling).
JSON can't handle functions, but you can pass any script source into view
-property instead of JSON.
This source will be eval
ed on client and should return any DiscoveryJS view.
my-custom-report-view.js:
(() => [
{
view: 'button',
data: {
text: 'Click me',
},
onClick() {
alert('It works!');
},
},
])();
Report config:
({
id: 'foo',
view: fs.readFileSync('./my-custom-report-view.js', 'utf8')
})