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 withcontext.registerPerspectives
.
Migrate the recordView function
-
Rename the registered
recordView
function torender
and move it inside aview.<choose a view name>
object. -
Move the data fetching logic to a function called
enrich
and keep only the rendering logic in functionrender
. Whenenrich
is defined Investigate calls therender
function periodically to update the view. Therender
function must not beasync
. -
Store computed data inside input object
computedData
. Create a function calledinitialData
to initialize thecomputedData
object with values beforeenrich
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
tobinary
. -
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' };
}
}
}
});