Skip to content

Commit 904ea56

Browse files
committed
wip: tooltip
1 parent 0b1eac5 commit 904ea56

File tree

5 files changed

+86
-8
lines changed

5 files changed

+86
-8
lines changed

src/components/Graph/BlockComponents/ConnectionBlockComponent.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type {TBlock} from '@gravity-ui/graph';
22
import { Icon } from '@gravity-ui/uikit';
33
import {CodeMerge, Shuffle, VectorCircle, MapPin, BroadcastSignal} from '@gravity-ui/icons';
44

5+
import { TooltipComponent } from '../TooltipComponent';
6+
57
type Props = {
68
block: TBlock;
79
className: string;
@@ -24,9 +26,18 @@ const getIcon = (name: string) => {
2426

2527
export const ConnectionBlockComponent = ({className, block}: Props) => {
2628
const icon = getIcon(block.name);
27-
return (
29+
const content = (
2830
<div className={className}>
2931
{icon && <Icon data={icon}/>} {block.name}
3032
</div>
3133
);
34+
35+
if (!block.stats?.length) {
36+
return content;
37+
}
38+
39+
return (
40+
<TooltipComponent block={block}>{content}</TooltipComponent>
41+
42+
);
3243
};
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
import type {TBlock} from '@gravity-ui/graph';
1+
import type { TBlock } from '@gravity-ui/graph';
22
import { Text } from '@gravity-ui/uikit';
33

4+
import { TooltipComponent } from '../TooltipComponent';
5+
46
type Props = {
57
block: TBlock;
68
className: string;
79
};
810

9-
export const StageBlockComponent = ({className, block}: Props) => {
11+
export const StageBlockComponent = ({ className, block }: Props) => {
12+
const content = <div className={className}>
13+
{block.operators ? block.operators.map((item) => <div key={item}>{item}</div>) : block.name}
14+
{block.tables ? <div><Text color='secondary'>Tables: </Text>{block.tables.join(', ')}</div> : null}
15+
</div>;
16+
17+
if (!block.stats?.length) {
18+
return content;
19+
}
20+
1021
return (
11-
<div className={className}>
12-
{block.operators ? block.operators.map((item) => <div key={item}>{item}</div>) : block.name}
13-
{block.tables ? <div><Text color='secondary'>Tables: </Text>{block.tables.join(', ')}</div> : null}
14-
</div>
22+
<TooltipComponent block={block}>{content}</TooltipComponent>
23+
1524
);
1625
};

src/components/Graph/GravityGraph.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@
4141
}
4242

4343
&__block-content.connection {
44+
display: flex;
45+
align-items: center;
46+
gap: 4px;
4447
border-radius: 6px;
4548
box-shadow: none;
4649
background: var(--g-color-base-info-light);
4750
border: 1px solid var(--g-color-line-info);
4851
color: var(--g-color-text-info-heavy);
4952
}
53+
54+
&__tooltip-content {
55+
padding: 8px;
56+
width: 300px;
57+
font-size: var(--g-text-body-short-font-size);
58+
line-height: var(--g-text-body-short-line-height);
59+
60+
}
5061
}

src/components/Graph/GravityGraph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const config = {
5656
const elk = new ELK();
5757

5858
const renderBlockFn = (graph, block) => {
59-
console.log('===', block);
59+
// console.log('===', block);
6060

6161
const map = {
6262
query: QueryBlockComponent,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { useState, useMemo } from 'react';
2+
import type { TBlock } from '@gravity-ui/graph';
3+
import { Text, Popover, TabProvider, TabList, Tab, TabPanel } from '@gravity-ui/uikit';
4+
5+
type Props = {
6+
block: TBlock;
7+
children: React.ReactNode;
8+
};
9+
10+
const getTooltipContent = (block: TBlock) => {
11+
const [activeTab, setActiveTab] = useState(block?.stats[0]?.group);
12+
13+
return (
14+
<TabProvider value={activeTab} onUpdate={setActiveTab}>
15+
<TabList>
16+
{block?.stats?.map((item) => <Tab value={item.group}>{item.group}</Tab>)}
17+
</TabList>
18+
{block?.stats?.map((item) => <TabPanel value={item.group}>
19+
{item.stats?.map((stat) => <div key={stat.name}>
20+
{Boolean(stat.items) &&
21+
<>
22+
<strong>{stat.name}</strong>
23+
{stat.items?.map(({ name, value }) => <div key={value}>{name}: {value}</div>)}
24+
</>
25+
}
26+
{!stat.items && <div>{stat.name}: {stat.value}</div>}
27+
28+
29+
</div>)}
30+
</TabPanel>)}
31+
</TabProvider>
32+
);
33+
}
34+
35+
export const TooltipComponent = ({ block, children }: Props) => {
36+
return (
37+
<Popover content={getTooltipContent(block)}
38+
hasArrow
39+
trigger='click'
40+
placement='right-start'
41+
className='ydb-gravity-graph__tooltip-content'
42+
disablePortal
43+
strategy='fixed'>
44+
{children}
45+
</Popover>
46+
);
47+
};

0 commit comments

Comments
 (0)