5.28.1 • Published 2 years ago

@statoscope/stats-extension-custom-reports v5.28.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Statoscope Package Custom Reports

npm version Financial Contributors on Open Collective

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 evaled 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')
})