Templates API in Siren Investigate

context.registerPerspectives

The context global variable provides a registerPerspectives function you can use to register perspectives in the Siren Platform.

You must define perspectives in groups corresponding to their type. At the moment, there are 2 possible types of template perspectives:

  • view - for displaying interactive data.

  • binary - for statically opening and downloading data.

Example

context.registerPerspectives({
  shareComputedDataAcrossPerspectives: false,
  view: {
    'View 1': view1Definition,
    'View 2': view2Definition
  },
  binary: {
    'Download pdf report': myPdfReportDefinition
  }
});

Properties

Name Type Description

view

Record<string, PerspectiveDefinition>

(Optional) Dictionary of view perspectives.

binary

Record<string, PerspectiveDefinition>

(Optional) Dictionary of binary perspectives.

shareComputedDataAcrossPerspectives

boolean

(Optional) Whether perspectives of the script will share the input.computedData object for the same input document. Defaults to true.

PerspectiveDefinition

An object that defines a perspective to register with context.registerPerspectives.

Properties

Name Type Description

computedDataTTL

number

(Optional) A number representing the time, in seconds, Investigate will keep the input.computedData object cached. Defaults to 2 minutes.

dataModelFormatting

boolean | string[]

A boolean or list of strings that controls the content of the input.sourceMeta.formattedFields property:

  • true: Investigate will format all fields.

  • string[]: List of field names to format.


PerspectiveDefinition.render(PerspectiveInput)

Renders the output of the perspective. The output of the function depends on its type:

  • view - JSX.Element, a React element to display.

  • binary - BinaryOutput, a binary output representation.

When the perspective defines an enrich function, the render function must be synchronous.

Parameter Type Description

PerspectiveInput

PerspectiveInput

Properties used to render the data.

Returns: the output type depends on the perspective type.

  • view: must return a React element.

  • binary: must return a BinaryOutput object.


PerspectiveDefinition.enrich(PerspectiveInput)

An optional function that is responsible for fetching and processing data.

Use it to refresh view perspectives during long data processing. Investigate will call the render function periodically until enrich completes.

You can store computed data in the input computedData property to make it available to the render function.

Parameter Type Description

PerspectiveInput

PerspectiveInput

Properties used to process the data.


PerspectiveDefinition.initialData(PerspectiveInput)

An optional function which returns the initial state of the input.computedData object.

Parameter Type Description

PerspectiveInput

PerspectiveInput

Properties used to initialize the data.

Returns: Record<string, unknown>.


PerspectiveInput

Input data passed to all perspective functions.

Name Type Description

source

Record<string, unknown>

A raw source of the record data.

sourceMeta.sourceType

'elasticsearch' | 'eid'

The type of input document. elasticsearch refers to an Elasticsearch-based document. eid refers to a virtual entity identifier.

sourceMeta.fields

Record<string, unknown[]>

The fields property of the Elasticsearch hit. Only defined when sourceType has the value elasticsearch. Object values are always arrays.

sourceMeta.formattedFields

Record<string, unknown[]>

A key-value dictionary that maps field names to values as formatted strings ready to display. Only defined when sourceType has value elasticsearch. Object values are always arrays.

sourceMeta.highlight

Record<string, Siren.HighlightItem[][]>

A key-value dictionary that maps field names to lists of highlighted items. See Highlighting for more details. Only defined when sourceType has value elasticsearch. Object values are always arrays.

record

DataRecord

A DataRecord instance for the displayed record.

dataModelEntity

DataModelEntity

A DataModelEntity instance for the data model entity that prompted the record display.

computedData

Record<string, unknown>

An object used to store fetched data and make it available on render function calls.

computedMeta.creationTime

number

The time the computedData object was created, in milliseconds since the Unix epoch.

computedMeta.expirationTime

number

The time the computedData object is going to be removed from the Investigate cache, in milliseconds since the Unix epoch.

cancelPromise

Promise<void>

A promise rejected in case of cancellation for example, the user changes the page or closes the Record Viewer.

isCanceled

() ⇒ boolean

A function returning whether the execution was canceled.

BinaryOutput

Representation of an output binary object. The object must have either the content property or the templateId property.

Name Type Description

filename

string

File name used when downloading the resource.

content

string | Blob

(Optional) Static content of the binary object.

templateId

string

(Optional) A jsreport template id. See Creating downloadable reports for how to create jsreport templates.

data

Object

(Optional) Data supplied to the jsreport template.