From 8ba52cd0ea7c0ed0f92a09cccd6c1756dcebccab Mon Sep 17 00:00:00 2001 From: jo-hnny Date: Fri, 23 Apr 2021 18:18:28 +0800 Subject: [PATCH] fix(console): fix some attribute not have , let ui error (#1222) --- web/console/helpers/format.ts | 2 +- .../nodeManage/ComputerActionPanel.tsx | 8 ++++---- .../resource/nodeManage/ComputerTablePanel.tsx | 18 +++++++++--------- .../resourceDetail/ResourceNodeDetailPanel.tsx | 15 ++++++--------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/web/console/helpers/format.ts b/web/console/helpers/format.ts index d5ea16a80..547ebe74f 100644 --- a/web/console/helpers/format.ts +++ b/web/console/helpers/format.ts @@ -15,7 +15,7 @@ export const formatMemory = ( memory: string, finalUnit: 'K' | 'M' | 'G' | 'T' | 'P' | 'E' | 'Ki' | 'Mi' | 'Gi' | 'Ti' | 'Pi' | 'Ei' ) => { - const unit = memory.toUpperCase().match(/[KMGTPEI]+/)[0] ?? 'MI'; + const unit = memory.toUpperCase().match(/[KMGTPEI]+/)?.[0] ?? 'MI'; const memoryNum = parseInt(memory); diff --git a/web/console/src/modules/cluster/components/resource/nodeManage/ComputerActionPanel.tsx b/web/console/src/modules/cluster/components/resource/nodeManage/ComputerActionPanel.tsx index 65fac4878..1a58ae735 100644 --- a/web/console/src/modules/cluster/components/resource/nodeManage/ComputerActionPanel.tsx +++ b/web/console/src/modules/cluster/components/resource/nodeManage/ComputerActionPanel.tsx @@ -56,7 +56,7 @@ export class ComputerActionPanel extends React.Component { item.metadata.name, item.status.phase, item.metadata.role, - `cpu: ${item.status.capacity.cpu ?? '-'} 核; 内存: ${item.status.capacity.memory ?? '-'}`, + `cpu: ${item?.status?.capacity?.cpu ?? '-'} 核; 内存: ${item?.status?.capacity?.memory ?? '-'}`, this._reduceIp(item), item.spec.podCIDR, dateFormatter(new Date(item.metadata.creationTimestamp), 'YYYY-MM-DD HH:mm:ss') @@ -68,10 +68,10 @@ export class ComputerActionPanel extends React.Component { } _reduceCapacity(node: Computer) { - const capacity = node.status.capacity; + const capacity = node?.status?.capacity; const capacityInfo = { - cpu: capacity.cpu, - memory: capacity.memory + cpu: capacity?.cpu, + memory: capacity?.memory }; const finalCpu = ReduceRequest('cpu', capacityInfo), finalmem = (ReduceRequest('memory', capacity) / 1024).toFixed(2); diff --git a/web/console/src/modules/cluster/components/resource/nodeManage/ComputerTablePanel.tsx b/web/console/src/modules/cluster/components/resource/nodeManage/ComputerTablePanel.tsx index a2f43f917..de1b2933b 100644 --- a/web/console/src/modules/cluster/components/resource/nodeManage/ComputerTablePanel.tsx +++ b/web/console/src/modules/cluster/components/resource/nodeManage/ComputerTablePanel.tsx @@ -128,10 +128,10 @@ export class ComputerTablePanel extends React.Component { width: '8%', render: x => ( - - {x.status.phase || '-'} + + {x?.status?.phase || '-'} - {x.status.phase === 'Initializing' && ( + {x?.status?.phase === 'Initializing' && (