Live Platform
  • Introduction
  • Release Notes
    • Live 3
      • 3.59.0
      • 3.58.0
      • 3.57.0
      • 3.56.0
      • 3.55.0
      • 3.54.0
      • 3.53.0
      • 3.52.0
      • 3.51.0
      • 3.50.0
      • 3.49.0
      • 3.48.0
      • 3.47.0
      • 3.46.0
      • 3.45.0
      • 3.44.0
      • 3.43.0
      • 3.42.0
      • 3.41.0
      • 3.40.0
      • 3.39.0
      • 3.38.0
      • 3.37.0
      • 3.36.0
      • 3.35.0
      • 3.34.0
      • 3.33.0
      • 3.32.0
      • 3.31.0
      • 3.30.0
      • 3.29.0
      • 3.28.0
      • 3.27.0
      • 3.26.0
      • 3.25.0
      • 3.24.0
      • 3.23.0
      • 3.22.0
      • 3.21.0
      • 3.20.0
      • 3.19.0
      • 3.18.0
      • 3.17.0
      • 3.16.0
      • 3.15.0
      • 3.14.0
      • 3.13.0
      • 3.12.0
      • 3.11.0
      • 3.10.0
      • 3.9.0
      • 3.8.0
      • 3.7.0
      • 3.6.0
      • 3.5.0
      • 3.4.0
      • 3.3.0
      • 3.2.0
      • 3.1.0
      • 3.0.0
    • Live 2
  • Articles
    • Creating an aggregation
    • Creating a pipe
  • Theoretical Background
    • Fundamentals
    • Key Advantages
  • Platform Architecture
    • Introduction
    • Queries
    • Glossary
  • Featured plugins
    • Annotations
    • Groovy support
    • Messenger
    • Microsoft Teams
    • MongoDB
    • MongoDB Timeseries
    • MongoDB Kit
    • Purge plugin
    • SQL
    • TCP Input
    • TimescaleDB
  • Data visualization
    • Pipes widgets
      • Temporal
      • Cartesian
      • Multi-value snapshot
      • Single-value snapshot
      • Tables
      • Heatmap
      • JSX Widgets
      • Lollipop
      • Histogram
      • State Timeline
      • Boxplot
    • Pipes modifiers on Pipes charts
  • Alerts and notifications
    • Pipes modifiers on rules
  • Pipes Queries
    • Introduction
    • Dynamic filters
    • Meta parameters
    • Reducer
      • Uniform compress
      • PIP
    • Storage Hints
    • Execution Context
    • Event flow modifiers
  • Developers
    • Plugins
    • Packages
    • Backend API
      • Lookup Tables
      • Extensions
      • Settings
      • Storage Providers
      • Web Services
      • Web Setup
      • Entity Audit
    • Web application
      • Services
        • Point service
        • Menu service
      • Browser Compatibility
      • Runtime modules
        • Core Javascript modules
        • Library modules
        • Adding modules to runtime
      • Localization (i18n)
      • Date formatting
      • Dashboard and Widgets
        • Widget API
        • Custom widget editors
        • Live Event Types
        • Live Widget Configuration
        • Live Widget Packaging
        • Widget Request Interceptors
      • React Contexts
        • Dashboard
        • Dashboard widget
      • Registering Home Page options
    • Python application
    • Subscribing to Live Events
  • Administration
    • Configuration
      • Home Page Customization
      • live.properties
    • Infrastructure Monitoring
    • Storage Monitoring
    • Queries Monitoring
    • Logs Monitoring
    • Data Purging
  • Features
    • Access Permission
    • Datasources
    • Export Dashboard
    • Partial Indexes
    • WebApp Metrics
    • Entity Audit
Powered by GitBook
On this page
  • Creating a new widget editor
  • Creating an editor component
  • Registering the widget editor
  • Registering a menu option
  • Customizing the menus

Was this helpful?

  1. Developers
  2. Web application
  3. Dashboard and Widgets

Custom widget editors

Create custom editors for widgets, add the editor to the new widget menu or customize the menu

PreviousWidget APINextLive Event Types

Last updated 4 years ago

Was this helpful?

When a new widget type is created using the , it will use the standard pipes widget editor by default. However, the developer may register a custom editor to be used for a widget type.

Here we will guide on how to do some of the most common tasks in the creation of a new widget using examples. For a detailed documentation of the available API please look at the JSDocs in the source code available at live/services/editor-menu.

Creating a new widget editor

To create a widget editor, there are three main things a developer should do: create an editor component, register it using the EditorService and register an item in the "New chart" menu in the dashboard using the EditorMenuService.

Creating an editor component

The editor component receives as props the data (aLiveWidget object), the stores and actions and the meta array.

