diff --git a/inlong-dashboard/src/components/MetaData/StorageOracle.tsx b/inlong-dashboard/src/components/MetaData/StorageOracle.tsx index 745d8ccac4a..b502c350695 100644 --- a/inlong-dashboard/src/components/MetaData/StorageOracle.tsx +++ b/inlong-dashboard/src/components/MetaData/StorageOracle.tsx @@ -48,7 +48,6 @@ const oracleFieldTypes = [ 'CLOB', 'RAW', 'BLOB', - // 'interval', ].map(item => ({ label: item, value: item, @@ -65,7 +64,7 @@ const getForm: GetStorageFormFieldsType = ( name: 'jdbcUrl', rules: [{ required: true }], props: { - placeholder: 'jdbc:oracle:thin://127.0.0.1:3306/write', + placeholder: 'jdbc:oracle:thin://127.0.0.1:1521/db_name', disabled: isEdit && [110, 130].includes(currentValues?.status), style: { width: 500 }, }, @@ -181,6 +180,7 @@ const getFieldListColumns: GetStorageColumnsType = (dataType, currentValues) => }, { title: i18n.t('components.AccessHelper.StorageMetaData.Oracle.IsMetaField'), + initialValue: 0, dataIndex: 'isMetaField', type: 'select', props: (text, record, idx, isNew) => ({ diff --git a/inlong-dashboard/src/components/MetaData/StoragePostgreSQL.tsx b/inlong-dashboard/src/components/MetaData/StoragePostgreSQL.tsx new file mode 100644 index 00000000000..d71addd7994 --- /dev/null +++ b/inlong-dashboard/src/components/MetaData/StoragePostgreSQL.tsx @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { + getColsFromFields, + GetStorageColumnsType, + GetStorageFormFieldsType, +} from '@/utils/metaData'; +import { ColumnsType } from 'antd/es/table'; +import EditableTable, { ColumnsItemProps } from '@/components/EditableTable'; +import i18n from '@/i18n'; +import { excludeObject } from '@/utils'; +import { sourceDataFields } from './SourceDataFields'; + +// postgreSQLFieldTypes +const postgreSQLFieldTypes = [ + 'SMALLINT', + 'INT2', + 'SMALLSERIAL', + 'SERIAL2', + 'INTEGER', + 'SERIAL', + 'BIGINT', + 'BIGSERIAL', + 'REAL', + 'FLOAT4', + 'FLOAT8', + 'DOUBLE', + 'NUMERIC', + 'DECIMAL', + 'BOOLEAN', + 'DATE', + 'TIME', + 'TIMESTAMP', + 'CHAR', + 'CHARACTER', + 'VARCHAR', + 'TEXT', + 'BYTEA', +].map(item => ({ + label: item, + value: item, +})); + +const getForm: GetStorageFormFieldsType = ( + type, + { currentValues, inlongGroupId, isEdit, dataType, form } = {} as any, +) => { + const fileds = [ + { + type: 'input', + label: 'JDBC URL', + name: 'jdbcUrl', + rules: [{ required: true }], + props: { + placeholder: 'jdbc:postgresql://127.0.0.1:5432/db_name', + disabled: isEdit && [110, 130].includes(currentValues?.status), + style: { width: 500 }, + }, + }, + { + type: 'input', + label: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.DbName'), + name: 'dbName', + rules: [{ required: true }], + props: { + disabled: isEdit && [110, 130].includes(currentValues?.status), + }, + _inTable: true, + }, + { + type: 'input', + label: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.TableName'), + name: 'tableName', + rules: [{ required: true }], + props: { + disabled: isEdit && [110, 130].includes(currentValues?.status), + }, + _inTable: true, + }, + { + type: 'input', + label: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.PrimaryKey'), + name: 'primaryKey', + rules: [{ required: true }], + props: { + disabled: isEdit && [110, 130].includes(currentValues?.status), + }, + _inTable: true, + }, + { + type: 'radio', + label: i18n.t('components.AccessHelper.StorageMetaData.EnableCreateResource'), + name: 'enableCreateResource', + rules: [{ required: true }], + initialValue: 1, + tooltip: i18n.t('components.AccessHelper.StorageMetaData.EnableCreateResourceHelp'), + props: { + disabled: isEdit && [110, 130].includes(currentValues?.status), + options: [ + { + label: i18n.t('basic.Yes'), + value: 1, + }, + { + label: i18n.t('basic.No'), + value: 0, + }, + ], + }, + }, + { + type: 'input', + label: i18n.t('components.AccessHelper.StorageMetaData.Username'), + name: 'username', + rules: [{ required: true }], + props: { + disabled: isEdit && [110, 130].includes(currentValues?.status), + }, + _inTable: true, + }, + { + type: 'password', + label: i18n.t('components.AccessHelper.StorageMetaData.Password'), + name: 'password', + rules: [{ required: true }], + props: { + disabled: isEdit && [110, 130].includes(currentValues?.status), + style: { + maxWidth: 500, + }, + }, + }, + { + type: ( + !isEdit || isNew} + /> + ), + name: 'sinkFieldList', + }, + ]; + + return type === 'col' + ? getColsFromFields(fileds) + : fileds.map(item => excludeObject(['_inTable'], item)); +}; + +const getFieldListColumns: GetStorageColumnsType = (dataType, currentValues) => { + return [ + ...sourceDataFields, + { + title: `POSTGRESQL${i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldName')}`, + dataIndex: 'fieldName', + initialValue: '', + rules: [ + { required: true }, + { + pattern: /^[a-z][0-9a-z_]*$/, + message: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldNameRule'), + }, + ], + props: (text, record, idx, isNew) => ({ + disabled: [110, 130].includes(currentValues?.status as number) && !isNew, + }), + }, + { + title: `POSTGRESQL${i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldType')}`, + dataIndex: 'fieldType', + initialValue: postgreSQLFieldTypes[0].value, + type: 'select', + props: (text, record, idx, isNew) => ({ + options: postgreSQLFieldTypes, + disabled: [110, 130].includes(currentValues?.status as number) && !isNew, + }), + rules: [{ required: true }], + }, + { + title: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.IsMetaField'), + initialValue: 0, + dataIndex: 'isMetaField', + type: 'select', + props: (text, record, idx, isNew) => ({ + options: [ + { + label: i18n.t('basic.Yes'), + value: 1, + }, + { + label: i18n.t('basic.No'), + value: 0, + }, + ], + }), + }, + { + title: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldFormat'), + dataIndex: 'fieldFormat', + initialValue: '', + type: 'autocomplete', + props: (text, record, idx, isNew) => ({ + options: ['MICROSECONDS', 'MILLISECONDS', 'SECONDS', 'SQL', 'ISO_8601'].map(item => ({ + label: item, + value: item, + })), + }), + visible: (text, record) => + ['BIGINT', 'DATE', 'TIMESTAMP'].includes(record.fieldType as string), + }, + { + title: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldDescription'), + dataIndex: 'fieldComment', + initialValue: '', + }, + ] as ColumnsItemProps[]; +}; + +const tableColumns = getForm('col') as ColumnsType; + +export const StoragePostgreSQL = { + getForm, + getFieldListColumns, + tableColumns, +}; diff --git a/inlong-dashboard/src/components/MetaData/index.ts b/inlong-dashboard/src/components/MetaData/index.ts index a502e37387e..66a6bd8a934 100644 --- a/inlong-dashboard/src/components/MetaData/index.ts +++ b/inlong-dashboard/src/components/MetaData/index.ts @@ -27,6 +27,7 @@ import { StorageEs } from './StorageEs'; import { StorageGreenplum } from './StorageGreenplum'; import { StorageMySQL } from './StorageMySQL'; import { StorageOracle } from './StorageOracle'; +import { StoragePostgreSQL } from './StoragePostgreSQL'; export interface StoragesType { label: string; @@ -84,4 +85,9 @@ export const Storages: StoragesType[] = [ value: 'ORACLE', ...StorageOracle, }, + { + label: 'PostgreSQL', + value: 'POSTGRES', + ...StoragePostgreSQL, + }, ]; diff --git a/inlong-dashboard/src/locales/cn.json b/inlong-dashboard/src/locales/cn.json index d0bf3c6f8bd..e520dc7ee5f 100644 --- a/inlong-dashboard/src/locales/cn.json +++ b/inlong-dashboard/src/locales/cn.json @@ -143,6 +143,15 @@ "components.AccessHelper.StorageMetaData.Oracle.IsMetaField": "是否为元字段", "components.AccessHelper.StorageMetaData.Oracle.FieldFormat": "字段格式", "components.AccessHelper.StorageMetaData.Oracle.FieldDescription": "字段描述", + "components.AccessHelper.StorageMetaData.PostgreSQL.DbName": "DB名称", + "components.AccessHelper.StorageMetaData.PostgreSQL.TableName": "表名称", + "components.AccessHelper.StorageMetaData.PostgreSQL.PrimaryKey": "主键", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldName": "字段名", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldNameRule": "以英文字母或下划线开头,只能包含英文字母、数字、下划线", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldType": "字段类型", + "components.AccessHelper.StorageMetaData.PostgreSQL.IsMetaField": "是否为元字段", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldFormat": "字段格式", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldDescription": "字段描述", "components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "条/秒", "components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "消息中间件", "components.AccessHelper.FieldsConfig.businessFields.AccessSize": "按天接入大小", diff --git a/inlong-dashboard/src/locales/en.json b/inlong-dashboard/src/locales/en.json index a63530cf30e..4076a9ec31c 100644 --- a/inlong-dashboard/src/locales/en.json +++ b/inlong-dashboard/src/locales/en.json @@ -143,6 +143,15 @@ "components.AccessHelper.StorageMetaData.Oracle.IsMetaField": "IsMetaField", "components.AccessHelper.StorageMetaData.Oracle.FieldFormat": "FieldFormat", "components.AccessHelper.StorageMetaData.Oracle.FieldDescription": "FieldDescription", + "components.AccessHelper.StorageMetaData.PostgreSQL.DbName": "DbName", + "components.AccessHelper.StorageMetaData.PostgreSQL.TableName": "TableName", + "components.AccessHelper.StorageMetaData.PostgreSQL.PrimaryKey": "PrimaryKey", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldName": "FieldName", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldNameRule": "At the beginning of English letters, only English letters, numbers, and underscores", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldType": "FieldType", + "components.AccessHelper.StorageMetaData.PostgreSQL.IsMetaField": "IsMetaField", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldFormat": "FieldFormat", + "components.AccessHelper.StorageMetaData.PostgreSQL.FieldDescription": "FieldDescription", "components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "Stripe / S", "components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "Middleware", "components.AccessHelper.FieldsConfig.businessFields.AccessSize": "Access Size",