API migration guides

Templates migration guide

Version 2 (Investigate 13.3.0)

To migrate a version 1 template script to version 2, follow these steps:

  • Function context.registerTemplate has been renamed. Search and replace it with context.registerPerspectives.

Migrate the recordView function

  • Rename the registered recordView function to render and move it inside a view.<choose a view name> object.

  • Move the data fetching logic to a function called enrich and keep only the rendering logic in function render. When enrich is defined Investigate calls the render function periodically to update the view. The render function must not be async.

  • Store computed data inside input object computedData. Create a function called initialData to initialize the computedData object with values before enrich is called.

Example
// Version 1
context.registerTemplate({
  async recordView(input) {
    const { render } = input;

    const recordData = { value: 'loading' };
    const timerId = setInterval(() => render(reactView(recordData)), 200);

    try {
      await fetchRecordData(input, recordData);
    } finally {
      clearInterval(timerId); // Clean up automatic updates before quitting
    }

    return reactView(recordData);
  }
});


// Version 2
context.registerPerspectives({
  view: {
    'My View': {
      initialData() {
        return { value: loading };
      },

      async enrich(input) {
        await fetchRecordData(input, input.computedData);
      },

      render({ computedData }) {
        return reactView(computedData);
      }
    }
  }
});

Migrate download functions

  • Rename registered object download to binary.

  • Replace calls to sirenapi.Reporting with returning a binary output object.

Example
// Version 1
context.registerTemplate({
  download: {
    async pdf() {
      await sirenapi.Reporting.download(templateId, { value: 'value' }, 'report.pdf');
    },

    async txt() {
      await sirenapi.Reporting.downloadString('Report content here', 'report.txt');
    }
  }
});

// Version 2
context.registerPerspectives({
  binary: {
    'My pdf export': {
      render() {
        return { filename: 'report.pdf', templateId, data: { value: 'value' } };
      }
    },

    'My txt export': {
      render() {
        return { filename: 'report.txt', content: 'Report content here' };
      }
    }
  }
});