import { ConfigBar, EditorContainer } from 'plugin-assets/shared/widget/components/styled'
import Configs from './Configs'
const MySimpleEditor = (props: ChannelsWidgetEditorProps)=> {
    return (<ThemedEditorContainer className="editor-container default-editor">
        <ConfigBar>
            <Configs
                widgetConfig={this.props.data.jsonConfig}
                type={this.props.selectedWidget.type}
                changeConfig={this.props.widgetConfigActions.changeConfig}
                changeLayoutConfig={this.props.widgetConfigActions.changeLayoutConfig}
                isEditor={true}
            />
        </ConfigBar>
        <PreviewAndData
            widgetConfigStore={this.props.widgetConfigStore}
            widgetConfigActions={this.props.widgetConfigActions}
            widgetDataStore={this.props.widgetDataStore}
            widgetDataActions={this.props.widgetDataActions}
            widget={this.props.data}
            renderPreview={this.props.renderPreview}
            isEmpty={isEmpty}
            isAssetSelected={selectedAsset}
        />
    </ThemedEditorContainer>)
}

For the editor to be registered, it must provide a Higher Order wrapper component that receives the store and actions as parameters, as well as the meta array.

export default function MySimpleEditorHOC(
    widgetConfigStore: Record<string, any>,
    widgetConfigActions: Record<string, any>,
    widgetDataStore: Record<string, any>,
    widgetDataActions: Record<string, any>,
    meta: Array<any>
): (props: ChannelsValueTypeActionProps) => React.ReactNode {
    return function MySimpleEditorWrapper(props: ChannelsValueTypeActionProps): React.ReactNode {
        return (
            <MySimpleEditor
                widgetConfigStore={widgetConfigStore}
                widgetDataActions={widgetDataActions}
                widgetConfigActions={widgetConfigActions}
                widgetDataStore={widgetDataStore}
                meta={meta}
                {...props}
            />
        )
    }
}

Registering the widget editor

import EditorService from 'live/services/editor'
import MySimpleEditorHOC from './MySimpleEditorComponent'
const widgetType = 'my-simple-chart'
const editorType = 'my-simple-chart-editor'

EditorService.newEditor({
    name: editorType,
    editor: MySimpleEditorHOC,
    defaultWidgetType: widgetType
})

Once registered, the url /#/widget/new?dashboard=123&type=my-simple-chart-editor will be available to create a widget (in the dashboard 123, in this example).

Registering a menu option

For the widget editor to be accessible in the dashboard menu, it must be registered using the EditorMenuService API. Since 2.28.0 images (210px x 100px) are used to represent the editors instead of icons. Editors added using the API below will be added to the "Standard charts" tab. If you want to customize the tabs, use the method described in the next section.

Starting in Live 2.28.0 you can use the following API to add a widget editor to the "Standard chart" tab.

import EditorMenuService from 'live/services/editor-menu'
import i18n from 'live/services/i18n'
import thumbnail from 'img/chart-editor/example.png'

const option = {
    order: 0,
    type: 'my-simple-chart',
    label: i18n('My Simple Chart'),
    description: i18('This chart is an example for the live documentation'),
    thumbnail: thumbnail
}

EditorMenuService.add(option)

In previous versions, the following API should be used.

import EditorService from 'live/services/editor'
import i18n from 'live/services/i18n'

const option = {
    order: 0,
    type: 'my-simple-chart',
    label: i18n('My Simple Chart'),
    description: i18('This chart is an example for the live documentation'),
    iconClass: 'fa fa-bar-chart'
}

EditorService.newEditorMenuOption(option.type, option)

Customizing the menus

While using the API described previously is recommended, it is possible to customize the tabs, creating new tabs, removing existing tabs and replacing the default "Standard Charts" tab. Notice internally we call tabs "groups" since the visual representation of these groups may change from tabs to some other representation.

If there are no widget editors in the standard tab, it will not be shown in the interface nor listed in the API.

Replacing the standard tab

The developer may replace the standard tab to rename it or change the order of the tabs. All existing editors added to the standard tab will be moved to the new standard tab and new editors added using the default API will be added to the new standard tab as well.

const newStandardGroup = new EditorMenuOptionGroup({ label: 'test', order: 100 })

EditorMenuService.replaceStandardGroup(newStandardGroup)

Adding a new tab

The developer may add a new tab to the menu and add editors to it

const group = new EditorMenuOptionGroup({ order: 0, label: 'Example group' })

const editorMenuExample = {
    order: 1,
    type: 'example',
    label: 'Example chart',
    description: 'A chart that is used as an example for code testing purposes',
    thumbnail: 'https://www.intelie.com/images/id-intelie-new.png'
}

group.add(editorMenuExample)

EditorMenuService.add(group)

Removing a tab

The developer may remove a tab if he so wishes, but is responsible for adding the editors in that tab to some other tab

const allOptions = EditorMenuService.options()

EditorMenuService.groups().forEach((group) =>
    const groupOptions = group.options()
    EditorMenuService.remove(group)
)

Following the example from the , we will add an editor to the 'my-simple-chart' widget type:

Widget API
Widget API
The "New chart" menu