Skip to content

Commit f8547ca

Browse files
committed
chore: avoid menu duplicated
1 parent 4ac2eaa commit f8547ca

File tree

7 files changed

+800
-771
lines changed

7 files changed

+800
-771
lines changed

console/atest-ui/src/App.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Guide,
99
DataAnalysis, Help, Setting
1010
} from '@element-plus/icons-vue'
11+
import * as ElementPlusIcons from '@element-plus/icons-vue'
1112
import { ref, watch, getCurrentInstance} from 'vue'
1213
import { API } from './views/net'
1314
import { Cache } from './views/cache'
@@ -152,17 +153,13 @@ API.GetMenus((menus) => {
152153
<el-icon><Guide /></el-icon>
153154
<template #title>{{ t('title.mock' )}}</template>
154155
</el-menu-item>
155-
<el-menu-item index="data" test-id="data-menu">
156-
<el-icon><DataAnalysis /></el-icon>
157-
<template #title>{{ t('title.data' )}}</template>
158-
</el-menu-item>
159156
<el-menu-item index="store">
160157
<el-icon><location /></el-icon>
161158
<template #title>{{ t('title.stores') }}</template>
162159
</el-menu-item>
163160
<span v-for="menu in extensionMenus" :key="menu.index" :index="menu.index">
164161
<el-menu-item :index="menu.index">
165-
<el-icon><IconMenu /></el-icon>
162+
<el-icon><component :is="ElementPlusIcons[menu.icon]" /></el-icon>
166163
<template #title>{{ menu.name }}</template>
167164
</el-menu-item>
168165
</span>

console/atest-ui/src/views/Extension.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const loadPlugin = async (): Promise<void> => {
1010
try {
1111
API.GetPageOfCSS(props.name, (d) => {
1212
const style = document.createElement('style');
13-
style.type = 'text/css';
1413
style.textContent = d.message;
1514
document.head.appendChild(style);
1615
});
@@ -26,7 +25,10 @@ const loadPlugin = async (): Promise<void> => {
2625
if (plugin && plugin.mount) {
2726
console.log('extension load success');
2827
const container = document.getElementById("plugin-container");
29-
plugin.mount(container);
28+
if (container) {
29+
container.innerHTML = ''; // Clear previous content
30+
plugin.mount(container);
31+
}
3032
}
3133
});
3234
} catch (error) {

pkg/server/remote_server.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,13 +1395,28 @@ func (s *server) GetMenus(ctx context.Context, _ *Empty) (result *MenuList, err
13951395
return
13961396
}
13971397

1398+
duplicatedMenus := make(map[string]int) // index is key, value is the slice index
13981399
for _, loader := range loaders {
13991400
if menus, mErr := loader.GetMenus(); mErr == nil {
14001401
for _, menu := range menus {
14011402
if isSystemMenu(menu.Index) {
14021403
serverLogger.Info("skip due to conflict with system name", "menu", menu)
14031404
continue
14041405
}
1406+
1407+
// take the bigger version if the menu index is duplicated
1408+
if existingIndex, exists := duplicatedMenus[menu.Index]; exists {
1409+
if menu.Version > result.Data[existingIndex].Version {
1410+
result.Data[existingIndex] = &Menu{
1411+
Name: menu.Name,
1412+
Icon: menu.Icon,
1413+
Index: menu.Index,
1414+
}
1415+
}
1416+
continue
1417+
}
1418+
1419+
duplicatedMenus[menu.Index] = len(result.Data)
14051420
result.Data = append(result.Data, &Menu{
14061421
Name: menu.Name,
14071422
Icon: menu.Icon,
@@ -1410,12 +1425,16 @@ func (s *server) GetMenus(ctx context.Context, _ *Empty) (result *MenuList, err
14101425
}
14111426
}
14121427
}
1428+
1429+
slices.SortFunc(result.Data, func(a, b *Menu) int {
1430+
return strings.Compare(a.Index, b.Index)
1431+
})
14131432
return
14141433
}
14151434

14161435
func isSystemMenu(index string) bool {
14171436
switch index {
1418-
case "testing", "history", "data", "mock", "store", "welcome", "":
1437+
case "testing", "history", "mock", "store", "welcome", "":
14191438
return true
14201439
}
14211440
return false

0 commit comments

Comments
 (0)