Skip to content

Commit 1efdb31

Browse files
committed
refactor(ui): Optimize the topology detail display logic and remove duplicate code
1 parent 6fb340d commit 1efdb31

2 files changed

Lines changed: 20 additions & 42 deletions

File tree

ui-vue3/src/views/resources/applications/tabs/topology.vue

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@
2929
bordered
3030
:labelStyle="{ fontWeight: 'bold', width: '160px' }"
3131
>
32-
<a-descriptions-item
33-
v-for="(v, k) in detailData"
34-
:key="k"
35-
v-show="v !== undefined && v !== null"
36-
>
37-
<template #label>{{ k }}</template>
38-
<a-typography-paragraph style="margin-bottom: 0">{{
39-
formatValueForDisplay(v)
40-
}}</a-typography-paragraph>
32+
<a-descriptions-item v-for="item in detailEntries" :key="item.key">
33+
<template #label>{{ item.key }}</template>
34+
{{ formatValueForDisplay(item.value) }}
4135
</a-descriptions-item>
4236
</a-descriptions>
4337
</a-spin>
@@ -150,7 +144,14 @@ const detailTitle = computed(() => {
150144
return currentDetailKey.value ? `应用详情:${currentDetailKey.value}` : '应用详情'
151145
})
152146
153-
const formatValueForDisplay = (v: unknown) => {
147+
const detailEntries = computed(() => {
148+
const data = detailData.value ?? {}
149+
return Object.entries(data)
150+
.filter(([, v]) => v !== undefined && v !== null && String(v) !== '')
151+
.map(([key, value]) => ({ key, value }))
152+
})
153+
154+
const formatValueForDisplay = (v: unknown): string => {
154155
if (v === null || v === undefined) return ''
155156
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') return String(v)
156157
if (Array.isArray(v))
@@ -211,7 +212,7 @@ const renderTopology = (graphData: any) => {
211212
node: {
212213
type: 'vue-node',
213214
style: {
214-
component: (data) => <StatefulNode data={Object.assign({}, data)} />
215+
component: (data: any) => <StatefulNode data={Object.assign({}, data)} />
215216
}
216217
},
217218
edge: {

ui-vue3/src/views/resources/services/tabs/topology.vue

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,7 @@
3131
>
3232
<a-descriptions-item v-for="item in detailEntries" :key="item.key">
3333
<template #label>{{ item.key }}</template>
34-
<template v-if="item.key === 'versionGroups' && Array.isArray(item.value)">
35-
<a-space direction="vertical" size="small">
36-
<a-space v-for="(vg, idx) in item.value" :key="idx" size="small">
37-
<a-tag>version: {{ vg?.version ?? '无' }}</a-tag>
38-
<a-tag>group: {{ vg?.group ?? '无' }}</a-tag>
39-
</a-space>
40-
</a-space>
41-
</template>
42-
<template v-else>
43-
<a-typography-paragraph style="margin-bottom: 0">{{
44-
formatValueForDisplay(item.value)
45-
}}</a-typography-paragraph>
46-
</template>
34+
{{ formatValueForDisplay(item.value) }}
4735
</a-descriptions-item>
4836
</a-descriptions>
4937
</a-spin>
@@ -169,26 +157,15 @@ const detailTitle = computed(() => {
169157
return currentDetailKey.value ? `${base}:${currentDetailKey.value}` : base
170158
})
171159
160+
const detailEntryBlacklist = new Set<string>(['versionGroups', 'appName'])
161+
172162
const detailEntries = computed(() => {
173163
const data = detailData.value ?? {}
174-
const preferredKeys = ['versionGroups', 'avgRT', 'avgQPS', 'requestTotal']
175-
const pairs = Object.entries(data).filter(
176-
([, v]) => v !== undefined && v !== null && String(v) !== ''
177-
)
178-
const ordered: Array<[string, unknown]> = []
179-
const used = new Set<string>()
180-
for (const k of preferredKeys) {
181-
const hit = pairs.find(([key]) => key === k)
182-
if (hit) {
183-
ordered.push(hit)
184-
used.add(k)
185-
}
186-
}
187-
const rest = pairs
188-
.filter(([k]) => !used.has(k))
189-
.sort((a, b) => (a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0))
190-
ordered.push(...rest)
191-
return ordered.map(([key, value]) => ({ key, value }))
164+
return Object.entries(data)
165+
.filter(
166+
([k, v]) => !detailEntryBlacklist.has(k) && v !== undefined && v !== null && String(v) !== ''
167+
)
168+
.map(([key, value]) => ({ key, value }))
192169
})
193170
194171
const formatValueForDisplay = (v: unknown) => {

0 commit comments

Comments
 (0)