create.config.ts
2.42 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
import { AttributeConfiguration } from '/@/views/rule/designer/src/components/AttributeConfiguration';
import { FileItemType, getFileData } from '../AzureIotHub/CredentialsCard/config';
import { FormSchema, useComponentRegister } from '/@/components/Form';
// GCP pubsub
export enum GcpPubsubFieldsEnum {
  PROJECT_ID = 'projectId',
  TOPIC_NAME = 'topicName',
  SERVICE_ACCOUNT_KEY = 'serviceAccountKey',
  SERVICE_ACCOUNT_KEY_FILE_NAME = 'serviceAccountKeyFileName',
  MESSAGE_ATTRIBUTES = 'messageAttributes',
}
import { useRuleChainI18n } from '../../../hook/useRuleChainI18n';
const { tLabel, tPlaceholder } = useRuleChainI18n('external', 'gcpPubsub');
useComponentRegister('AttributeConfiguration', AttributeConfiguration);
export const formSchemas: FormSchema[] = [
  {
    field: GcpPubsubFieldsEnum.PROJECT_ID,
    label: tLabel(GcpPubsubFieldsEnum.PROJECT_ID),
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GcpPubsubFieldsEnum.PROJECT_ID),
    },
  },
  {
    field: GcpPubsubFieldsEnum.TOPIC_NAME,
    label: tLabel(GcpPubsubFieldsEnum.TOPIC_NAME),
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GcpPubsubFieldsEnum.TOPIC_NAME),
    },
  },
  {
    field: GcpPubsubFieldsEnum.SERVICE_ACCOUNT_KEY_FILE_NAME,
    label: tLabel(GcpPubsubFieldsEnum.SERVICE_ACCOUNT_KEY_FILE_NAME),
    component: 'Input',
    show: false,
    componentProps: {
      placeholder: tPlaceholder(GcpPubsubFieldsEnum.TOPIC_NAME),
    },
  },
  {
    field: GcpPubsubFieldsEnum.SERVICE_ACCOUNT_KEY,
    label: tLabel(GcpPubsubFieldsEnum.SERVICE_ACCOUNT_KEY),
    component: 'ApiUpload',
    valueField: 'fileList',
    changeEvent: 'update:fileList',
    required: true,
    componentProps: ({ formActionType }) => {
      const { setFieldsValue } = formActionType;
      return {
        overFileLimitHiddenUploadEntry: true,
        api: getFileData,
        'onUpdate:fileList'(file: FileItemType[]) {
          setFieldsValue({ [GcpPubsubFieldsEnum.SERVICE_ACCOUNT_KEY_FILE_NAME]: file?.[0]?.name });
        },
      };
    },
  },
  {
    field: GcpPubsubFieldsEnum.MESSAGE_ATTRIBUTES,
    label: tLabel(GcpPubsubFieldsEnum.MESSAGE_ATTRIBUTES),
    component: 'AttributeConfiguration',
    helpMessage:
      'Use ${metadataKey} for value from metadata, $[messageKey] for value from message body in name/value fields',
    slot: GcpPubsubFieldsEnum.MESSAGE_ATTRIBUTES,
  },
];