Skip to content

Commit e97a56b

Browse files
committed
fix(TableRename): update filtering logic and improve List component structure for better performance and readability
1 parent 147103c commit e97a56b

2 files changed

Lines changed: 34 additions & 40 deletions

File tree

packages/dag/src/components/form/table-rename/List.vue

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
1-
<script lang="jsx">
1+
<script lang="tsx">
2+
import { defineComponent, ref, watch } from 'vue'
23
import { RecycleScroller } from 'vue-virtual-scroller'
34
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
45
5-
const InnerInput = {
6+
const InnerInput = defineComponent({
67
name: 'InnerInput',
78
props: ['value', 'readOnly'],
8-
data() {
9-
return {
10-
val: null,
11-
}
12-
},
13-
watch: {
14-
value(val) {
15-
this.val = val
16-
},
17-
},
18-
created() {
19-
this.val = this.value
20-
},
219
emits: ['change'],
22-
render() {
23-
return (
10+
setup(props, { emit }) {
11+
const val = ref(props.value)
12+
watch(
13+
() => props.value,
14+
(newVal) => {
15+
val.value = newVal
16+
},
17+
)
18+
return () => (
2419
<input
25-
class="name-list-item-input px-2 rounded-4"
26-
readOnly={this.readOnly}
27-
value={this.val}
28-
onChange={(ev) => this.$emit('change', ev)}
20+
class="name-list-item-input px-2 rounded-lg"
21+
readonly={props.readOnly}
22+
value={val.value}
23+
onChange={(ev) => emit('change', ev)}
2924
/>
3025
)
3126
},
32-
}
27+
})
3328
3429
export default {
3530
name: 'List',
3631
components: { RecycleScroller, InnerInput },
3732
props: [
33+
'items',
3834
'nameMap',
3935
'tableData',
4036
'updateName',
@@ -71,8 +67,14 @@ export default {
7167
</script>
7268

7369
<template>
74-
<RecycleScroller v-bind="$attrs">
75-
<template #default="{ item: name }">
70+
<RecycleScroller
71+
v-bind="$attrs"
72+
:items="items"
73+
key-field="name"
74+
:item-size="38"
75+
:buffer="50"
76+
>
77+
<template #default="{ item: { name } }">
7678
<div class="name-list-item flex align-center position-relative">
7779
<div class="flex-1 px-4 text-truncate">
7880
<span :title="name">{{ name }}</span>
@@ -92,12 +94,6 @@ export default {
9294
}"
9395
@change="handleChange(name, $event)"
9496
/>
95-
<!--<input
96-
class="name-list-item-input px-2"
97-
:readOnly="disabled"
98-
:value="nameMap[name] || name"
99-
@change="handleChange"
100-
/>-->
10197
</div>
10298
<VIcon size="12" class="name-list-item-center font-color-light">
10399
left

packages/dag/src/components/form/table-rename/index.jsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,11 @@ export const TableRenamePreview = defineComponent({
154154
const filterNames = computed(() => {
155155
const txt = config.search.trim().toLowerCase()
156156
if (txt) {
157-
return tableDataRef.value.filter((n) => n.toLowerCase().includes(txt))
157+
return tableDataRef.value
158+
.filter((n) => n.toLowerCase().includes(txt))
159+
.map((name) => ({ name }))
158160
}
159-
return tableDataRef.value
161+
return tableDataRef.value.map((name) => ({ name }))
160162
})
161163

162164
const doModify = () => {
@@ -339,8 +341,6 @@ export const TableRenamePreview = defineComponent({
339341
<List
340342
disabled={this.disabled}
341343
items={this.filterNames}
342-
itemSize={this.itemSize}
343-
buffer={50}
344344
countByName={this.countByName}
345345
nameMap={this.nameMap}
346346
globalNameMap={this.globalNameMap}
@@ -487,11 +487,11 @@ export const TableRename = connect(
487487
const filterNames = computed(() => {
488488
const txt = config.search.trim().toLowerCase()
489489
if (txt) {
490-
return tableDataRef.value.filter((n) =>
491-
n.toLowerCase().includes(txt),
492-
)
490+
return tableDataRef.value
491+
.filter((n: string) => n.toLowerCase().includes(txt))
492+
.map((name: string) => ({ name }))
493493
}
494-
return tableDataRef.value
494+
return tableDataRef.value.map((name: string) => ({ name }))
495495
})
496496

497497
const doModify = () => {
@@ -784,8 +784,6 @@ export const TableRename = connect(
784784
<List
785785
disabled={this.disabled}
786786
items={this.filterNames}
787-
itemSize={this.itemSize}
788-
buffer={50}
789787
countByName={this.countByName}
790788
nameMap={this.nameMap}
791789
globalNameMap={this.globalNameMap}

0 commit comments

Comments
 (0)