@statoscope/stats-extension-custom-reports
v5.28.1
Published
Statoscope extension to store custom reports in stats
Downloads
609,840
Readme
Statoscope Package Custom Reports
Statoscope extension to store custom reports in stats.
A custom report is:
export type Report<TData, TContext> = {
id: string; // report id
name?: string; // report title
compilation?: string | null; // if specified then a report will be shown only in specific compilation
data?: TData | (() => Promise<TData> | TData); // raw data for the report or a function that produces a data (may return promise)
view: string | ViewConfig<TData, TContext>; // any DiscoveryJS. String turns to script to eval
};
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')
})