Skip to content

Commit 9bf2565

Browse files
committed
chore: BuildInfraDescriptorProps type & NestedBreadCrumb component refactoring
1 parent 874dea2 commit 9bf2565

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1+
import React from 'react'
12
import { Link } from 'react-router-dom'
23

34
import { BreadcrumbText, getBreadCrumbSeparator } from './BreadcrumbStore'
45
import { NestedBreadCrumbProps } from './Types'
56

6-
export const NestedBreadCrumb = ({ redirectUrl, linkText, profileName }: NestedBreadCrumbProps) => (
7-
<div className="flex left flex-grow-1">
8-
<Link
9-
className="active dc__devtron-breadcrumb__item fs-16 fw-4 lh-1-5 dc__ellipsis-right dc__mxw-155"
10-
to={redirectUrl}
11-
>
12-
{linkText}
13-
</Link>
14-
{getBreadCrumbSeparator()}
15-
<BreadcrumbText heading={profileName} isActive />
16-
</div>
17-
)
7+
export const NestedBreadCrumb = ({ redirectUrl, linkText, profileName }: NestedBreadCrumbProps) => {
8+
const breadcrumbLinkClass = 'active dc__devtron-breadcrumb__item fs-16 fw-4 lh-1-5 dc__ellipsis-right dc__mxw-155'
9+
10+
const breadcrumbs = [
11+
{ type: 'link', label: linkText, to: redirectUrl },
12+
{ type: 'link', label: 'Profiles', to: redirectUrl },
13+
{ type: 'text', label: profileName },
14+
]
15+
16+
return (
17+
<div className="flex left flex-grow-1 dc__gap-4">
18+
{breadcrumbs.map((crumb, index) => (
19+
<React.Fragment key={crumb.label}>
20+
{crumb.type === 'link' ? (
21+
<Link to={crumb.to!} className={breadcrumbLinkClass}>
22+
{crumb.label}
23+
</Link>
24+
) : (
25+
<BreadcrumbText heading={crumb.label} isActive />
26+
)}
27+
{index < breadcrumbs.length - 1 && getBreadCrumbSeparator()}
28+
</React.Fragment>
29+
))}
30+
</div>
31+
)
32+
}

src/Pages/GlobalConfigurations/BuildInfra/Descriptor.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,30 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { NestedBreadCrumb, URLS } from '@Common/index'
1718
import { InfoIconTippy } from '@Shared/Components/InfoIconTippy'
1819

19-
import { BreadCrumb } from '../../../Common'
2020
import { BUILD_INFRA_TEXT } from './constants'
2121
import { BuildInfraDescriptorProps } from './types'
2222

2323
const Descriptor = ({
2424
additionalContainerClasses,
25-
breadCrumbs,
2625
children,
2726
tippyInfoText,
2827
tippyAdditionalContent,
2928
tooltipNode,
3029
tooltipHeading,
30+
profileName,
3131
}: BuildInfraDescriptorProps) => (
3232
<div className={`flexbox dc__content-space dc__align-items-center w-100 ${additionalContainerClasses ?? ''}`}>
3333
<div className="flexbox dc__align-items-center dc__gap-4">
3434
{tooltipNode || (
3535
<>
36-
<BreadCrumb breadcrumbs={breadCrumbs} />
36+
<NestedBreadCrumb
37+
redirectUrl={URLS.APPLICATION_MANAGEMENT_CONFIGURATIONS_BUILD_INFRA_PROFILES}
38+
linkText={BUILD_INFRA_TEXT.HEADING}
39+
profileName={profileName}
40+
/>
3741
<InfoIconTippy
3842
infoText={tippyInfoText ?? BUILD_INFRA_TEXT.EDIT_DEFAULT_TOOLTIP}
3943
additionalContent={tippyAdditionalContent}

src/Pages/GlobalConfigurations/BuildInfra/types.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { FormEvent, FunctionComponent, ReactNode, SyntheticEvent } from 'react'
1919
import { BUILD_INFRA_INHERIT_ACTIONS, useBuildInfraForm } from '@Pages/index'
2020

2121
import { ServerErrors } from '../../../Common'
22-
import { Breadcrumb } from '../../../Common/BreadCrumb/Types'
2322
import {
2423
CMSecretComponentType,
2524
CMSecretConfigData,
@@ -76,21 +75,31 @@ export enum BuildInfraProfileVariants {
7675
CUSTOM = 'CUSTOM',
7776
}
7877

79-
export interface BuildInfraDescriptorProps {
78+
export type BuildInfraDescriptorProps = {
8079
/**
8180
* In case we want to restrict the max-width
8281
*/
8382
additionalContainerClasses?: string
84-
breadCrumbs?: Breadcrumb[]
8583
/**
8684
* Would stick at right of div
8785
*/
8886
children?: ReactNode
89-
tippyInfoText?: string
90-
tippyAdditionalContent?: ReactNode
91-
tooltipNode?: ReactNode
92-
tooltipHeading?: string
93-
}
87+
} & (
88+
| {
89+
tooltipNode: ReactNode
90+
tippyInfoText?: never
91+
tooltipHeading?: never
92+
tippyAdditionalContent?: never
93+
profileName?: never
94+
}
95+
| {
96+
tooltipNode?: never
97+
tippyInfoText: string
98+
tooltipHeading?: string
99+
tippyAdditionalContent?: ReactNode
100+
profileName?: string
101+
}
102+
)
94103

95104
export type NumericBuildInfraConfigTypes = Extract<
96105
BuildInfraConfigTypes,

0 commit comments

Comments
 (0)