create.config.ts 2.42 KB
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,
  },
];