-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathNodeHostWrapper.tsx
77 lines (67 loc) · 2.55 KB
/
NodeHostWrapper.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
import {PopoverBehavior} from '@gravity-ui/uikit';
import {getDefaultNodePath} from '../../containers/Node/NodePages';
import type {NodeAddress} from '../../types/additionalProps';
import type {TNodeInfo, TSystemStateInfo} from '../../types/api/nodes';
import {
createBaseDeveloperUILinkWithNodeId,
createDeveloperUIInternalPageHref,
} from '../../utils/developerUI/developerUI';
import {isUnavailableNode} from '../../utils/nodes';
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
import {EntityStatus} from '../EntityStatus/EntityStatus';
import {NodeEndpointsTooltipContent} from '../TooltipsContent';
export type NodeHostData = NodeAddress &
Pick<TNodeInfo, 'ConnectStatus'> &
Pick<TSystemStateInfo, 'SystemState'> & {
NodeId: string | number;
TenantName?: string;
};
export type StatusForIcon = 'SystemState' | 'ConnectStatus';
interface NodeHostWrapperProps {
node: NodeHostData;
getNodeRef?: (node?: NodeAddress) => string | null;
database?: string;
statusForIcon?: StatusForIcon;
}
export const NodeHostWrapper = ({
node,
getNodeRef,
database,
statusForIcon,
}: NodeHostWrapperProps) => {
if (!node.Host) {
return <span>—</span>;
}
const status = statusForIcon === 'ConnectStatus' ? node.ConnectStatus : node.SystemState;
const isNodeAvailable = !isUnavailableNode(node);
let developerUIInternalHref: string | undefined;
if (getNodeRef) {
const developerUIHref = getNodeRef(node);
developerUIInternalHref = developerUIHref
? createDeveloperUIInternalPageHref(developerUIHref, database)
: undefined;
} else if (node.NodeId) {
const developerUIHref = createBaseDeveloperUILinkWithNodeId(node.NodeId);
developerUIInternalHref = createDeveloperUIInternalPageHref(developerUIHref, database);
}
const nodePath = isNodeAvailable
? getDefaultNodePath(
node.NodeId,
{
database: database ?? node.TenantName,
},
node.TenantName ? 'tablets' : 'storage',
)
: undefined;
return (
<CellWithPopover
disabled={!isNodeAvailable}
content={<NodeEndpointsTooltipContent data={node} nodeHref={developerUIInternalHref} />}
placement={['top', 'bottom']}
behavior={PopoverBehavior.Immediate}
delayClosing={200}
>
<EntityStatus name={node.Host} status={status} path={nodePath} hasClipboardButton />
</CellWithPopover>
);
};