|
1 | | -import {CircularProgressBar} from '../../../../../../components/CircularProgressBar/CircularProgressBar'; |
2 | 1 | import {DiagnosticCard} from '../../../../../../components/DiagnosticCard/DiagnosticCard'; |
| 2 | +import {ProgressViewer} from '../../../../../../components/ProgressViewer/ProgressViewer'; |
| 3 | +import type {ProgressViewerProps} from '../../../../../../components/ProgressViewer/ProgressViewer'; |
| 4 | +import {StatusIcon} from '../../../../../../components/StatusIcon/StatusIcon'; |
3 | 5 | import type {MetricStatus} from '../../../../../../store/reducers/tenants/types'; |
4 | | -import {formatUsage} from '../../../../../../store/reducers/tenants/utils'; |
| 6 | +import {EFlag} from '../../../../../../types/api/enums'; |
5 | 7 | import {cn} from '../../../../../../utils/cn'; |
6 | | -import i18n from '../../i18n'; |
7 | 8 |
|
8 | 9 | import './MetricCard.scss'; |
9 | 10 |
|
10 | 11 | const b = cn('ydb-metrics-card'); |
11 | 12 |
|
| 13 | +const getStatusIcon = (status?: MetricStatus) => { |
| 14 | + let colorStatus: EFlag | undefined; |
| 15 | + |
| 16 | + if (status === 'Warning') { |
| 17 | + colorStatus = EFlag.Yellow; |
| 18 | + } |
| 19 | + if (status === 'Danger') { |
| 20 | + colorStatus = EFlag.Red; |
| 21 | + } |
| 22 | + |
| 23 | + if (colorStatus) { |
| 24 | + return <StatusIcon status={colorStatus} mode="icons" size="l" />; |
| 25 | + } |
| 26 | + |
| 27 | + return null; |
| 28 | +}; |
| 29 | + |
| 30 | +export interface DiagnosticsCardMetric extends ProgressViewerProps { |
| 31 | + title?: React.ReactNode; |
| 32 | +} |
| 33 | + |
12 | 34 | interface MetricCardProps { |
13 | 35 | active?: boolean; |
14 | | - progress?: number; |
15 | 36 | label?: string; |
16 | 37 | status?: MetricStatus; |
17 | | - resourcesUsed?: string; |
| 38 | + metrics: DiagnosticsCardMetric[]; |
18 | 39 | } |
19 | 40 |
|
20 | | -export function MetricCard({active, progress, label, status, resourcesUsed}: MetricCardProps) { |
| 41 | +export function MetricCard({active, label, status, metrics}: MetricCardProps) { |
21 | 42 | const renderContent = () => { |
22 | | - if (progress === undefined && resourcesUsed === undefined) { |
23 | | - return <div className={b('content')}>{i18n('no-data')}</div>; |
24 | | - } |
25 | | - |
26 | | - return ( |
27 | | - <div className={b('content')}> |
28 | | - {progress && <div className={b('progress')}>{formatUsage(progress)}</div>} |
29 | | - {resourcesUsed && <div className={b('resources')}>{resourcesUsed}</div>} |
30 | | - </div> |
31 | | - ); |
| 43 | + return metrics.map(({title, ...progressViewerProps}, index) => { |
| 44 | + return ( |
| 45 | + <div key={index} className={b('metric')}> |
| 46 | + <div className={b('metric-title')}>{title}</div> |
| 47 | + <ProgressViewer size="xs" colorizeProgress={true} {...progressViewerProps} /> |
| 48 | + </div> |
| 49 | + ); |
| 50 | + }); |
32 | 51 | }; |
33 | 52 | return ( |
34 | 53 | <DiagnosticCard className={b({active})} active={active}> |
35 | | - <div className={b('header')}>{label && <div className={b('label')}>{label}</div>}</div> |
36 | | - <CircularProgressBar |
37 | | - size={172} |
38 | | - strokeWidth={11} |
39 | | - progress={progress || 0} |
40 | | - content={renderContent()} |
41 | | - status={status} |
42 | | - circleBgClassName={b('progress-bar-circle-bg')} |
43 | | - /> |
| 54 | + <div className={b('header')}> |
| 55 | + {label && <div className={b('label')}>{label}</div>} |
| 56 | + {getStatusIcon(status)} |
| 57 | + </div> |
| 58 | + <div className={b('content')}>{renderContent()}</div> |
44 | 59 | </DiagnosticCard> |
45 | 60 | ); |
46 | 61 | } |
0 commit comments