Skip to main content

Dashboard Plugin

Plugin Introduction

The Dashboard plugin is used to display data of device entities, including historical data, latest data, and entity data operations. The Dashboard plugin allows for customizable display content, supporting various data presentation methods such as tables, charts, and cards.

Overall Process

  1. Log in to the open-source project.
  2. Create and develop your own plugin.
  3. Connect integration on the settings page.
  4. Add your own entity on the device page.
  5. Add your plugin on the dashboard page.

Dashboard Plugin Directory Structure

The plugin directory is located in the apps\web\src\components\drawing-board\plugin directory of the project. The internal structure of the plugin is as follows:

plugin
├── components # Base components directory for plugins
│ ├── chart-metrics-select # Chart metrics selection component
│ ├── chart-time-select # Chart time selection component
│ ├── entity-select # Entity single selection component
│ ├── icon-color-select # Icon color selector component
│ ├── icon-select # Icon selector component
| ├── input # Input box component
| ├── multi-entity-select # Multi-entity selection component
| ├── select # Selector component
| ├── switch # Switch component
| └── index.ts # Entry file for base components
├── config-plugin # General plugin configuration dialog, no need to focus on it during plugin development
├── plugins # Plugin directory
│ ├── area-chart # Area chart plugin
| ├── configure # Plugin form configuration file
| ├── view # Plugin preview file
| ├── config.json # Plugin configuration file
| ├── icon.png # Plugin icon
│ ├── bar-chart # Bar chart plugin
│ ├── data-card # Data card plugin
│ ├── gauge-chart # Gauge chart plugin
│ ├── horizon-bar-chart # Horizontal bar chart plugin
│ ├── icon-remaining # Remaining icon plugin
│ ├── line-chart # Line chart plugin
│ └── pie-chart # Pie chart plugin
│ └── radar-chart # Radar chart plugin
│ └── switch # Switch plugin
│ └── trigger # Event trigger plugin
├── render # Plugin rendering engine, no need to focus on it during plugin development
├── view-components # Common UI display components for plugins
├── typings.d.ts # Plugin type definition file
├── utils.ts # Plugin utility functions

Development Steps

  • Create a new Dashboard plugin directory under apps\web\src\components\drawing-board\plugin\plugins.

  • After creating your own plugin directory, the first step is to create a control-panel directory and establish an index.ts file within it as the unified entry point. You may omit configure and view components, but control-panel\index.ts is mandatory. A single control-panel\index.ts file suffices for both plugin form configuration and configuration preview.

  • In extremely exceptional circumstances (not recommended), it is only advised to create a configure directory within the project and establish an index.tsx file as the unified entry point within this directory when complete customization of the plugin's control panel configuration rendering is required. Under normal circumstances, please refrain from employing this approach.

  • After creating control-panel\index.ts, configure the control-panel\index.ts file's type. The type serves as the unique identifier for the plugin and must not be duplicated. Avoid simple names to prevent conflicts with other plugins.

  • Configure the control-panel\index.ts file's name attribute and the icon path. The name will be displayed as the plugin name in the Dashboard configuration dialog, and the icon will be displayed as the plugin icon in the Dashboard configuration dialog.

  • After completing the above steps, you will see your plugin on the Dashboard. However, it will not be usable yet. You need to configure the configProps and view attributes to make the plugin configurable and displayable. For specific configuration details, please refer to the following instructions.

  • Configure other items in control-panel\index.ts. All required types in types.ts must be filled out, otherwise, it will affect the final plugin effect.

Control-panel\index.ts Configuration Item Description

Detailed Explanation of control-panel\index.ts Configuration Items

AttributeDescriptionRequiredDefaultStored
namePlugin name, used to display the plugin name in the formYes-No
typePlugin type, used as the unique identifier for the plugin. It must not be duplicated. It is used to find the corresponding configuration file in actual use.Yes-Yes
classPlugin category, used to categorize the plugin. When adding a plugin on the dashboard, it will be displayed based on the category. If not filled, it defaults to the "other" category.Yes-No
iconPlugin icon, optional. The value can only be icon.png or left blank. It is used to display the plugin icon when adding a plugin on the dashboard. If not filled, the default icon is displayed.No-No
defaultColDefault number of columns occupied by the plugin on the dashboardYes-No
defaultRowDefault number of rows occupied by the plugin on the dashboardYes-No
minColMinimum number of columns occupied by the plugin on the dashboardYes-No
minRowMinimum number of rows occupied by the plugin on the dashboardYes-No
maxColMaximum number of columns occupied by the plugin on the dashboardYes-No
maxRowMaximum number of rows occupied by the plugin on the dashboardYes-No
configPropsConfigurable properties of the pluginYes-No
viewDisplay configuration of the plugin on the dashboardIf the view file under the plugin has custom configuration, this attribute can be omitted-No
configThe current component has configured valueNo-Yes
fullscreenableCan it be displayed in fullscreenNo-No
fullscreenIconSxPlugin fullscreen icon sx custom styleNo-No
posCurrent plugin position information within the layoutNo-Yes

