-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathEntityStatus.tsx
95 lines (83 loc) · 2.47 KB
/
EntityStatus.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React from 'react';
import type {LabelProps} from '@gravity-ui/uikit';
import {ActionTooltip, Flex, HelpMark, Label} from '@gravity-ui/uikit';
import {EFlag} from '../../types/api/enums';
import {cn} from '../../utils/cn';
import {StatusIcon} from '../StatusIconNew/StatusIcon';
import i18n from './i18n';
import {EFlagToDescription} from './utils';
import './EntityStatus.scss';
const b = cn('ydb-entity-status-new');
const EFlagToLabelTheme: Record<EFlag, LabelProps['theme'] | 'orange'> = {
[EFlag.Red]: 'danger',
[EFlag.Blue]: 'info',
[EFlag.Green]: 'success',
[EFlag.Grey]: 'unknown',
[EFlag.Orange]: 'orange',
[EFlag.Yellow]: 'warning',
};
const EFlagToStatusName: Record<EFlag, string> = {
get [EFlag.Red]() {
return i18n('title_red');
},
get [EFlag.Yellow]() {
return i18n('title_yellow');
},
get [EFlag.Orange]() {
return i18n('title_orange');
},
get [EFlag.Green]() {
return i18n('title_green');
},
get [EFlag.Grey]() {
return i18n('title_grey');
},
get [EFlag.Blue]() {
return i18n('title_blue');
},
};
interface EntityStatusLabelProps {
status: EFlag;
note?: React.ReactNode;
children?: React.ReactNode;
withStatusName?: boolean;
size?: LabelProps['size'];
}
function EntityStatusLabel({
children,
status,
withStatusName = true,
note,
size = 'm',
}: EntityStatusLabelProps) {
const theme = EFlagToLabelTheme[status];
return (
<ActionTooltip title={EFlagToDescription[status]} disabled={Boolean(note)}>
<Label
theme={theme === 'orange' ? undefined : theme}
icon={<StatusIcon status={status} />}
size={size}
className={b({orange: theme === 'orange'})}
>
<Flex gap="2" wrap="nowrap">
{children}
{withStatusName ? EFlagToStatusName[status] : null}
{note && <HelpMark>{note}</HelpMark>}
</Flex>
</Label>
</ActionTooltip>
);
}
interface EntityStatusProps {
children?: React.ReactNode;
className?: string;
}
export function EntityStatus({className, children}: EntityStatusProps) {
return (
<Flex gap="2" wrap="nowrap" alignItems="center" className={b(null, className)}>
{children}
</Flex>
);
}
EntityStatus.Label = EntityStatusLabel;
EntityStatus.displayName = 'EntityStatus';