Skip to content

Commit 946131c

Browse files
authored
Merge pull request #910 from devtron-labs/feat/nested-navigation-route
feat: Nested Routing (breadcrumb optional in buildInfraDescription props)
2 parents 27a9277 + 046beb3 commit 946131c

11 files changed

Lines changed: 96 additions & 29 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.20.3-pre-12",
3+
"version": "1.20.5-pre-5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/BreadCrumb/BreadCrumb.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import React, { useMemo, useEffect } from 'react'
1818
import { Link, useRouteMatch, useParams } from 'react-router-dom'
19-
import { useBreadcrumbContext } from './BreadcrumbStore'
19+
import { useBreadcrumbContext, getBreadCrumbSeparator } from './BreadcrumbStore'
2020
import { ConditionalWrap } from '../Helper'
2121
import { Breadcrumb, Breadcrumbs, UseBreadcrumbOptionalProps, UseBreadcrumbState } from './Types'
2222

@@ -115,7 +115,7 @@ export const BreadCrumb: React.FC<Breadcrumbs> = ({
115115
</ConditionalWrap>
116116

117117
{idx + 1 !== filteredCrumbs.length && breadcrumb.name && (
118-
<span className="dc__devtron-breadcrumb__item__separator">{sep}</span>
118+
getBreadCrumbSeparator(sep)
119119
)}
120120
</React.Fragment>
121121
))}

src/Common/BreadCrumb/BreadcrumbStore.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const BreadcrumbText = ({ heading, isActive, shouldTruncate = false }: Br
2525
<span className={`dc__breadcrumb-text cb-5 fs-16 lh-1-5 ${shouldTruncate ? 'dc__truncate' : ''} ${isActive ? 'cn-9 fw-6' : 'cb-5 fw-4 dc__mxw-155 dc__ellipsis-right'}`}>{heading}</span>
2626
)
2727

28+
export const getBreadCrumbSeparator = (sep: string = '/') => (
29+
<span className="dc__devtron-breadcrumb__item__separator">{sep}</span>
30+
)
31+
2832
const Store = ({ children }) => {
2933
const [state, setState] = useState(initialState)
3034
return <BreadcrumbContext.Provider value={{ state, setState }}>{children}</BreadcrumbContext.Provider>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react'
2+
import { Link } from 'react-router-dom'
3+
4+
import { BreadcrumbText, getBreadCrumbSeparator } from './BreadcrumbStore'
5+
import { NestedBreadCrumbProps } from './Types'
6+
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+
...(profileName
13+
? [
14+
{ type: 'link', label: 'Profiles', to: redirectUrl },
15+
{
16+
type: 'text',
17+
label: profileName,
18+
},
19+
]
20+
: [
21+
{
22+
type: 'text',
23+
label: 'Create Profile',
24+
},
25+
]),
26+
]
27+
28+
return (
29+
<div className="flex left flex-grow-1 dc__gap-4">
30+
{breadcrumbs.map((crumb, index) => (
31+
<React.Fragment key={crumb.label}>
32+
{crumb.type === 'link' ? (
33+
<Link to={crumb.to!} className={breadcrumbLinkClass}>
34+
{crumb.label}
35+
</Link>
36+
) : (
37+
<BreadcrumbText heading={crumb.label} isActive />
38+
)}
39+
{index < breadcrumbs.length - 1 && getBreadCrumbSeparator()}
40+
</React.Fragment>
41+
))}
42+
</div>
43+
)
44+
}

src/Common/BreadCrumb/Types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,19 @@ export interface BreadcrumbTextProps {
5252
*/
5353
shouldTruncate?: boolean
5454
}
55+
56+
export interface NestedBreadCrumbProps {
57+
/**
58+
* It is the url to which the link should redirect
59+
*/
60+
redirectUrl: string
61+
/**
62+
* It is the text of the link
63+
*/
64+
linkText: string
65+
/**
66+
* It is the name of the profile
67+
* If not given, would show "Create Profile"
68+
*/
69+
profileName: string
70+
}

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const URLS = {
100100
APPLICATION_MANAGEMENT_CONFIGURATIONS_DEPLOYMENT_CHARTS: `${APPLICATION_MANAGEMENT_CONFIGURATIONS}/deployment-charts`,
101101
APPLICATION_MANAGEMENT_CONFIGURATIONS_SCOPED_VARIABLES: `${APPLICATION_MANAGEMENT_CONFIGURATIONS}/scoped-variables`,
102102
APPLICATION_MANAGEMENT_CONFIGURATIONS_BUILD_INFRA: `${APPLICATION_MANAGEMENT_CONFIGURATIONS}/build-infra`,
103+
APPLICATION_MANAGEMENT_CONFIGURATIONS_BUILD_INFRA_PROFILES: `${APPLICATION_MANAGEMENT_CONFIGURATIONS}/build-infra/profiles`,
103104
APPLICATION_MANAGEMENT_CONFIGURATIONS_NOTIFICATIONS: `${APPLICATION_MANAGEMENT_CONFIGURATIONS}/notifications`,
104105
// INFRASTRUCTURE MANAGEMENT
105106
INFRASTRUCTURE_MANAGEMENT: INFRASTRUCTURE_MANAGEMENT_ROOT,

src/Common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './AddCDButton'
1818
export * from './API'
1919
export { BreadCrumb, useBreadcrumb } from './BreadCrumb/BreadCrumb'
2020
export { default as BreadcrumbStore, BreadcrumbText } from './BreadCrumb/BreadcrumbStore'
21+
export { NestedBreadCrumb } from './BreadCrumb/NestedBreadCrumb'
2122
export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSelector'
2223
export * from './Checkbox'
2324
export * from './CIPipeline.Types'

src/Pages/GlobalConfigurations/BuildInfra/Descriptor.tsx

Lines changed: 8 additions & 4 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,
26+
tooltipNode,
2727
tippyInfoText,
2828
tippyAdditionalContent,
29-
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/constants.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { ReactComponent as ICTag } from '@Icons/ic-tag.svg'
1919
import { ReactComponent as ICTimer } from '@Icons/ic-timer.svg'
2020
import { ReactComponent as ICCpu } from '@IconsV2/ic-cpu.svg'
2121
import { ReactComponent as ICMemory } from '@IconsV2/ic-memory.svg'
22-
import { UseBreadcrumbProps } from '@Common/BreadCrumb/Types'
2322
import { CMSecretComponentType } from '@Shared/Services'
2423

2524
import {
@@ -82,17 +81,6 @@ export const BUILD_INFRA_TEXT = {
8281
INVALID_FORM_MESSAGE: 'Valid input is required for all mandatory fields.',
8382
} as const
8483

85-
export const BUILD_INFRA_BREADCRUMB: UseBreadcrumbProps = {
86-
alias: {
87-
'application-management': null,
88-
configurations: null,
89-
'build-infra': {
90-
component: <h2 className="m-0 cn-9 fs-16 fw-6 lh-32">{BUILD_INFRA_TEXT.HEADING}</h2>,
91-
linked: false,
92-
},
93-
},
94-
}
95-
9684
export const BUILD_INFRA_LOCATOR_MARKER_MAP: Readonly<Record<BuildInfraLocators, BuildInfraFormFieldType['marker']>> = {
9785
[BuildInfraLocators.CPU]: ICCpu,
9886
[BuildInfraLocators.MEMORY]: ICMemory,

0 commit comments

Comments
 (0)