create.config.ts
5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { DirectionEnum, RelationTypeEnum, RelationTypeNameEnum } from '../../../enum/form';
import { useRuleChainI18n } from '../../../hook/useRuleChainI18n';
export enum RelatedDeviceAttributeFieldsEnum {
  DEVICE_RELATIONS_QUERY = 'deviceRelationsQuery',
  TELL_FAILURE_IF_ABSENT = 'tellFailureIfAbsent',
  CLIENT_ATTRIBUTE_NAMES = 'clientAttributeNames',
  SHARED_ATTRIBUTE_NAMES = 'sharedAttributeNames',
  SERVER_ATTRIBUTE_NAMES = 'serverAttributeNames',
  LATEST_TS_KEY_NAMES = 'latestTsKeyNames',
  GET_LATEST_VALUE_WITH_TS = 'getLatestValueWithTs',
  FETCH_LAST_LEVEL_ONLY = 'fetchLastLevelOnly',
  // DEVICE_RELATIONS_QUERY
  DIRECTION = 'direction',
  MAX_LEVEL = 'maxLevel',
  RELATION_TYPE = 'relationType',
  DEVICE_TYPES = 'deviceTypes',
}
import { getDeviceTypes } from '/@/api/ruleChainDesigner';
import { FormSchema } from '/@/components/Form';
const { tLabel, tPlaceholder, t } = useRuleChainI18n('enrichment', 'relatedDeviceAttributes');
export interface ValueType {
  deviceRelationsQuery: DeviceRelationsQuery;
  tellFailureIfAbsent: boolean;
  clientAttributeNames: string[];
  sharedAttributeNames: string[];
  serverAttributeNames: string[];
  latestTsKeyNames: string[];
  getLatestValueWithTs: boolean;
}
export interface DeviceRelationsQuery {
  fetchLastLevelOnly: boolean;
  direction: string;
  maxLevel: number;
  relationType: string;
  deviceTypes: string[];
}
export const formSchemas: FormSchema[] = [
  {
    field: RelatedDeviceAttributeFieldsEnum.FETCH_LAST_LEVEL_ONLY,
    component: 'Checkbox',
    label: '',
    renderComponentContent: () => ({
      default: () => tLabel(RelatedDeviceAttributeFieldsEnum.FETCH_LAST_LEVEL_ONLY),
    }),
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.DIRECTION,
    component: 'Select',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.DIRECTION),
    colProps: { span: 12 },
    required: true,
    componentProps: {
      options: Object.keys(DirectionEnum).map((value) => ({
        label: t(`enum.direction.${value}`),
        value,
      })),
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.DIRECTION, 'choose'),
      getPopupContainer: () => document.body,
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.MAX_LEVEL,
    component: 'InputNumber',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.MAX_LEVEL),
    colProps: { span: 12 },
    componentProps: {
      min: 1,
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.MAX_LEVEL),
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.RELATION_TYPE,
    component: 'Select',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.RELATION_TYPE),
    componentProps: {
      options: Object.keys(RelationTypeEnum).map((value) => ({
        label: RelationTypeNameEnum[value],
        value,
      })),
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.RELATION_TYPE, 'choose'),
      getPopupContainer: () => document.body,
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.DEVICE_TYPES,
    component: 'ApiSelect',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.DEVICE_TYPES),
    componentProps: {
      mode: 'multiple',
      api: getDeviceTypes,
      labelField: 'type',
      valueField: 'type',
      getPopupContainer: () => document.body,
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.DEVICE_TYPES, 'choose'),
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.TELL_FAILURE_IF_ABSENT,
    component: 'Checkbox',
    label: '',
    renderComponentContent: () => ({
      default: () => tLabel(RelatedDeviceAttributeFieldsEnum.TELL_FAILURE_IF_ABSENT),
    }),
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.CLIENT_ATTRIBUTE_NAMES,
    component: 'Select',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.CLIENT_ATTRIBUTE_NAMES),
    componentProps: {
      open: false,
      mode: 'tags',
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.CLIENT_ATTRIBUTE_NAMES),
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.SHARED_ATTRIBUTE_NAMES,
    component: 'Select',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.SHARED_ATTRIBUTE_NAMES),
    componentProps: {
      open: false,
      mode: 'tags',
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.SHARED_ATTRIBUTE_NAMES),
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.SERVER_ATTRIBUTE_NAMES,
    component: 'Select',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.SERVER_ATTRIBUTE_NAMES),
    componentProps: {
      open: false,
      mode: 'tags',
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.SERVER_ATTRIBUTE_NAMES),
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.LATEST_TS_KEY_NAMES,
    component: 'Select',
    label: tLabel(RelatedDeviceAttributeFieldsEnum.LATEST_TS_KEY_NAMES),
    componentProps: {
      open: false,
      mode: 'tags',
      placeholder: tPlaceholder(RelatedDeviceAttributeFieldsEnum.LATEST_TS_KEY_NAMES),
    },
  },
  {
    field: RelatedDeviceAttributeFieldsEnum.GET_LATEST_VALUE_WITH_TS,
    component: 'Checkbox',
    label: '',
    renderComponentContent: () => ({
      default: () => tLabel(RelatedDeviceAttributeFieldsEnum.GET_LATEST_VALUE_WITH_TS),
    }),
  },
];