Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 245 additions & 0 deletions inlong-dashboard/src/components/MetaData/StorageTDSQLPostgreSQL.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
/*
* 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';

// tdsqlpostgreSQLFieldTypes
const tdsqlpostgreSQLFieldTypes = [
'SMALLINT',
'SMALLSERIAL',
'INT2',
'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.TDSQLPostgreSQL.SchemaName'),
name: 'schemaName',
rules: [{ required: true }],
props: {
disabled: isEdit && [110, 130].includes(currentValues?.status),
},
_inTable: true,
},
{
type: 'input',
label: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.TableName'),
name: 'tableName',
rules: [{ required: true }],
props: {
disabled: isEdit && [110, 130].includes(currentValues?.status),
},
_inTable: true,
},
{
type: 'input',
label: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.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: (
<EditableTable
size="small"
columns={getFieldListColumns(dataType, currentValues)}
canDelete={(record, idx, isNew) => !isEdit || isNew}
/>
),
name: 'sinkFieldList',
},
];

return type === 'col'
? getColsFromFields(fileds)
: fileds.map(item => excludeObject(['_inTable'], item));
};

const getFieldListColumns: GetStorageColumnsType = (dataType, currentValues) => {
return [
...sourceDataFields,
{
title: `TDSQLPOSTGRESQL${i18n.t(
'components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldName',
)}`,
dataIndex: 'fieldName',
initialValue: '',
rules: [
{ required: true },
{
pattern: /^[a-z][0-9a-z_]*$/,
message: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldNameRule'),
},
],
props: (text, record, idx, isNew) => ({
disabled: [110, 130].includes(currentValues?.status as number) && !isNew,
}),
},
{
title: `TDSQLPOSTGRESQL${i18n.t(
'components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldType',
)}`,
dataIndex: 'fieldType',
initialValue: tdsqlpostgreSQLFieldTypes[0].value,
type: 'select',
props: (text, record, idx, isNew) => ({
options: tdsqlpostgreSQLFieldTypes,
disabled: [110, 130].includes(currentValues?.status as number) && !isNew,
}),
rules: [{ required: true }],
},
{
title: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.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.TDSQLPostgreSQL.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.TDSQLPostgreSQL.FieldDescription'),
dataIndex: 'fieldComment',
initialValue: '',
},
] as ColumnsItemProps[];
};

const tableColumns = getForm('col') as ColumnsType;

export const StorageTDSQLPostgreSQL = {
getForm,
getFieldListColumns,
tableColumns,
};
6 changes: 6 additions & 0 deletions inlong-dashboard/src/components/MetaData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { StorageMySQL } from './StorageMySQL';
import { StorageOracle } from './StorageOracle';
import { StoragePostgreSQL } from './StoragePostgreSQL';
import { StorageSQLServer } from './StorageSQLServer';
import { StorageTDSQLPostgreSQL } from './StorageTDSQLPostgreSQL';

export interface StoragesType {
label: string;
Expand Down Expand Up @@ -96,4 +97,9 @@ export const Storages: StoragesType[] = [
value: 'SQLSERVER',
...StorageSQLServer,
},
{
label: 'TDSQLPostgreSQL',
value: 'TDSQLPOSTGRESQL',
...StorageTDSQLPostgreSQL,
},
];
9 changes: 9 additions & 0 deletions inlong-dashboard/src/locales/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@
"components.AccessHelper.StorageMetaData.SQLServer.IsMetaField": "是否为元字段",
"components.AccessHelper.StorageMetaData.SQLServer.FieldFormat": "字段格式",
"components.AccessHelper.StorageMetaData.SQLServer.FieldDescription": "字段描述",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.SchemaName": "架构名称",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.TableName": "表名称",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.PrimaryKey": "主键",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldName": "字段名",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldNameRule": "以英文字母或下划线开头,只能包含英文字母、数字、下划线",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldType": "字段类型",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.IsMetaField": "是否为元字段",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldFormat": "字段格式",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldDescription": "字段描述",
"components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "条/秒",
"components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "消息中间件",
"components.AccessHelper.FieldsConfig.businessFields.AccessSize": "按天接入大小",
Expand Down
9 changes: 9 additions & 0 deletions inlong-dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@
"components.AccessHelper.StorageMetaData.SQLServer.IsMetaField": "IsMetaField",
"components.AccessHelper.StorageMetaData.SQLServer.FieldFormat": "FieldFormat",
"components.AccessHelper.StorageMetaData.SQLServer.FieldDescription": "FieldDescription",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.SchemaName": "SchemaName",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.TableName": "TableName",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.PrimaryKey": "PrimaryKey",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldName": "FieldName",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldNameRule": "At the beginning of English letters, only English letters, numbers, and underscores",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldType": "FieldType",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.IsMetaField": "IsMetaField",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldFormat": "FieldFormat",
"components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldDescription": "FieldDescription",
"components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "Stripe / S",
"components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "Middleware",
"components.AccessHelper.FieldsConfig.businessFields.AccessSize": "Access Size",
Expand Down