Skip to content

Commit 862660c

Browse files
authored
fix(Header): add icons for nodes and tablets (#500)
1 parent 46220c4 commit 862660c

File tree

9 files changed

+75
-39
lines changed

9 files changed

+75
-39
lines changed

src/components/Tablet/Tablet.scss

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
.tablet {
2-
display: flex;
3-
justify-content: center;
4-
5-
width: 23px;
6-
height: 18px;
7-
8-
font-size: 10px;
92
cursor: pointer;
10-
text-transform: uppercase;
113

124
color: var(--yc-color-text-complementary);
13-
border: 1px solid var(--yc-color-base-generic-medium-hover);
14-
border-radius: 4px;
5+
border-color: var(--yc-color-base-generic-medium-hover);
156

167
&__wrapper {
178
margin-right: 2px;
@@ -25,12 +16,6 @@
2516
padding: 10px;
2617
}
2718

28-
&__type {
29-
line-height: 17px;
30-
31-
color: var(--yc-color-text-complementary);
32-
}
33-
3419
&_status_gray {
3520
background-color: var(--yc-color-text-complementary);
3621
}

src/components/Tablet/Tablet.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {getTabletLabel} from '../../utils/constants';
55
import routes, {createHref} from '../../routes';
66

77
import {ContentWithPopup} from '../ContentWithPopup/ContentWithPopup';
8+
import {TabletIcon} from '../TabletIcon/TabletIcon';
89
import {InternalLink} from '../InternalLink';
910
import {TabletTooltipContent} from '../TooltipsContent';
1011

@@ -18,20 +19,19 @@ interface TabletProps {
1819
}
1920

2021
export const Tablet = ({tablet = {}, tenantName}: TabletProps) => {
21-
const {TabletId: id, NodeId} = tablet;
22+
const {TabletId: id, NodeId, Type} = tablet;
2223
const status = tablet.Overall?.toLowerCase();
2324

24-
const tabletPath = id && createHref(routes.tablet, {id}, {nodeId: NodeId, tenantName});
25+
const tabletPath =
26+
id && createHref(routes.tablet, {id}, {nodeId: NodeId, tenantName, type: Type});
2527

2628
return (
2729
<ContentWithPopup
2830
className={b('wrapper')}
2931
content={<TabletTooltipContent data={tablet} className={b('popup-content')} />}
3032
>
3133
<InternalLink to={tabletPath}>
32-
<div className={b({status})}>
33-
<div className={b('type')}>{[getTabletLabel(tablet.Type)]}</div>
34-
</div>
34+
<TabletIcon className={b({status})} text={getTabletLabel(tablet.Type)} />
3535
</InternalLink>
3636
</ContentWithPopup>
3737
);
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.tablet-icon {
2+
display: flex;
3+
justify-content: center;
4+
5+
width: 23px;
6+
height: 16px;
7+
8+
font-size: 10px;
9+
text-transform: uppercase;
10+
11+
border: 1px solid;
12+
border-radius: 4px;
13+
14+
&__type {
15+
line-height: 14px;
16+
}
17+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import cn from 'bem-cn-lite';
2+
3+
import './TabletIcon.scss';
4+
5+
interface TabletIconProps {
6+
text?: string;
7+
className?: string;
8+
}
9+
10+
const b = cn('tablet-icon');
11+
12+
export const TabletIcon = ({text, className}: TabletIconProps) => {
13+
return (
14+
<div className={b(null, className)}>
15+
<div className={b('type')}>{text || 'T'}</div>
16+
</div>
17+
);
18+
};

src/containers/Header/Header.scss

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
align-items: center;
1616

1717
&__icon {
18+
display: flex;
19+
1820
margin-right: 3px;
1921
}
2022
}

src/containers/Header/Header.tsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {useHistory, useLocation} from 'react-router';
33
import {useDispatch} from 'react-redux';
44
import block from 'bem-cn-lite';
55

6-
import {Breadcrumbs, Icon} from '@gravity-ui/uikit';
6+
import {Breadcrumbs} from '@gravity-ui/uikit';
77

88
import {ExternalLinkWithIcon} from '../../components/ExternalLinkWithIcon/ExternalLinkWithIcon';
99

@@ -91,12 +91,7 @@ function Header({mainPage}: HeaderProps) {
9191
}
9292
return (
9393
<span className={b('breadcrumb')}>
94-
<Icon
95-
width={16}
96-
height={16}
97-
data={icon}
98-
className={b('breadcrumb__icon')}
99-
/>
94+
<div className={b('breadcrumb__icon')}>{icon}</div>
10095
{text}
10196
</span>
10297
);

src/containers/Header/breadcrumbs.ts renamed to src/containers/Header/breadcrumbs.tsx

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import nodesRightIcon from '@gravity-ui/icons/svgs/nodes-right.svg';
2-
import databaseIcon from '@gravity-ui/icons/svgs/database.svg';
1+
import {
2+
NodesRight as ClusterIcon,
3+
Database as DatabaseIcon,
4+
Cpu as ComputeNodeIcon,
5+
HardDrive as StorageNodeIcon,
6+
} from '@gravity-ui/icons';
37

48
import type {
59
BreadcrumbsOptions,
@@ -15,8 +19,9 @@ import {
1519
TENANT_PAGE,
1620
TENANT_PAGES_IDS,
1721
} from '../../store/reducers/tenant/constants';
22+
import {TabletIcon} from '../../components/TabletIcon/TabletIcon';
1823
import routes, {createHref} from '../../routes';
19-
import {CLUSTER_DEFAULT_TITLE} from '../../utils/constants';
24+
import {CLUSTER_DEFAULT_TITLE, getTabletLabel} from '../../utils/constants';
2025

2126
import {getClusterPath} from '../Cluster/utils';
2227
import {TenantTabsGroups, getTenantPath} from '../Tenant/TenantPages';
@@ -29,7 +34,7 @@ const prepareTenantName = (tenantName: string) => {
2934
export interface RawBreadcrumbItem {
3035
text: string;
3136
link?: string;
32-
icon?: SVGIconData;
37+
icon?: JSX.Element;
3338
}
3439

3540
const getClusterBreadcrumbs = (
@@ -42,7 +47,7 @@ const getClusterBreadcrumbs = (
4247
{
4348
text: clusterName || CLUSTER_DEFAULT_TITLE,
4449
link: getClusterPath(clusterTab, query),
45-
icon: nodesRightIcon,
50+
icon: <ClusterIcon />,
4651
},
4752
];
4853
};
@@ -56,7 +61,7 @@ const getTenantBreadcrumbs = (
5661
const text = tenantName ? prepareTenantName(tenantName) : 'Tenant';
5762
const link = tenantName ? getTenantPath({...query, name: tenantName}) : undefined;
5863

59-
return [...getClusterBreadcrumbs(options, query), {text, link, icon: databaseIcon}];
64+
return [...getClusterBreadcrumbs(options, query), {text, link, icon: <DatabaseIcon />}];
6065
};
6166

6267
const getNodeBreadcrumbs = (options: NodeBreadcrumbsOptions, query = {}): RawBreadcrumbItem[] => {
@@ -81,8 +86,13 @@ const getNodeBreadcrumbs = (options: NodeBreadcrumbsOptions, query = {}): RawBre
8186

8287
const text = nodeId ? `Node ${nodeId}` : 'Node';
8388
const link = nodeId ? getDefaultNodePath(nodeId, query) : undefined;
89+
const icon = isStorageNode ? <StorageNodeIcon /> : <ComputeNodeIcon />;
8490

85-
breadcrumbs.push({text, link});
91+
breadcrumbs.push({
92+
text,
93+
link,
94+
icon,
95+
});
8696

8797
return breadcrumbs;
8898
};
@@ -123,12 +133,13 @@ const getTabletBreadcrubms = (
123133
options: TabletBreadcrumbsOptions,
124134
query = {},
125135
): RawBreadcrumbItem[] => {
126-
const {tabletId} = options;
136+
const {tabletId, tabletType} = options;
127137

128138
const breadcrumbs = getTabletsBreadcrubms(options, query);
129139

130140
breadcrumbs.push({
131141
text: tabletId || 'Tablet',
142+
icon: <TabletIcon text={getTabletLabel(tabletType)} />,
132143
});
133144

134145
return breadcrumbs;

src/containers/Tablet/Tablet.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {DEVELOPER_UI_TITLE} from '../../utils/constants';
1313
import '../../services/api';
1414
import {parseQuery} from '../../routes';
1515

16+
import type {EType} from '../../types/api/tablet';
1617
import EntityStatus from '../../components/EntityStatus/EntityStatus';
1718
import {ResponseError} from '../../components/Errors/ResponseError';
1819
import {Tag} from '../../components/Tag';
@@ -48,10 +49,14 @@ export const Tablet = () => {
4849
error,
4950
} = useTypedSelector((state) => state.tablet);
5051

51-
const {nodeId: queryNodeId, tenantName: queryTenantName} = parseQuery(location);
52-
52+
const {
53+
nodeId: queryNodeId,
54+
tenantName: queryTenantName,
55+
type: queryTabletType,
56+
} = parseQuery(location);
5357
const nodeId = tablet.NodeId?.toString() || queryNodeId?.toString();
5458
const tenantName = tenantPath || queryTenantName?.toString();
59+
const type = tablet.Type || (queryTabletType?.toString() as EType | undefined);
5560

5661
// NOTE: should be reviewed when migrating to React 18
5762
useEffect(() => {
@@ -79,9 +84,10 @@ export const Tablet = () => {
7984
nodeIds: nodeId ? [nodeId] : [],
8085
tenantName,
8186
tabletId: id,
87+
tabletType: type,
8288
}),
8389
);
84-
}, [dispatch, tenantName, id, nodeId]);
90+
}, [dispatch, tenantName, id, nodeId, type]);
8591

8692
const renderExternalLinks = (link: {name: string; path: string}, index: number) => {
8793
return (

src/store/reducers/header/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {ClusterTab} from '../../../containers/Cluster/utils';
2+
import type {EType} from '../../../types/api/tablet';
23

34
import {setHeaderBreadcrumbs} from './header';
45

@@ -23,6 +24,7 @@ export interface TabletsBreadcrumbsOptions extends TenantBreadcrumbsOptions {
2324

2425
export interface TabletBreadcrumbsOptions extends TabletsBreadcrumbsOptions {
2526
tabletId?: string;
27+
tabletType?: EType;
2628
}
2729

2830
export type BreadcrumbsOptions =

0 commit comments

Comments
 (0)