Description of configProps Attributes

AttributeDescriptionTypeRequiredDefault
labelConfigured tab labelReactNodeYes
descriptionConfigured tab descriptionReactNodeNo
controlSetItemsConfiguration items under the configured tabControlSetItem[]Yes

Description of configProps.ControlSetItem Attributes

AttributeDescriptionTypeRequiredDefault
nameConfiguration item nameReactNodeYes
groupNameName of the group to which the configuration item belongsReactNodeNo
configConfiguration data for configuration itemsBaseControlConfig[]Yes

Description of ControlSetItem.config.BaseControlConfig Attributes

AttributeDescriptionTypeRequiredDefault
typeConfiguration form typestringNo-
labelConfiguration form labelReactNodeNo-
descriptionConfiguration form descriptionReactNodeNo-
controllerPropsConfiguration react form hook controller propsControllerPropsNo-
componentPropsConfiguration form component propsComponentPropsNo-
visibilityConfiguration form should be visibleFunctionNo-
mapStateToPropsConfiguration form map state to propsFunctionNo-
setValuesToFormConfigConfiguration form update config dataFunctionNo-

Description of view Attributes

AttributeDescriptionTypeRequiredDefault
tagHTML tag namestringYes
propsHTML tag attributesRecord<string, any>No
idHTML tag idstringNo
contentHTML tag contentstringNo
paramsParameters bound to the HTML contentstring[]No
showDependedHTML tag display dependencies. Refer to the configuration example for details.Record<string, any>No
childrenHTML child nodesViewProps[](self-nesting view attributes)No
classGeneral class namestringNo
styleGeneral stylestringNo
styleDependedStyle dependent on other plugin valuesRecord<string, string>No
themesHTML tag stylesRecord<'default' | 'dark', ViewThemeProps>No

control-panel\index.ts Configuration Example

/**
* The Image Control Panel Config
*/
const imageControlPanelConfig = (): ControlPanelConfig<ImageConfigType> => {
return {
class: 'data_card',
type: 'image',
name: 'image',
icon: ImageIcon,
defaultRow: 4,
defaultCol: 4,
minRow: 1,
minCol: 2,
maxRow: 12,
maxCol: 12,
configProps: [
{
label: 'image config',
controlSetItems: [
{
name: 'input',
config: {
type: 'Input',
label: t('common.label.title'),
controllerProps: {
name: 'label',
defaultValue: 'Title',
rules: {
maxLength: 35,
},
},
},
},
{
name: 'radio',
config: {
type: 'ToggleRadio',
controllerProps: {
name: 'dataType',
defaultValue: 'entity',
},
componentProps: {
options: [
{
label: t('common.label.select_entity'),
value: 'entity',
},
{
label: t('common.label.local_upload'),
value: 'upload',
},
{
label: t('common.label.url'),
value: 'url',
},
],
},
},
},
{
name: 'entitySelect',
config: {
type: 'EntitySelect',
label: t('common.label.entity'),
controllerProps: {
name: 'entity',
rules: {
required: true,
},
},
componentProps: {
required: true,
entityType: ['PROPERTY'],
entityValueType: ['STRING', 'LONG', 'DOUBLE', 'BOOLEAN'],
entityAccessMod: ['R', 'RW'],
},
visibility(formData) {
return (
!formData?.dataType || Boolean(formData?.dataType === 'entity')
);
},
},
},
{
name: 'upload',
config: {
type: 'Upload',
controllerProps: {
name: 'file',
rules: {
required: true,
},
},
componentProps: {
label: t('common.label.upload_image'),
multiple: false,
required: true,
matchExt: true,
},
visibility(formData) {
return Boolean(formData?.dataType === 'upload');
},
},
},
{
name: 'input',
config: {
type: 'Input',
label: t('common.label.url'),
controllerProps: {
name: 'url',
rules: {
required: true,
pattern: {
value: /^https?:\/\//,
message: t('valid.input.url'),
},
},
},
componentProps: {
required: true,
placeholder: t('common.placeholder.input'),
},
visibility(formData) {
return Boolean(formData?.dataType === 'url');
},
},
},
],
},
],
};
};