Skip to content

Commit 27893ab

Browse files
committed
chore: DeploymentConfigDiff - add support for item to scroll into view after accordion transition
1 parent 61db0a9 commit 27893ab

File tree

8 files changed

+26
-13
lines changed

8 files changed

+26
-13
lines changed

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": "0.1.15-beta-7",
3+
"version": "0.1.15-beta-11",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Shared/Components/Collapse/Collapse.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState, useRef } from 'react'
22

33
import { CollapseProps } from './types'
44

5-
export const Collapse = ({ expand, children }: CollapseProps) => {
5+
export const Collapse = ({ expand, onTransitionEnd, children }: CollapseProps) => {
66
const ref = useRef<HTMLDivElement>(null)
77
const [contentHeight, setContentHeight] = useState(0)
88

@@ -16,10 +16,10 @@ export const Collapse = ({ expand, children }: CollapseProps) => {
1616
<div
1717
style={{
1818
height: expand ? contentHeight : 0,
19-
transitionProperty: 'height',
20-
transitionDuration: '0.3s',
19+
transition: 'height 200ms ease-out',
2120
overflow: 'hidden',
2221
}}
22+
onTransitionEnd={onTransitionEnd}
2323
>
2424
<div ref={ref}>{children}</div>
2525
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './Collapse'
2+
export * from './types'
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ReactNode } from 'react'
1+
import { ReactNode, TransitionEvent } from 'react'
22

33
export interface CollapseProps {
44
expand: boolean
55
children: ReactNode
6+
onTransitionEnd?: (e: TransitionEvent<HTMLDivElement>) => void
67
}

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiffAccordion.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { Collapse } from '../Collapse'
66
import { DeploymentConfigDiffAccordionProps } from './types'
77

88
export const DeploymentConfigDiffAccordion = forwardRef<HTMLDivElement, DeploymentConfigDiffAccordionProps>(
9-
({ hasDiff, children, title, id, isExpanded, handleOnClick }, ref) => (
9+
({ hasDiff, children, title, id, isExpanded, onClick, onTransitionEnd }, ref) => (
1010
<div ref={ref} id={id} className="dc__border br-4 deployment-config-diff__accordion">
1111
<button
1212
type="button"
1313
className="dc__unset-button-styles px-16 py-10 flexbox dc__align-items-center dc__gap-8 w-100 br-4 bcn-50 dc__position-sticky dc__top-0 dc__zi-10"
1414
aria-label="expand-collapse-btn"
15-
onClick={handleOnClick}
15+
onClick={onClick}
1616
>
1717
<ICCaretDown
1818
className="icon-dim-16 fsn-6 rotate"
@@ -23,7 +23,9 @@ export const DeploymentConfigDiffAccordion = forwardRef<HTMLDivElement, Deployme
2323
className={`m-0 fs-13 lh-20 fw-6 ${hasDiff ? 'cy-7' : 'cg-7'}`}
2424
>{`${hasDiff ? 'Has' : 'No'} difference`}</p>
2525
</button>
26-
<Collapse expand={isExpanded}>{children}</Collapse>
26+
<Collapse expand={isExpanded} onTransitionEnd={onTransitionEnd}>
27+
{children}
28+
</Collapse>
2729
</div>
2830
),
2931
)

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiffMain.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export const DeploymentConfigDiffMain = ({
2929
})
3030
}
3131

32+
const handleTransitionEnd = () => {
33+
if (scrollIntoViewId) {
34+
const element = document.querySelector(`#${scrollIntoViewId}`)
35+
element?.scrollIntoView({ block: 'start' })
36+
}
37+
}
38+
3239
useEffect(() => {
3340
if (!isLoading) {
3441
setExpandedView(
@@ -114,7 +121,8 @@ export const DeploymentConfigDiffMain = ({
114121
title={title}
115122
isExpanded={expandedView[id]}
116123
hasDiff={hasDiff}
117-
handleOnClick={handleAccordionClick(id)}
124+
onClick={handleAccordionClick(id)}
125+
onTransitionEnd={handleTransitionEnd}
118126
>
119127
{isDeploymentTemplate ? (
120128
<>

src/Shared/Components/DeploymentConfigDiff/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SortingOrder } from '@Common/Constants'
33
import { DeploymentHistoryDetail } from '../CICDHistory'
44
import { CollapsibleListConfig, CollapsibleListItem } from '../CollapsibleList'
55
import { SelectPickerProps } from '../SelectPicker'
6+
import { CollapseProps } from '../Collapse'
67

78
export interface DeploymentConfigType {
89
list: DeploymentHistoryDetail
@@ -74,11 +75,11 @@ export interface DeploymentConfigDiffMainProps
7475
'isLoading' | 'headerText' | 'configList' | 'scrollIntoViewId' | 'selectorsConfig' | 'sortingConfig'
7576
> {}
7677

77-
export interface DeploymentConfigDiffAccordionProps {
78+
export interface DeploymentConfigDiffAccordionProps extends Pick<CollapseProps, 'onTransitionEnd'> {
7879
id: string
7980
title: string
8081
children: React.ReactNode
8182
hasDiff?: boolean
8283
isExpanded?: boolean
83-
handleOnClick?: (e: React.MouseEvent<HTMLButtonElement>) => void
84+
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void
8485
}

0 commit comments

Comments
 (0)