Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve]Support Sink input table name. #253

Closed
wants to merge 11 commits into from
Closed
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
1 change: 1 addition & 0 deletions seatunnel-ui/src/locales/en_US/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ export default {
sql_content_label: 'SQL',
sql_content_label_placeholder: 'please input the SQL statement',
query_validate: 'please input the SQL statement',
target_name_tips: 'Please enter or select table name',
},
synchronization_instance: {
pipeline_id: 'Pipeline Id',
Expand Down
5 changes: 3 additions & 2 deletions seatunnel-ui/src/locales/zh_CN/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,8 @@ export default {
check_model: '请检查模型信息',
sql_content_label: 'SQL',
sql_content_label_placeholder: '请输入SQL语句',
query_validate: '请输入SQL语句'
query_validate: '请输入SQL语句',
target_name_tips: '请输入或选择表名(必填)'
},
synchronization_instance: {
pipeline_id: 'Pipeline ID',
Expand Down Expand Up @@ -1110,7 +1111,7 @@ export default {
confirm: '确定',
cancel: '取消',
delete: '删除',
delete_confirm: '确定删除吗?',
delete_confirm: '确定删除吗?'
},
menu: {
fav: '收藏组件',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import {
getSceneModeOptions
} from './use-configuration-form'
import { useI18n } from 'vue-i18n'
import type { NodeType } from './types'

import type { NodeType, TableOption, State } from './types'
import { debounce } from 'lodash'

const ConfigurationForm = defineComponent({
Expand Down Expand Up @@ -75,16 +74,55 @@ const ConfigurationForm = defineComponent({

const onTableChange = (tableName: any) => {
state.model.tableName = tableName
if (props.nodeType === 'sink' && state.model.database) {
getTableOptions(state.model.database, '')
}
emit('tableNameChange', state.model)
}


const prevQueryTableName = ref('');
const onTableSearch = debounce((tableName: any) => {
// rely on database
if(state.model.database && prevQueryTableName.value !== tableName) {
getTableOptions(state.model.database, tableName)
prevQueryTableName.value = tableName
const prevQueryTableName = ref('')
const onTableSearch = debounce(async (tableName: any) => {
// If it is a sink node and there is input content.
if (props.nodeType === 'sink' && tableName) {
try {
// rely on database
if (state.model.database && prevQueryTableName.value !== tableName) {
await getTableOptions(state.model.database, tableName)
prevQueryTableName.value = tableName

// If there are no results after searching, add user input as a custom value to the options
const existingOption = state.tableOptions.find(
(option: TableOption) => option.value === tableName
)

if (!existingOption) {
const newOption: TableOption = {
label: tableName,
value: tableName
}
state.tableOptions = [...state.tableOptions, newOption]
}
}
} catch (err) {
// If the interface call fails, also use user input as a custom value
const existingOption = state.tableOptions.find(
(option: TableOption) => option.value === tableName
)

if (!existingOption) {
const newOption: TableOption = {
label: tableName,
value: tableName
}
state.tableOptions = [...state.tableOptions, newOption]
}
}
} else {
// The source node maintains its original logic
if (state.model.database && prevQueryTableName.value !== tableName) {
getTableOptions(state.model.database, tableName)
prevQueryTableName.value = tableName
}
}
}, 1000)

Expand Down Expand Up @@ -214,7 +252,12 @@ const ConfigurationForm = defineComponent({
onSearch={onTableSearch}
remote
virtualScroll
/>
clearable
tag={props.nodeType === 'sink'}
showArrow={true}
allowInput={props.nodeType === 'sink'}
placeholder={t('project.synchronization_definition.target_name_tips')}
/>
</NFormItem>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import type { SelectOption } from 'naive-ui'

export type NodeType = 'source' | 'sink' | 'transform'
export type OptionType = 'datasource' | 'database' | 'table'
export type { TableColumns } from 'naive-ui/es/data-table/src/interface'
Expand Down Expand Up @@ -59,3 +61,23 @@ export type InputPlugin = {
type: NodeType
}
export type NodeInfo = { [key: string]: any }

export interface TableOption {
label: string;
value: string;
}

export interface State {
model: any;
rules: any;
loading: boolean;
tableLoading: boolean;
databaseLoading: boolean;
datasourceLoading: boolean;
formStructure: any[];
formName: string;
formLocales: any;
datasourceOptions: SelectOption[];
databaseOptions: SelectOption[];
tableOptions: TableOption[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
findSink
} from '@/service/sync-task-definition'
import { useSynchronizationDefinitionStore } from '@/store/synchronization-definition'
import type { NodeType } from './types'
import type { NodeType, TableOption, State } from './types'
import type { SelectOption } from 'naive-ui'

export const useConfigurationForm = (
nodeType: NodeType,
Expand All @@ -56,7 +57,24 @@ export const useConfigurationForm = (
query: ''
}

const state = reactive({
const state = reactive<{
model: typeof initialModel;
loading: boolean;
datasourceOptions: any[];
datasourceLoading: boolean;
databaseOptions: any[];
databaseLoading: boolean;
tableOptions: TableOption[];
tableLoading: boolean;
formStructure: any[];
formLocales: any;
formName: string;
formLoading: boolean;
inputTableData: any[];
outputTableData: any[];
tableColumnsLoading: boolean;
rules: any;
}>({
model: cloneDeep(initialModel),
loading: false,
datasourceOptions: [],
Expand Down
Loading