diff --git a/apps/desktop/src/components/nacos/NacosAdminConsole.vue b/apps/desktop/src/components/nacos/NacosAdminConsole.vue index c0991b4164..f412bdfcaf 100644 --- a/apps/desktop/src/components/nacos/NacosAdminConsole.vue +++ b/apps/desktop/src/components/nacos/NacosAdminConsole.vue @@ -48,7 +48,7 @@ import { type NacosConfigDeleteSnapshot, } from "@/lib/nacos/nacosAdmin"; import { createNacosNamespaceRequestGuard, subscribeNacosNamespacesChanged, type NacosNamespacesChangedDetail } from "@/lib/nacos/nacosNamespaceCache"; -import { nacosInstanceMatchesPatch, nacosInstanceRefIdentity, nacosIpAddressIsValid, nacosServiceDetailMatches } from "@/lib/nacos/nacosServiceManagement"; +import { nacosInstanceMatchesPatch, nacosInstanceRefIdentity, nacosIpAddressIsValid, nacosServiceDetailMatches, nacosServiceInstanceHealthSummary } from "@/lib/nacos/nacosServiceManagement"; import { loadReadableNacosNamespaces, nacosNamespaceIdentity } from "@/lib/nacos/nacosNamespaceVisibility"; import { clipboardLineEndings, copyToClipboard, readTextFromClipboard } from "@/lib/common/clipboard"; import { trimmedSelectionLayer } from "@/lib/editor/codemirrorTrimmedSelectionLayer"; @@ -473,6 +473,12 @@ const canRequestBatchDeleteConfigs = computed(() => !props.readOnly && !savingCo const pendingBatchDeleteDetails = computed(() => pendingBatchDelete.value?.keys.map((key) => `namespace=${key.namespace || "public"}\ndataId=${key.dataId}\ngroup=${key.group || "DEFAULT_GROUP"}`).join("\n\n") || ""); const pendingHistoryRollbackDetails = computed(() => (pendingHistoryRollback.value ? buildNacosConfigHistoryRollbackConfirm(pendingHistoryRollback.value, namespace.value) : "")); const pendingInstanceDetails = computed(() => (pendingInstanceUpdate.value && selectedService.value ? buildNacosInstanceConfirm(selectedService.value, pendingInstanceUpdate.value.instance, pendingInstanceUpdate.value.patch, serviceGroup.value, namespace.value) : "")); +const pendingInstanceAvailabilityAction = computed(() => { + const enabled = pendingInstanceUpdate.value?.patch.enabled; + return enabled == null ? "" : t(enabled ? "nacos.online" : "nacos.offline"); +}); +const pendingInstanceTitle = computed(() => (pendingInstanceAvailabilityAction.value ? `${t("nacos.confirmInstanceTitle")}: ${pendingInstanceAvailabilityAction.value}` : t("nacos.confirmInstanceTitle"))); +const pendingInstanceConfirmLabel = computed(() => pendingInstanceAvailabilityAction.value || t("dangerDialog.confirm")); const pendingInstanceDeregisterDetails = computed(() => { if (!pendingInstanceDeregister.value || !selectedService.value) return ""; const ref = instanceRef(pendingInstanceDeregister.value); @@ -2111,6 +2117,35 @@ function serviceIdentity(service: NacosServiceInfo | null) { return service ? `${service.groupName || "DEFAULT_GROUP"}\u0000${service.serviceName}` : ""; } +function serviceInstanceHealthLabel(service: NacosServiceInfo) { + const summary = nacosServiceInstanceHealthSummary(service); + if (!summary) return ""; + const counts = { healthy: summary.healthy, total: summary.total }; + switch (summary.status) { + case "allHealthy": + return t("nacos.serviceInstancesAllHealthy", counts); + case "partiallyHealthy": + return t("nacos.serviceInstancesPartiallyHealthy", counts); + case "noHealthyInstances": + return t("nacos.serviceInstancesNoHealthyInstances", counts); + case "noInstances": + return t("nacos.serviceInstancesNoInstances"); + } +} + +function serviceInstanceHealthClass(service: NacosServiceInfo) { + switch (nacosServiceInstanceHealthSummary(service)?.status) { + case "allHealthy": + return "border-emerald-500/50 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"; + case "partiallyHealthy": + return "border-amber-500/50 bg-amber-500/10 text-amber-700 dark:text-amber-300"; + case "noHealthyInstances": + return "border-destructive/50 bg-destructive/10 text-destructive"; + default: + return "border-muted-foreground/40 text-muted-foreground"; + } +} + async function loadServiceDetail() { const service = selectedService.value ? { ...selectedService.value } : null; if (!service || !getServiceCapability.value.supported) return; @@ -2367,7 +2402,9 @@ async function reconcileInstancePresence(ref: NacosInstanceRef, shouldExist: boo async function updateInstance(instance: NacosInstanceInfo, patch: NacosInstancePatch) { if (!selectedService.value || props.readOnly || !supportsInstanceUpdate.value) return; const ref = instanceRef(instance); - if (!(await confirmNacosMutation(t("nacos.confirmInstanceTitle"), props.connectionId, ref.namespace || namespace.value))) return; + const availabilityAction = patch.enabled == null ? "" : t(patch.enabled ? "nacos.online" : "nacos.offline"); + const reviewText = availabilityAction ? `${t("nacos.confirmInstanceTitle")}: ${availabilityAction}` : t("nacos.confirmInstanceTitle"); + if (!(await confirmNacosMutation(reviewText, props.connectionId, ref.namespace || namespace.value))) return; const key = instanceIdentity(instance); const updateId = ++instanceUpdateSequence; const operationToken = beginInstanceOperation(key); @@ -3193,8 +3230,11 @@ useUpdateBlocker(() => {{ service.groupName || serviceGroup }} - · {{ t("nacos.instanceCount", { count: service.ipCount }) }} - · {{ t("nacos.healthy") }} {{ service.healthyInstanceCount }} + {{ serviceInstanceHealthLabel(service) }} + · {{ t("nacos.cluster") }} {{ service.clusterCount }} {{ t("nacos.protectionTriggered") }} @@ -3337,7 +3377,9 @@ useUpdateBlocker(() => {{ instance.ip }}:{{ instance.port }} {{ instance.clusterName || "DEFAULT" }} {{ instance.healthy === false ? t("nacos.unhealthy") : t("nacos.healthy") }} - {{ instance.enabled === false ? t("nacos.offline") : t("nacos.enabled") }} + {{ + instance.enabled === false ? t("nacos.offline") : t("nacos.online") + }} {{ instance.ephemeral ? t("nacos.ephemeral") : t("nacos.persistent") }}
@@ -3380,12 +3422,13 @@ useUpdateBlocker(() => size="sm" variant="outline" class="h-7 gap-1" + data-testid="nacos-instance-availability-action" :class="instance.enabled === false ? 'border-emerald-500/50 text-emerald-700 hover:bg-emerald-500/10 hover:text-emerald-800 dark:text-emerald-300 dark:hover:text-emerald-200' : 'border-destructive/50 text-destructive hover:bg-destructive/10'" :disabled="readOnly || !supportsInstanceUpdate || isInstanceUpdating(instance)" @click="requestUpdateInstance(instance, { enabled: !instance.enabled })" > - {{ instance.enabled === false ? t("nacos.enable") : t("nacos.disable") }} + {{ instance.enabled === false ? t("nacos.online") : t("nacos.offline") }}