Skip to content

Commit cdf36da

Browse files
NaiSideraIvan Samarin
andauthored
feat(Header): use InternalLink for breadcrumb items (#913)
Co-authored-by: Ivan Samarin <[email protected]>
1 parent 86faa42 commit cdf36da

File tree

6 files changed

+142
-145
lines changed

6 files changed

+142
-145
lines changed

src/containers/Header/Header.scss

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,23 @@
1010

1111
border-bottom: 1px solid var(--g-color-line-generic);
1212

13-
&__breadcrumb {
13+
&__breadcrumbs-item {
1414
display: flex;
15-
align-items: center;
15+
gap: 3px;
16+
17+
color: var(--g-color-text-secondary);
1618

17-
&__icon {
18-
display: flex;
19+
&_link:hover {
20+
color: var(--g-color-text-complementary);
21+
}
1922

20-
margin-right: 3px;
23+
&_active {
24+
color: var(--g-color-text-primary);
2125
}
2226
}
27+
28+
&__breadcrumbs-icon {
29+
display: flex;
30+
align-items: center;
31+
}
2332
}

src/containers/Header/Header.tsx

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React from 'react';
22

33
import {Breadcrumbs} from '@gravity-ui/uikit';
4+
import {get} from 'lodash';
45
import {useHistory, useLocation} from 'react-router';
56

7+
import {InternalLink} from '../../components/InternalLink';
68
import {LinkWithIcon} from '../../components/LinkWithIcon/LinkWithIcon';
79
import {parseQuery} from '../../routes';
810
import {backend, customBackend} from '../../store';
@@ -33,66 +35,65 @@ interface HeaderProps {
3335
function Header({mainPage}: HeaderProps) {
3436
const history = useHistory();
3537
const location = useLocation();
38+
const queryParams = parseQuery(location);
3639

3740
const singleClusterMode = useTypedSelector((state) => state.singleClusterMode);
3841
const {page, pageBreadcrumbsOptions} = useTypedSelector((state) => state.header);
3942

40-
const queryParams = parseQuery(location);
41-
42-
const clusterNameFromQuery = queryParams.clusterName?.toString();
43-
const {currentData: {clusterData: data} = {}} =
44-
clusterApi.useGetClusterInfoQuery(clusterNameFromQuery);
43+
const clusterInfo = clusterApi.useGetClusterInfoQuery(queryParams.clusterName);
4544

46-
const clusterNameFinal = data?.Name || clusterNameFromQuery;
45+
const clusterName = get(
46+
clusterInfo,
47+
['currentData', 'clusterData', 'Name'],
48+
queryParams.clusterName,
49+
);
4750

4851
const breadcrumbItems = React.useMemo(() => {
4952
const rawBreadcrumbs: RawBreadcrumbItem[] = [];
50-
let options = pageBreadcrumbsOptions;
53+
const options = pageBreadcrumbsOptions;
5154

5255
if (mainPage) {
5356
rawBreadcrumbs.push(mainPage);
5457
}
5558

56-
if (clusterNameFinal) {
57-
options = {
58-
...pageBreadcrumbsOptions,
59-
clusterName: clusterNameFinal,
60-
};
59+
if (clusterName) {
60+
options.clusterName = clusterName;
6161
}
6262

6363
const breadcrumbs = getBreadcrumbs(page, options, rawBreadcrumbs, queryParams);
6464

6565
return breadcrumbs.map((item) => {
66-
const action = () => {
67-
if (item.link) {
68-
history.push(item.link);
69-
}
70-
};
71-
return {...item, action};
66+
return {...item, action: () => {}};
7267
});
73-
}, [clusterNameFinal, mainPage, history, queryParams, page, pageBreadcrumbsOptions]);
68+
}, [clusterName, mainPage, history, queryParams, page, pageBreadcrumbsOptions]);
7469

7570
const renderHeader = () => {
7671
return (
7772
<header className={b()}>
78-
<div>
79-
<Breadcrumbs
80-
items={breadcrumbItems}
81-
lastDisplayedItemsCount={1}
82-
firstDisplayedItemsCount={1}
83-
renderItemContent={({icon, text}) => {
84-
if (!icon) {
85-
return text;
86-
}
87-
return (
88-
<span className={b('breadcrumb')}>
89-
<div className={b('breadcrumb__icon')}>{icon}</div>
90-
{text}
91-
</span>
92-
);
93-
}}
94-
/>
95-
</div>
73+
<Breadcrumbs
74+
items={breadcrumbItems}
75+
lastDisplayedItemsCount={1}
76+
firstDisplayedItemsCount={1}
77+
className={b('breadcrumbs')}
78+
renderItem={({item, isCurrent}) => {
79+
const {icon, text, link} = item;
80+
81+
return (
82+
<InternalLink
83+
className={b('breadcrumbs-item', {
84+
active: isCurrent,
85+
link: !isCurrent,
86+
})}
87+
to={isCurrent ? undefined : link}
88+
>
89+
{icon ? (
90+
<span className={b('breadcrumbs-icon')}>{icon}</span>
91+
) : null}
92+
<span>{text}</span>
93+
</InternalLink>
94+
);
95+
}}
96+
/>
9697

9798
<LinkWithIcon title={DEVELOPER_UI_TITLE} url={getInternalLink(singleClusterMode)} />
9899
</header>

0 commit comments

Comments
 (0)