Skip to content

Commit 62432f2

Browse files
committed
refactor: enhance TableSelector component with error handling and localization
- Simplified imports by removing unused APIs and consolidating component imports. - Added error handling for table selection to provide user feedback when tables do not exist. - Implemented localization for error messages using the `useI18n` hook. - Updated clipboard submission logic to prevent adding invalid tables and improved autofix functionality.
1 parent 5833c57 commit 62432f2

File tree

1 file changed

+46
-20
lines changed

1 file changed

+46
-20
lines changed

packages/dag/src/components/form/table-selector/TableSelector.vue

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
<script setup lang="ts">
2-
import {
3-
connectionsApi,
4-
metadataInstancesApi,
5-
taskApi,
6-
workerApi,
7-
} from '@tap/api'
8-
import { RightBoldOutlined, VEmpty } from '@tap/component'
9-
import VIcon from '@tap/component/src/base/VIcon'
2+
import { metadataInstancesApi, taskApi } from '@tap/api'
3+
import { RightBoldOutlined, VEmpty, VIcon } from '@tap/component'
104
import OverflowTooltip from '@tap/component/src/overflow-tooltip'
5+
import { useI18n } from '@tap/i18n'
116
import { computed, ref, watch } from 'vue'
127
import { RecycleScroller } from 'vue-virtual-scroller'
138
import { useStore } from 'vuex'
@@ -17,6 +12,7 @@ import { getPrimaryKeyTablesByType } from '../../../util'
1712
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
1813
1914
const store = useStore()
15+
const { t } = useI18n()
2016
2117
// Props
2218
const props = defineProps({
@@ -25,7 +21,7 @@ const props = defineProps({
2521
required: true,
2622
},
2723
value: {
28-
type: Array as PropType<string[]>,
24+
type: Array,
2925
default: () => [],
3026
},
3127
disabled: Boolean,
@@ -232,17 +228,48 @@ const changeSeletedMode = () => {
232228
}
233229
}
234230
231+
const getErrorTables = (tables: string[]) => {
232+
const errors = {}
233+
const allTables = table.value.tables
234+
235+
if (!loading.value) {
236+
tables.forEach((table) => {
237+
if (!allTables.includes(table)) {
238+
errors[table] = t(
239+
'packages_form_component_table_selector_error_not_exit',
240+
)
241+
}
242+
})
243+
}
244+
245+
errorTables.value = errors
246+
return errors
247+
}
248+
235249
const submitClipboard = () => {
236-
selected.value.tables = clipboardTables.value
250+
const errorTables = getErrorTables(clipboardTables.value)
251+
252+
if (Object.keys(errorTables).length) return
253+
254+
selected.value.tables = Array.from(
255+
new Set(selected.value.tables.concat(clipboardTables.value)),
256+
)
237257
isOpenClipMode.value = false
238258
emit('change', selected.value.tables)
239259
}
240260
241261
const autofix = () => {
242-
selected.value.tables = selected.value.tables.filter(
243-
(t) => !errorTables.value[t],
244-
)
245-
emit('change', selected.value.tables)
262+
if (isOpenClipMode.value) {
263+
clipboardValue.value = clipboardTables.value
264+
.filter((t) => !errorTables.value[t])
265+
.join(', ')
266+
errorTables.value = {}
267+
} else {
268+
selected.value.tables = selected.value.tables.filter(
269+
(t) => !errorTables.value[t],
270+
)
271+
emit('change', selected.value.tables)
272+
}
246273
}
247274
248275
const getTableInfo = (table: string) => {
@@ -252,7 +279,7 @@ const getTableInfo = (table: string) => {
252279
// Watch
253280
watch(
254281
() => props.value,
255-
(val) => {
282+
(val: string[]) => {
256283
selected.value.tables = val || []
257284
},
258285
{ immediate: true },
@@ -641,15 +668,14 @@ getTables()
641668
<span class="color-danger"
642669
>*{{ $t('packages_form_component_table_selector_error') }}</span
643670
>
644-
<ElLink class="ml-2" type="primary" @click="autofix">{{
671+
<el-button text class="ml-1" type="primary" @click="autofix">{{
645672
$t('packages_form_component_table_selector_autofix')
646-
}}</ElLink>
673+
}}</el-button>
647674
</div>
648675
<div v-if="isOpenClipMode" class="px-4 pb-4 text-end">
649-
<!-- <ElButton @click="changeSeletedMode()">{{ $t('public_button_cancel') }}</ElButton>-->
650-
<ElButton type="primary" @click="submitClipboard">{{
676+
<el-button type="primary" @click="submitClipboard">{{
651677
$t('public_button_confirm')
652-
}}</ElButton>
678+
}}</el-button>
653679
</div>
654680
</div>
655681
</div>

0 commit comments

Comments
 (0)