diff --git a/packages/backend.ai-ui/src/components/BAIStatistic.tsx b/packages/backend.ai-ui/src/components/BAIStatistic.tsx index 2d4d5b3fe4..34520759f8 100644 --- a/packages/backend.ai-ui/src/components/BAIStatistic.tsx +++ b/packages/backend.ai-ui/src/components/BAIStatistic.tsx @@ -1,5 +1,5 @@ import BAIFlex from './BAIFlex'; -import { theme, Typography, Tooltip } from 'antd'; +import { theme, Typography, Tooltip, Progress } from 'antd'; import _ from 'lodash'; import React from 'react'; import { useTranslation } from 'react-i18next'; @@ -11,8 +11,9 @@ export interface BAIStatisticProps { unit?: string; precision?: number; infinityDisplay?: string; - showProgress?: boolean; + progressMode?: 'ghost' | 'hidden' | 'normal'; progressSteps?: number; + style?: React.CSSProperties; } const BAIStatistic: React.FC = ({ @@ -22,11 +23,13 @@ const BAIStatistic: React.FC = ({ unit = '', precision = 2, infinityDisplay = '∞', - showProgress = false, - progressSteps = 12, + progressMode = 'hidden', + progressSteps = 20, + style, }) => { const { token } = theme.useToken(); const { t } = useTranslation(); + const showProgress = progressMode !== 'hidden'; // Format number with precision const formatNumber = (value: number): string => { @@ -41,26 +44,22 @@ const BAIStatistic: React.FC = ({ : formatNumber(current); const displayTotal = total !== undefined ? formatNumber(total) : undefined; - // Calculate progress position - const calculateProgress = (): number => { + const calculatePercent = (): number => { if (!showProgress || total === undefined || total === Infinity) return 0; - if (!_.isFinite(current) || !isFinite(total) || total === 0) - return progressSteps; - return _.isUndefined(current) - ? 0 - : Math.round((current / total) * progressSteps); + if (!_.isFinite(current) || !isFinite(total) || total === 0) return 100; + return _.isUndefined(current) ? 0 : Math.round((current / total) * 100); }; - const currentPosition = calculateProgress(); + const percent = calculatePercent(); return ( - + {title} @@ -95,37 +94,42 @@ const BAIStatistic: React.FC = ({ style={{ fontSize: 32, lineHeight: '1em', - fontWeight: 700, - color: token.colorSuccess, }} > {displayCurrent} - {unit && {unit}} + {unit && ( + + {unit} + + )} )} - {showProgress && total !== undefined && ( + {progressMode === 'normal' && total !== undefined ? ( - - {_.map(_.range(progressSteps), (i) => ( - - ))} - + - )} + ) : progressMode === 'ghost' ? ( + + ) : null} ); }; diff --git a/packages/backend.ai-ui/src/components/ResourceStatistics.tsx b/packages/backend.ai-ui/src/components/ResourceStatistics.tsx index b1a801d534..70fa225cb2 100644 --- a/packages/backend.ai-ui/src/components/ResourceStatistics.tsx +++ b/packages/backend.ai-ui/src/components/ResourceStatistics.tsx @@ -1,7 +1,7 @@ import { convertToBinaryUnit, getDisplayUnitToInputSizeUnit } from '../helper'; import BAIFlex from './BAIFlex'; import BAIRowWrapWithDividers from './BAIRowWrapWithDividers'; -import BAIStatistic from './BAIStatistic'; +import BAIStatistic, { BAIStatisticProps } from './BAIStatistic'; import { Empty, theme } from 'antd'; import React from 'react'; import { useTranslation } from 'react-i18next'; @@ -28,7 +28,7 @@ interface ResourceData { interface ResourceStatisticsProps { resourceData: ResourceData; displayType: 'used' | 'free'; - showProgress?: boolean; + progressMode?: BAIStatisticProps['progressMode']; precision?: number; progressSteps?: number; } @@ -55,8 +55,8 @@ export const convertToNumber = (value: any): number => { const ResourceStatistics: React.FC = ({ resourceData, displayType, - showProgress = false, - progressSteps = 12, + progressMode = 'hidden', + progressSteps, precision = 2, }) => { const { t } = useTranslation(); @@ -85,7 +85,7 @@ const ResourceStatistics: React.FC = ({ total={resourceData.cpu[displayType].total} title={resourceData.cpu.metadata.title} unit={resourceData.cpu.metadata.displayUnit} - showProgress={showProgress} + progressMode={progressMode} progressSteps={progressSteps} precision={precision} /> @@ -96,7 +96,7 @@ const ResourceStatistics: React.FC = ({ total={resourceData.memory[displayType].total} title={resourceData.memory.metadata.title} unit={resourceData.memory.metadata.displayUnit} - showProgress={showProgress} + progressMode={progressMode} progressSteps={progressSteps} precision={precision} /> @@ -107,7 +107,7 @@ const ResourceStatistics: React.FC = ({ = ({ total={acc[displayType].total} title={acc.metadata.title} unit={acc.metadata.displayUnit} - showProgress={showProgress} + progressMode={progressMode} progressSteps={progressSteps} precision={precision} /> diff --git a/react/src/components/AgentStats.tsx b/react/src/components/AgentStats.tsx index 329c405372..f4373d2f46 100644 --- a/react/src/components/AgentStats.tsx +++ b/react/src/components/AgentStats.tsx @@ -215,7 +215,7 @@ const AgentStats: React.FC = ({ )} diff --git a/react/src/components/MyResource.tsx b/react/src/components/MyResource.tsx index cb9e063ff9..491505a3a6 100644 --- a/react/src/components/MyResource.tsx +++ b/react/src/components/MyResource.tsx @@ -181,7 +181,7 @@ const MyResource: React.FC = ({ ); diff --git a/react/src/components/MyResourceWithinResourceGroup.tsx b/react/src/components/MyResourceWithinResourceGroup.tsx index b1397895c9..1949e0e2b8 100644 --- a/react/src/components/MyResourceWithinResourceGroup.tsx +++ b/react/src/components/MyResourceWithinResourceGroup.tsx @@ -248,7 +248,7 @@ const MyResourceWithinResourceGroup: React.FC< )} diff --git a/react/src/components/SessionCountDashboardItem.tsx b/react/src/components/SessionCountDashboardItem.tsx index d2fe366848..07afe48591 100644 --- a/react/src/components/SessionCountDashboardItem.tsx +++ b/react/src/components/SessionCountDashboardItem.tsx @@ -1,11 +1,11 @@ import BAIFetchKeyButton from './BAIFetchKeyButton'; -import BAIPanelItem from './BAIPanelItem'; import { theme } from 'antd'; import { BAIBoardItemTitle, BAIFlex, BAIFlexProps, BAIRowWrapWithDividers, + BAIStatistic, } from 'backend.ai-ui'; import _ from 'lodash'; import { useTransition } from 'react'; @@ -72,7 +72,15 @@ const SessionCountDashboardItem: React.FC = ({ const { myInteractive, myBatch, myInference, myUpload } = data || {}; const renderBAIPanelItem = (title: string, value: number) => ( - + ); return ( @@ -81,8 +89,7 @@ const SessionCountDashboardItem: React.FC = ({ align="stretch" style={{ paddingLeft: token.paddingXL, - paddingRight: token.paddingXL, - height: '100%', + paddingRight: token.padding, ...props.style, }} {..._.omit(props, ['style'])} @@ -92,6 +99,7 @@ const SessionCountDashboardItem: React.FC = ({ title={title} extra={ { @@ -107,27 +115,12 @@ const SessionCountDashboardItem: React.FC = ({ type="text" style={{ backgroundColor: 'transparent', - margin: -token.marginXS, }} /> } /> - - {/* Scrollable Content Section */} - + );