Skip to content

Commit 9fafdbb

Browse files
committed
feat: enhance TableSelect component with partition table support and dynamic method fetching
1 parent b074c40 commit 9fafdbb

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

packages/dag/src/components/form/table-select/index.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const useTableExist = (attrs, refs, connectionId) => {
9292

9393
export const TableSelect = observer(
9494
defineComponent({
95-
props: ['reloadTime', 'connectionId'],
95+
props: ['reloadTime', 'connectionId', 'hasPartition', 'syncPartitionTableEnable', 'method'],
9696
setup(props, { attrs, listeners, emit, root, refs }) {
9797
const { taskId, activeNodeId } = root.$store.state.dataflow
9898

@@ -156,6 +156,53 @@ export const TableSelect = observer(
156156

157157
reWatch()
158158

159+
let cacheTables = []
160+
161+
watch(
162+
() => props.syncPartitionTableEnable,
163+
() => {
164+
cacheTables = []
165+
loadSelectData()
166+
}
167+
)
168+
169+
const fetchMethod = async (filter, config) => {
170+
if (props.hasPartition) {
171+
if (cacheTables.length) {
172+
if (!filter.where?.name?.like)
173+
return {
174+
items: cacheTables,
175+
total: cacheTables.length
176+
}
177+
178+
const search = filter.where?.name?.like.toLowerCase()
179+
const filtered = cacheTables.filter(it => it.value.toLowerCase().includes(search))
180+
return {
181+
items: filtered,
182+
total: filtered.length
183+
}
184+
} else {
185+
const res = await metadataInstancesApi.pagePartitionTables({
186+
connectionId: props.connectionId,
187+
limit: 0,
188+
syncPartitionTableEnable: props.syncPartitionTableEnable
189+
})
190+
cacheTables = res.items.map(it => ({
191+
label: it.tableName + (it.tableComment ? `(${it.tableComment})` : ''),
192+
value: it.tableName
193+
}))
194+
return {
195+
items: cacheTables,
196+
total: cacheTables.length
197+
}
198+
}
199+
} else {
200+
cacheTables = []
201+
202+
return props.method(filter, config)
203+
}
204+
}
205+
159206
onBeforeUnmount(() => {
160207
unWatch?.()
161208
})
@@ -206,6 +253,7 @@ export const TableSelect = observer(
206253

207254
return (
208255
<AsyncSelect
256+
method={fetchMethod}
209257
loading={loading.value}
210258
class="async-select"
211259
ref="select"

packages/dag/src/nodes/Table.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ export class Table extends NodeType {
197197
method: '{{loadTable}}',
198198
connectionId: '{{$values.connectionId}}',
199199
itemType: 'object',
200-
itemQuery: 'value'
200+
itemQuery: 'value',
201+
hasPartition: `{{$values.attrs.capabilities.some(item => item.id==="source_support_partition")}}`,
202+
syncPartitionTableEnable: '{{$values.syncSourcePartitionTableEnable}}'
201203
},
202204
'x-reactions': [
203205
{
@@ -238,6 +240,25 @@ export class Table extends NodeType {
238240
}
239241
},
240242

243+
syncSourcePartitionTableEnable: {
244+
title: i18n.t('packages_dag_syncSourcePartitionTableEnable'),
245+
type: 'boolean',
246+
default: true,
247+
'x-decorator': 'FormItem',
248+
'x-decorator-props': {
249+
class: 'flex-1',
250+
tooltip: i18n.t('packages_dag_syncSourcePartitionTableEnable_tip')
251+
},
252+
'x-component': 'Switch',
253+
'x-reactions': {
254+
fulfill: {
255+
state: {
256+
visible: '{{$values.attrs.capabilities.some(item => item.id==="source_support_partition")}}'
257+
}
258+
}
259+
}
260+
},
261+
241262
needDynamicTableName: {
242263
type: 'boolean',
243264
title: i18n.t('packages_dag_dynamic_date_suffix'),

0 commit comments

Comments
 (0)