Skip to content

Make expression renderer aware of current context #77161

@flash1293

Description

@flash1293

When rendering the result of an expression in an expression renderer, it is sometimes important to have some information about the context the result is rendered in because it can influence different aspects. In the case of Lens, there are several real world use cases for this:

  • noInteractivity: When a Lens visualization is embedded in a Canvas workpad, filter actions can't be dispatched. But the chart renderer doesn't know about this and is still appearing interactive (e.g. changing the cursor when hovering over bars and letting the user brush to select a range on the x axis which doesn't have any effect). [Lens] Option to disable interactions #65630
  • edit: In Lens there a features planned that would require to offer some chart interactivity only when within the Lens editor, not on dashboards. [Lens] Client side table sorting #76962
  • preview: Lens is rendering visualizations in a "preview" mode in suggestions. This is currently done using a special separate expression, but could be solved more easily using a mode passed directly to the renderer

Screenshot 2020-09-10 at 14 37 24

Proposal

This can be done by adding a mode option to the expression runner / component wrapper as part of the IExpressionLoaderParams:

<ExpressionRenderer expression={expression} mode="edit" />

This mode which is restricted by an enum ('noInteractivity' | 'edit' | 'preview' | 'display' with defaulting to 'display') is exposed to the renderer as part of the handlers:

{
  name: 'my_renderer',
  render: async (
    domNode: Element,
    config: MyProps,
    handlers: IInterpreterRenderHandlers
  ) => {
    if (handlers.getMode() === 'edit') { /* ... */ }
  }
}

As the possible modes are defined in a central place, this becomes a part of the generic contract of expression renderers. When implementing a renderer, it should respect the current mode as well as it can.

Metadata

Metadata

Assignees

Labels

Feature:ExpressionLanguageInterpreter expression language (aka canvas pipeline)Team:VisualizationsTeam label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t//

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions