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
16 changes: 16 additions & 0 deletions packages/api/src/core/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export function batchUpdateConnectionTags(params: any) {
return requestClient.patch(`${BASE_URL}/batchUpdateListtags`, params)
}

export interface BatchUpdateConnectionAgentSettingsParams {
requestId: string
connectionIds: string[]
settings: {
accessNodeType: string
accessNodeProcessId: string | null
priorityProcessId: string | null
}
}

export function batchUpdateConnectionAgentSettings(
params: BatchUpdateConnectionAgentSettingsParams,
) {
return requestClient.patch(`${BASE_URL}/batch-agent-settings`, params)
}

export function checkConnection(id: string, params: any) {
return requestClient.patch(`${BASE_URL}/${id}`, params)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/business/src/locale/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default {
packages_business_priorityProcessId: 'Tag-Based Scheduling',
packages_business_connection_form_access_node_tip:
'When using the automatic mode, the platform will assign nodes for connection access, while in manual mode, the user is responsible for manually specifying the nodes for access',
packages_business_connections_list_batch_agent_settings:
'Batch Agent Settings',
packages_business_agent_settings_dialog_title: 'Batch Agent Settings',
packages_business_agent_settings_dialog_subtitle:
'The same Agent settings will be prepared for {count} selected connections.',
packages_business_connection_form_give_up: 'Give Up',
packages_business_share_form_setting_table_name: 'Store MongoDB table name',
packages_business_share_form_setting_log_time: 'Log save time',
Expand Down
4 changes: 4 additions & 0 deletions packages/business/src/locale/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export default {
packages_business_priorityProcessId: '标签内调度方式',
packages_business_connection_form_access_node_tip:
'自动情况下由平台分配节点进行连接访问,手动情况下由用户手动指定节点进行访问',
packages_business_connections_list_batch_agent_settings: '批量设置 Agent',
packages_business_agent_settings_dialog_title: '批量设置 Agent',
packages_business_agent_settings_dialog_subtitle:
'将为选中的 {count} 个连接生成相同的 Agent 设置。',
packages_business_connection_form_give_up: '放弃',
packages_business_share_form_setting_table_name: '存储MongoDB表名',
packages_business_share_form_setting_log_time: '日志保存时长',
Expand Down
4 changes: 4 additions & 0 deletions packages/business/src/locale/lang/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export default {
packages_business_priorityProcessId: '標籤內調度方式',
packages_business_connection_form_access_node_tip:
'自動情況下由平台分配節點進行連接訪問,手動情況下由用戶手動指定節點進行訪問',
packages_business_connections_list_batch_agent_settings: '批量設定 Agent',
packages_business_agent_settings_dialog_title: '批量設定 Agent',
packages_business_agent_settings_dialog_subtitle:
'將為選取的 {count} 個連接產生相同的 Agent 設定。',
packages_business_connection_form_give_up: '放棄',
packages_business_share_form_setting_table_name: '存儲MongoDB表名',
packages_business_share_form_setting_log_time: '日誌保存時長',
Expand Down
181 changes: 181 additions & 0 deletions packages/business/src/views/connections/BatchAgentSettingsDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<script setup lang="ts">
import { action } from '@formily/reactive'
import SchemaToForm from '@tap/form/src/SchemaToForm.vue'
import { useI18n } from '@tap/i18n'
import { uuid } from '@tap/shared'
import { computed, ref } from 'vue'
import {
AGENT_GROUP_ALLOCATION,
AUTOMATIC_AGENT_ALLOCATION,
MANUAL_AGENT_ALLOCATION,
createAgentSettingsProperties,
loadAccessNodeOptions,
type AgentAllocationType,
type BatchAgentSettingsPayload,
} from './agentSettingsSchema'

interface ConnectionRow {
id: string
name?: string
shareCdcEnable?: boolean
}

const emit = defineEmits<{
submit: [payload: BatchAgentSettingsPayload]
}>()

const { t } = useI18n()
const isDaas = import.meta.env.VUE_APP_PLATFORM === 'DAAS'
const visible = ref(false)
const selectedConnections = ref<ConnectionRow[]>([])
const schemaForm = ref<InstanceType<typeof SchemaToForm> | null>(null)
const formValues = ref<Record<string, any>>({})
const formKey = ref(0)

const schema = computed(() => ({
type: 'object',
properties: {
__TAPDATA: {
type: 'object',
properties: {
shareCdcEnable: {
type: 'boolean',
'x-display': 'hidden',
},
shareCDCExternalStorageId: {
type: 'string',
'x-display': 'hidden',
},
...createAgentSettingsProperties((key) => t(key), isDaas),
},
},
},
}))

const formScope = {
$isDaas: isDaas,
useAsyncDataSource: (
service: (...args: any[]) => Promise<any>,
fieldName = 'dataSource',
...serviceParams: any[]
) => {
return (field: any) => {
field.loading = true
service({ field }, ...serviceParams).then(
action.bound((data) => {
if (fieldName === 'value') {
field.setValue(data)
} else {
field[fieldName] = data
}
field.loading = false
}),
)
}
},
loadAccessNode: loadAccessNodeOptions,
}

const open = (connections: ConnectionRow[]) => {
selectedConnections.value = [...connections]
const hasSharedCdcConnection = connections.some(
(connection) => connection.shareCdcEnable,
)
const requiresManualAgent = !isDaas && hasSharedCdcConnection

formValues.value = {
__TAPDATA: {
shareCdcEnable: hasSharedCdcConnection,
shareCDCExternalStorageId: '',
accessNodeType: requiresManualAgent
? MANUAL_AGENT_ALLOCATION
: AUTOMATIC_AGENT_ALLOCATION,
accessNodeProcessId: '',
priorityProcessId: '',
},
}
formKey.value += 1
visible.value = true
}

const handleClose = () => {
visible.value = false
selectedConnections.value = []
}

const handleSubmit = async () => {
const form = schemaForm.value?.getForm()
if (!form) return

try {
await form.validate()
} catch {
document
.querySelector('.formily-element-plus-form-item-error')
?.scrollIntoView({ block: 'center' })
return
}

const { __TAPDATA = {} } = schemaForm.value?.getFormValues() || {}
const accessNodeType = __TAPDATA.accessNodeType as AgentAllocationType
const usesAgent = accessNodeType !== AUTOMATIC_AGENT_ALLOCATION
const payload: BatchAgentSettingsPayload = {
requestId: uuid(),
connectionIds: selectedConnections.value.map(({ id }) => id),
settings: {
accessNodeType,
accessNodeProcessId: usesAgent
? __TAPDATA.accessNodeProcessId || null
: null,
priorityProcessId:
accessNodeType === AGENT_GROUP_ALLOCATION
? __TAPDATA.priorityProcessId || null
: null,
},
}

emit('submit', payload)
}

defineExpose({ open, close: handleClose })
</script>

<template>
<ElDialog
v-model="visible"
:title="t('packages_business_agent_settings_dialog_title')"
width="560px"
:close-on-click-modal="false"
append-to-body
destroy-on-close
@closed="handleClose"
>
<div class="mb-4 text-muted">
{{
t('packages_business_agent_settings_dialog_subtitle', {
count: selectedConnections.length,
})
}}
</div>
<SchemaToForm
:key="formKey"
ref="schemaForm"
:schema="schema"
:scope="formScope"
:value="formValues"
layout="vertical"
label-width="100%"
class="w-100"
/>
<template #footer>
<ElButton @click="handleClose">{{ t('public_button_cancel') }}</ElButton>
<ElButton
type="primary"
:disabled="!selectedConnections.length"
@click="handleSubmit"
>
{{ t('public_button_confirm') }}
</ElButton>
</template>
</ElDialog>
</template>
Loading
Loading