|
1 | 1 | import React from 'react'; |
2 | 2 |
|
3 | 3 | import {Breadcrumbs} from '@gravity-ui/uikit'; |
| 4 | +import {get} from 'lodash'; |
4 | 5 | import {useHistory, useLocation} from 'react-router'; |
5 | 6 |
|
| 7 | +import {InternalLink} from '../../components/InternalLink'; |
6 | 8 | import {LinkWithIcon} from '../../components/LinkWithIcon/LinkWithIcon'; |
7 | 9 | import {parseQuery} from '../../routes'; |
8 | 10 | import {backend, customBackend} from '../../store'; |
@@ -33,66 +35,65 @@ interface HeaderProps { |
33 | 35 | function Header({mainPage}: HeaderProps) { |
34 | 36 | const history = useHistory(); |
35 | 37 | const location = useLocation(); |
| 38 | + const queryParams = parseQuery(location); |
36 | 39 |
|
37 | 40 | const singleClusterMode = useTypedSelector((state) => state.singleClusterMode); |
38 | 41 | const {page, pageBreadcrumbsOptions} = useTypedSelector((state) => state.header); |
39 | 42 |
|
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); |
45 | 44 |
|
46 | | - const clusterNameFinal = data?.Name || clusterNameFromQuery; |
| 45 | + const clusterName = get( |
| 46 | + clusterInfo, |
| 47 | + ['currentData', 'clusterData', 'Name'], |
| 48 | + queryParams.clusterName, |
| 49 | + ); |
47 | 50 |
|
48 | 51 | const breadcrumbItems = React.useMemo(() => { |
49 | 52 | const rawBreadcrumbs: RawBreadcrumbItem[] = []; |
50 | | - let options = pageBreadcrumbsOptions; |
| 53 | + const options = pageBreadcrumbsOptions; |
51 | 54 |
|
52 | 55 | if (mainPage) { |
53 | 56 | rawBreadcrumbs.push(mainPage); |
54 | 57 | } |
55 | 58 |
|
56 | | - if (clusterNameFinal) { |
57 | | - options = { |
58 | | - ...pageBreadcrumbsOptions, |
59 | | - clusterName: clusterNameFinal, |
60 | | - }; |
| 59 | + if (clusterName) { |
| 60 | + options.clusterName = clusterName; |
61 | 61 | } |
62 | 62 |
|
63 | 63 | const breadcrumbs = getBreadcrumbs(page, options, rawBreadcrumbs, queryParams); |
64 | 64 |
|
65 | 65 | 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: () => {}}; |
72 | 67 | }); |
73 | | - }, [clusterNameFinal, mainPage, history, queryParams, page, pageBreadcrumbsOptions]); |
| 68 | + }, [clusterName, mainPage, history, queryParams, page, pageBreadcrumbsOptions]); |
74 | 69 |
|
75 | 70 | const renderHeader = () => { |
76 | 71 | return ( |
77 | 72 | <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 | + /> |
96 | 97 |
|
97 | 98 | <LinkWithIcon title={DEVELOPER_UI_TITLE} url={getInternalLink(singleClusterMode)} /> |
98 | 99 | </header> |
|
0 commit comments