From 1389cd0d03daf0846854070d0e50ba56a15536fa Mon Sep 17 00:00:00 2001 From: xudaotutou <13435638964@163.com> Date: Fri, 10 Jan 2025 15:21:56 +0800 Subject: [PATCH] fix(devbox): fix invaild devbox cr (#5339) --- .../detail/[name]/components/Version.tsx | 4 +- .../app/api/v1/getDevboxDetail/route.ts | 2 +- frontend/providers/devbox/types/k8s.d.ts | 2 +- frontend/providers/devbox/utils/adapt.ts | 82 ++++++------------- 4 files changed, 28 insertions(+), 62 deletions(-) diff --git a/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx b/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx index 2950d9c3b7c..439a1c88530 100644 --- a/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx +++ b/frontend/providers/devbox/app/[lang]/(platform)/devbox/detail/[name]/components/Version.tsx @@ -25,11 +25,11 @@ import CreateTemplateModal from '@/app/[lang]/(platform)/template/updateTemplate import SelectTemplateModal from '@/app/[lang]/(platform)/template/updateTemplate/SelectActionModal' import UpdateTemplateRepositoryModal from '@/app/[lang]/(platform)/template/updateTemplate/UpdateTemplateRepositoryModal' import AppSelectModal from '@/components/modals/AppSelectModal' +import useReleaseDriver from '@/hooks/useReleaseDriver' import { useDevboxStore } from '@/stores/devbox' import { useEnvStore } from '@/stores/env' import { AppListItemType } from '@/types/app' import { parseTemplateConfig } from '@/utils/tools' -import useReleaseDriver from '@/hooks/useReleaseDriver' const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 6) @@ -260,7 +260,7 @@ const Version = () => { + { - return { - id: devbox.metadata?.uid || ``, - name: devbox.metadata.name || 'devbox', - runtimeType: devbox.spec.runtimeType || '', - runtimeVersion: devbox.spec.runtimeRef.name || '', - status: - devbox.status.phase && devboxStatusMap[devbox.status.phase] - ? devboxStatusMap[devbox.status.phase] - : devboxStatusMap.Error, - sshPort: devbox.status.network.nodePort, - isPause: devbox.status.phase === 'Stopped', - createTime: dayjs(devbox.metadata.creationTimestamp).format('YYYY-MM-DD HH:mm'), - cpu: cpuFormatToM(devbox.spec.resource.cpu), - memory: memoryFormatToMi(devbox.spec.resource.memory), - usedCpu: { - name: '', - xData: new Array(30).fill(0), - yData: new Array(30).fill('0') - }, - usedMemory: { - name: '', - xData: new Array(30).fill(0), - yData: new Array(30).fill('0') - }, - networks: devbox.portInfos, - lastTerminatedReason: - devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error' - ? devbox.status.state.waiting - ? devbox.status.state.waiting.reason - : devbox.status.state.terminated - ? devbox.status.state.terminated.reason - : '' + devbox.status ? + devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error' + ? devbox.status.state.waiting + ? devbox.status.state.waiting.reason + : devbox.status.state.terminated + ? devbox.status.state.terminated.reason + : '' + : '' : '' } } + export const adaptDevboxDetailV2 = ( [devbox, portInfos, template]: GetDevboxByNameReturn ): DevboxDetailTypeV2 => { console.log('adaptDevboxDetailV2') - const status = devbox.status.phase && devboxStatusMap[devbox.status.phase] - ? devboxStatusMap[devbox.status.phase] - : devboxStatusMap.Error + const status = devbox.status?.phase && devboxStatusMap[devbox.status.phase] + ? devboxStatusMap[devbox.status.phase] + : devboxStatusMap.Error return { id: devbox.metadata?.uid || ``, name: devbox.metadata.name || 'devbox', @@ -153,8 +117,8 @@ export const adaptDevboxDetailV2 = ( image: template.image, iconId: template.templateRepository.iconId || '', status, - sshPort: devbox.status.network.nodePort, - isPause: devbox.status.phase === 'Stopped', + sshPort: devbox.status?.network.nodePort || 65535, + isPause: devbox.status?.phase === 'Stopped', createTime: dayjs(devbox.metadata.creationTimestamp).format('YYYY-MM-DD HH:mm'), cpu: cpuFormatToM(devbox.spec.resource.cpu), memory: memoryFormatToMi(devbox.spec.resource.memory), @@ -170,12 +134,14 @@ export const adaptDevboxDetailV2 = ( }, networks: portInfos || [], lastTerminatedReason: - devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error' - ? devbox.status.state.waiting - ? devbox.status.state.waiting.reason - : devbox.status.state.terminated - ? devbox.status.state.terminated.reason - : '' + devbox.status ? + devbox.status.lastState?.terminated && devbox.status.lastState.terminated.reason === 'Error' + ? devbox.status.state.waiting + ? devbox.status.state.waiting.reason + : devbox.status.state.terminated + ? devbox.status.state.terminated.reason + : '' + : '' : '' } }