-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathKeysView.tsx
54 lines (47 loc) · 2 KB
/
KeysView.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
import {Label} from '@gravity-ui/uikit';
import {ContentWithPopup} from '../../../../components/ContentWithPopup/ContentWithPopup';
import i18n from './i18n';
import {b} from './shared';
import type {SchemaData} from './types';
import {getPartitioningKeys, getPrimaryKeys} from './utils';
const MAX_VISIBLE_KEYS = 3;
interface KeysViewProps {
tableData: SchemaData[];
extended?: boolean;
type: 'primary' | 'partitioning';
}
export const KeysView = ({tableData, extended, type}: KeysViewProps) => {
const keys = type === 'primary' ? getPrimaryKeys(tableData) : getPartitioningKeys(tableData);
const visibleCount = extended ? MAX_VISIBLE_KEYS : keys.length;
const visibleKeys = keys.slice(0, visibleCount);
const hiddenKeys = keys.slice(visibleCount);
return keys.length > 0 ? (
<div className={b('keys', {summary: !extended, type})}>
<div className={b('keys-header')}>
{type === 'primary' ? i18n('primary-key.title') : i18n('partitioning-key.title')}
</div>
<div className={b('keys-values')}>
{' ' + visibleKeys.join(', ')}
{hiddenKeys.length ? (
<ContentWithPopup
className={b('more-badge')}
placement={['bottom']}
hasArrow={false}
pinOnClick
content={
<div className={b('popup-content')}>
{hiddenKeys.map((key) => (
<div className={b('popup-item')} key={key}>
{key}
</div>
))}
</div>
}
>
<Label className={b('keys-label')}>{`+${hiddenKeys.length}`}</Label>
</ContentWithPopup>
) : null}
</div>
</div>
) : null;
};