From 71eeeeb80ecad7d87e4d4d0c13692e501b3d1723 Mon Sep 17 00:00:00 2001 From: mizy <1060950782@163.com> Date: Fri, 19 May 2023 15:11:19 +0800 Subject: [PATCH 1/2] fix: add some utils --- src/components/Charts/RingProgressChart.tsx | 12 +++++++----- src/utils/dashboard.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/Charts/RingProgressChart.tsx b/src/components/Charts/RingProgressChart.tsx index d78bfaaf..0e30a003 100644 --- a/src/components/Charts/RingProgressChart.tsx +++ b/src/components/Charts/RingProgressChart.tsx @@ -8,6 +8,7 @@ interface IProps { percent: number; type: string; config?: any; + contentFormatter?:(p:number)=>string; } const ColorMap = { @@ -17,7 +18,7 @@ const ColorMap = { } function RingProgressChart(props: IProps) { - const { percent, type, config } = props; + const { percent, type, config,contentFormatter } = props; const calcColor = () => { const level = calcNodeHealty(percent); @@ -37,8 +38,8 @@ function RingProgressChart(props: IProps) { title: { style: { color: '#000', - fontSize: '12px', - lineHeight: '14px', + fontSize: '16px', + lineHeight: '16px', }, formatter: () => type, }, @@ -46,10 +47,11 @@ function RingProgressChart(props: IProps) { style: { color: '#000', fontWeight: 'bold', - marginTop: '15px', - fontSize: '14px', + marginTop: '10px', + fontSize: '12px', lineHeight: '14px', }, + formatter:contentFormatter } } } diff --git a/src/utils/dashboard.ts b/src/utils/dashboard.ts index 3ba70a31..57f5b966 100644 --- a/src/utils/dashboard.ts +++ b/src/utils/dashboard.ts @@ -144,6 +144,18 @@ export const getProperByteDesc = (bytes: number) => { desc: value + unit, } } + +export const getProperByUnit = (bytes: number, unit: string) => { + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] as const; + const i = sizes.findIndex(s => s === unit); + const value = (bytes / Math.pow(1024, i)).toFixed(2) + return { + value:parseFloat(value), + unit, + desc: value + unit, + } +} + export const getAutoLatency = (latency: number) => { if (latency > 60 * 1000 * 1000) { // min From 13f4bf1f661da7477db5cacd70b4e658eb691500 Mon Sep 17 00:00:00 2001 From: mizy <1060950782@163.com> Date: Fri, 19 May 2023 15:48:15 +0800 Subject: [PATCH 2/2] fix: overflow scroll bar --- src/components/Charts/SpaceChart.less | 1 - src/pages/MachineDashboard/Cards/DiskCard.tsx | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/Charts/SpaceChart.less b/src/components/Charts/SpaceChart.less index bae08aa4..a345ad4d 100644 --- a/src/components/Charts/SpaceChart.less +++ b/src/components/Charts/SpaceChart.less @@ -2,7 +2,6 @@ padding: 12px 0; overflow: auto; height: 100%; - max-height: 240px; overflow-y: auto; >.tip { diff --git a/src/pages/MachineDashboard/Cards/DiskCard.tsx b/src/pages/MachineDashboard/Cards/DiskCard.tsx index a49b58b5..b5c9e0f8 100644 --- a/src/pages/MachineDashboard/Cards/DiskCard.tsx +++ b/src/pages/MachineDashboard/Cards/DiskCard.tsx @@ -30,7 +30,7 @@ const DiskCard = forwardRef((props: IProps, ref) => { const asyncGetDiskUsageDetails = async () => { const clusterSuffix1 = cluster ? `,${getClusterPrefix()}="${cluster.id}"` : ''; - const instanceSuffix = `, instance=~"^${instance.replaceAll(".", "\.")}.*"`; + const instanceSuffix = instance!=='all'?`, instance=~"^${instance.replaceAll(".", "\.")}.*"`:''; const queries: any = [ { refId: 'diskSize', @@ -42,7 +42,7 @@ const DiskCard = forwardRef((props: IProps, ref) => { } ]; const data = await asyncBatchQueries(queries); - const { results } = data; + const { results } = data as any; const details = results.diskSize.result.map(item => { const metricItem = results.diskUsed.result.find(usedItem => usedItem.metric.device === item.metric.device); let used = 0; @@ -54,7 +54,7 @@ const DiskCard = forwardRef((props: IProps, ref) => { device: item.metric.device, mountpoint: item.metric.mountpoint, used, - name: instance, + name: item.metric.instance.split(':')[0], } }); setDiskUsageDetails(details);