Skip to content

Commit a9ea154

Browse files
feat(ui-vue3): improve func empty description
1 parent 4f38739 commit a9ea154

3 files changed

Lines changed: 45 additions & 71 deletions

File tree

pkg/console/service/service.go

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -349,37 +349,20 @@ func buildServiceMethodSummaries(metadataList []*meshresource.ServiceProviderMet
349349

350350
func buildServiceMethodCandidates(metadataList []*meshresource.ServiceProviderMetadataResource) []*serviceMethodCandidate {
351351
candidateByKey := make(map[string]*serviceMethodCandidate)
352-
structuredMethodNames := make(map[string]struct{})
353-
fallbackMethodNames := make(map[string]struct{})
354352

355353
for _, metadata := range metadataList {
354+
if metadata == nil || metadata.Spec == nil {
355+
continue
356+
}
356357
for _, method := range metadata.Spec.Methods {
357358
candidate, ok := newStructuredServiceMethodCandidate(method)
358359
if !ok {
359360
continue
360361
}
361362
candidateByKey[serviceMethodKey(candidate.detail.MethodName, candidate.signature)] = candidate
362-
structuredMethodNames[candidate.detail.MethodName] = struct{}{}
363-
}
364-
365-
if len(metadata.Spec.Methods) > 0 {
366-
continue
367-
}
368-
for _, methodName := range methodNamesFromMetadataParameters(metadata.Spec.Parameters) {
369-
fallbackMethodNames[methodName] = struct{}{}
370363
}
371364
}
372365

373-
// Legacy metadata may only expose flat method-name parameters without structured method definitions.
374-
// Keep those names as a fallback for method listing, but never let them shadow authoritative
375-
// structured metadata for the same method name.
376-
for methodName := range fallbackMethodNames {
377-
if _, ok := structuredMethodNames[methodName]; ok {
378-
continue
379-
}
380-
candidateByKey[serviceMethodKey(methodName, "")] = newFallbackServiceMethodCandidate(methodName)
381-
}
382-
383366
candidates := make([]*serviceMethodCandidate, 0, len(candidateByKey))
384367
for _, candidate := range candidateByKey {
385368
candidates = append(candidates, candidate)
@@ -429,12 +412,6 @@ func resolveStructuredServiceMethodCandidate(candidates []*serviceMethodCandidat
429412
)
430413
}
431414
if candidate == nil {
432-
if hasFallbackOnlyMethodCandidate(candidates, req.MethodName) {
433-
return nil, bizerror.New(
434-
bizerror.InvalidArgument,
435-
fmt.Sprintf("structured metadata not found for method %s of service %s", req.MethodName, req.ServiceName),
436-
)
437-
}
438415
return nil, bizerror.New(
439416
bizerror.NotFoundError,
440417
fmt.Sprintf("method %s not found for service %s", req.MethodName, req.ServiceName),
@@ -449,15 +426,6 @@ func resolveStructuredServiceMethodCandidate(candidates []*serviceMethodCandidat
449426
return candidate, nil
450427
}
451428

452-
func hasFallbackOnlyMethodCandidate(candidates []*serviceMethodCandidate, methodName string) bool {
453-
for _, candidate := range candidates {
454-
if candidate.detail.MethodName == methodName && candidate.method == nil {
455-
return true
456-
}
457-
}
458-
return false
459-
}
460-
461429
func newStructuredServiceMethodCandidate(method *meshproto.Method) (*serviceMethodCandidate, bool) {
462430
if method == nil {
463431
return nil, false
@@ -473,38 +441,6 @@ func newStructuredServiceMethodCandidate(method *meshproto.Method) (*serviceMeth
473441
}, true
474442
}
475443

476-
func newFallbackServiceMethodCandidate(methodName string) *serviceMethodCandidate {
477-
return &serviceMethodCandidate{
478-
detail: &model.ServiceMethodDetailResp{
479-
MethodName: methodName,
480-
Signature: "",
481-
ParameterTypes: []string{},
482-
Parameters: []model.ServiceMethodParameter{},
483-
Types: []model.ServiceMethodTypeResp{},
484-
},
485-
signature: "",
486-
}
487-
}
488-
489-
func methodNamesFromMetadataParameters(parameters map[string]string) []string {
490-
if parameters == nil {
491-
return nil
492-
}
493-
methodsRaw := strings.TrimSpace(parameters["methods"])
494-
if strutil.IsBlank(methodsRaw) {
495-
return nil
496-
}
497-
methodNames := make([]string, 0)
498-
for _, methodName := range strings.Split(methodsRaw, ",") {
499-
methodName = strings.TrimSpace(methodName)
500-
if strutil.IsBlank(methodName) {
501-
continue
502-
}
503-
methodNames = append(methodNames, methodName)
504-
}
505-
return methodNames
506-
}
507-
508444
func serviceMethodKey(methodName, signature string) string {
509445
return methodName + "\x00" + signature
510446
}

ui-vue3/.env.mock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
116
VITE_MOCK_ENABLED=true

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<a-card :bordered="false" :body-style="{ padding: '24px' }">
2020
<div class="tabs-title">方法列表</div>
2121
<a-spin :spinning="loadingMethods">
22-
<a-empty v-if="!loadingMethods && methodList.length === 0" description="暂无方法" />
22+
<a-empty v-if="!loadingMethods && methodList.length === 0" :description="emptyDescription" />
2323
<a-tabs
2424
v-else
2525
v-model:activeKey="activeKey"
@@ -175,6 +175,10 @@ import {
175175
} from '@/api/service/service'
176176
import { useMeshStore } from '@/stores/mesh'
177177
178+
defineOptions({
179+
name: 'ServiceDebugTab'
180+
})
181+
178182
interface MethodSummary {
179183
methodName: string
180184
parameterTypes: string[]
@@ -233,6 +237,16 @@ const timeout = ref(3000)
233237
const attachmentsModalOpen = ref(false)
234238
const attachmentsList = ref<{ key: string; value: string }[]>([])
235239
240+
const isMeshSelected = computed(() => Boolean(meshStore.mesh))
241+
const emptyDescription = computed(() => {
242+
if (!serviceName.value) {
243+
return '暂无方法'
244+
}
245+
if (!isMeshSelected.value) {
246+
return '请先选择 mesh'
247+
}
248+
return '暂无可调试方法'
249+
})
236250
const attachmentCount = computed(() => attachmentsList.value.filter((a) => a.key).length)
237251
const providerInstanceOptions = computed(() =>
238252
providerInstances.value.map((instance) => ({
@@ -392,7 +406,7 @@ function syncSelectedInstance() {
392406
}
393407
394408
async function loadProviderInstances() {
395-
if (!serviceName.value) {
409+
if (!serviceName.value || !isMeshSelected.value) {
396410
providerInstances.value = []
397411
instanceName.value = ''
398412
return
@@ -412,7 +426,7 @@ async function loadProviderInstances() {
412426
}
413427
414428
async function loadMethods() {
415-
if (!serviceName.value) {
429+
if (!serviceName.value || !isMeshSelected.value) {
416430
methodList.value = []
417431
currentMethodDetail.value = null
418432
requestValue.value = '[]'
@@ -547,7 +561,14 @@ function removeAttachment(idx: number) {
547561
548562
async function loadPageData() {
549563
responseValue.value = ''
550-
await Promise.all([loadProviderInstances(), loadMethods()])
564+
if (!isMeshSelected.value) {
565+
return
566+
}
567+
try {
568+
await Promise.all([loadProviderInstances(), loadMethods()])
569+
} catch (error) {
570+
console.error('load debug page data failed', error)
571+
}
551572
}
552573
553574
watch(
@@ -557,6 +578,8 @@ watch(
557578
providerInstances.value = []
558579
currentMethodDetail.value = null
559580
instanceName.value = ''
581+
requestValue.value = '[]'
582+
responseValue.value = ''
560583
void loadPageData()
561584
},
562585
{ immediate: true }

0 commit comments

Comments
 (0)