Dashboard Plugin

Overview

This article is aimed at InLong Dashboard plug-in developers, trying to describe the process of developing a Dashboard plug-in as comprehensively as possible, helping developers quickly add a data storage LoadNode, and making plug-in development easier. The InLong Dashboard itself acts as a front-end console, built with the React framework.

Extend a new Load Node

In the inlong-dashboard/src/components/MetaData directory, create a new StorageExample.tsx file, and at the same time export the file in the index.ts file in the current directory (refer to the existing LoadNode writing method ), which completes a new sink named Example.

  1. // export in index
  2. export const Storages: StoragesType[] = [
  3. // ... omit existing code
  4. {
  5. label: 'Example',
  6. value: 'Example',
  7. ...StorageExample,
  8. },
  9. ];

Next, we will introduce how to define the internal structure of the LoadNode.

In the definition of LoadNode, we can view the unified specification of our agreement through the type declaration in the import type { GetStorageFormFieldsType, GetStorageColumnsType } from '@/utils/metaData'; file, here we show a simplest LoadNode definition (emphasis inside the --Focus-- tag):

  1. import { getColsFromFields, GetStorageFormFieldsType } from '@/utils/metaData';
  2. import { ColumnsType } from 'antd/es/table';
  3. import { excludeObject } from '@/utils';
  4. const getForm: GetStorageFormFieldsType = (
  5. type: 'form' | 'col' = 'form',
  6. { currentValues, isEdit } = {} as any,
  7. ) => {
  8. // -- Focus Start --
  9. const fileds = [
  10. {
  11. name: 'name',
  12. type: 'input',
  13. label: 'Name',
  14. _inTable: true,
  15. },
  16. {
  17. name: 'sex',
  18. type: 'radio',
  19. label: 'Sex',
  20. initialValue: 'female',
  21. props: {
  22. options: [
  23. {
  24. label: 'female',
  25. value: 'female',
  26. },
  27. {
  28. label: 'male',
  29. value: 'male',
  30. },
  31. ],
  32. disabled: isEdit && [110, 130].includes(currentValues?.status),
  33. },
  34. _inTable: true,
  35. },
  36. {
  37. name: 'age',
  38. type: 'inputnumber',
  39. label: 'Age',
  40. props: {
  41. min: 1,
  42. max: 200,
  43. },
  44. },
  45. // -- Focus End --
  46. ];
  47. // The following is a generic return
  48. return type === 'col'
  49. ? getColsFromFields(fileds)
  50. : fileds.map(item => excludeObject(['_inTable'], item));
  51. };
  52. // The following is a generic export
  53. const tableColumns = getForm('col') as ColumnsType;
  54. export const StorageExample = {
  55. getForm,
  56. tableColumns,
  57. };

In the above example, we define a sink of Example, which consists of three fields: name, sex, age. The field name corresponds to the name attribute (the API interface field that interacts with the manager), and the type attribute represents the display on the front-end page. The input form usually includes input, inputnumber, radio, select and other forms. More complex display forms or the complete definition of the entire object can be obtained through the ts type description.