Skip to content

Commit 3c9bb3b

Browse files
committed
feat: add Collapse Transition component, add Collapse Tranisition to DeploymentDiffAccordion, CollapsibleList, DeploymentDiffMain - by default disable, SelectPicker: add disableDescription prop
1 parent fb51fa8 commit 3c9bb3b

File tree

12 files changed

+139
-58
lines changed

12 files changed

+139
-58
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useEffect, useState, useRef } from 'react'
2+
3+
import { CollapseProps } from './types'
4+
5+
export const Collapse = ({ expand, children }: CollapseProps) => {
6+
const ref = useRef<HTMLDivElement>(null)
7+
const [contentHeight, setContentHeight] = useState(0)
8+
9+
useEffect(() => {
10+
if (ref.current) {
11+
setContentHeight(ref.current.clientHeight)
12+
}
13+
}, [children])
14+
15+
return (
16+
<div
17+
style={{
18+
height: expand ? contentHeight : 0,
19+
transitionProperty: 'height',
20+
transitionDuration: '0.3s',
21+
overflow: 'hidden',
22+
}}
23+
>
24+
<div ref={ref}>{children}</div>
25+
</div>
26+
)
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Collapse'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ReactNode } from 'react'
2+
3+
export interface CollapseProps {
4+
expand: boolean
5+
children: ReactNode
6+
}

src/Shared/Components/CollapsibleList/CollapsibleList.component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Tippy, { TippyProps } from '@tippyjs/react'
55
import { ConditionalWrap } from '@Common/Helper'
66
import { ReactComponent as ICExpand } from '@Icons/ic-expand.svg'
77

8+
import { Collapse } from '../Collapse'
89
import { CollapsibleListProps } from './CollapsibleList.types'
910
import './CollapsibleList.scss'
1011

@@ -51,7 +52,7 @@ export const CollapsibleList = ({ config, onCollapseBtnClick }: CollapsibleListP
5152
</ConditionalWrap>
5253
)}
5354
</div>
54-
{isExpanded && (
55+
<Collapse expand={isExpanded}>
5556
<div className="collapsible ml-16 pl-4 dc__border-left">
5657
{!items.length ? (
5758
<div className="collapsible__item flexbox dc__gap-8 dc__no-decor no-hover br-4 py-6 px-8">
@@ -96,7 +97,7 @@ export const CollapsibleList = ({ config, onCollapseBtnClick }: CollapsibleListP
9697
))
9798
)}
9899
</div>
99-
)}
100+
</Collapse>
100101
</Fragment>
101102
))}
102103
</div>

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiffAccordion.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { forwardRef } from 'react'
22

33
import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
44

5+
import { Collapse } from '../Collapse'
56
import { DeploymentConfigDiffAccordionProps } from './types'
67

78
export const DeploymentConfigDiffAccordion = forwardRef<HTMLDivElement, DeploymentConfigDiffAccordionProps>(
@@ -22,7 +23,7 @@ export const DeploymentConfigDiffAccordion = forwardRef<HTMLDivElement, Deployme
2223
className={`m-0 fs-13 lh-20 fw-6 ${hasDiff ? 'cy-7' : 'cg-7'}`}
2324
>{`${hasDiff ? 'Has' : 'No'} difference`}</p>
2425
</button>
25-
{isExpanded && children}
26+
<Collapse expand={isExpanded}>{children}</Collapse>
2627
</div>
2728
),
2829
)

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiffMain.tsx

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Fragment, useEffect, useState } from 'react'
22

33
import { ReactComponent as ICSortArrowDown } from '@Icons/ic-sort-arrow-down.svg'
4+
import { ReactComponent as ICSort } from '@Icons/ic-arrow-up-down.svg'
45
import { Progressing } from '@Common/Progressing'
56
import { CodeEditor } from '@Common/CodeEditor'
67
import { MODES, SortingOrder } from '@Common/Constants'
@@ -15,8 +16,8 @@ export const DeploymentConfigDiffMain = ({
1516
headerText = 'Compare With',
1617
configList = [],
1718
selectorsConfig,
18-
sortOrder,
19-
onSortBtnClick,
19+
sortingConfig,
20+
scrollIntoViewId,
2021
}: DeploymentConfigDiffMainProps) => {
2122
// STATES
2223
const [expandedView, setExpandedView] = useState<Record<string | number, boolean>>({})
@@ -29,10 +30,21 @@ export const DeploymentConfigDiffMain = ({
2930
}
3031

3132
useEffect(() => {
32-
if (!isLoading && configList) {
33-
setExpandedView(configList.reduce((acc, curr) => ({ ...acc, [curr.id]: curr.hasDiff }), {}))
33+
if (!isLoading) {
34+
setExpandedView(
35+
configList.reduce(
36+
(acc, curr) => ({ ...acc, [curr.id]: scrollIntoViewId === curr.id || curr.hasDiff }),
37+
{},
38+
),
39+
)
40+
}
41+
}, [isLoading])
42+
43+
useEffect(() => {
44+
if (scrollIntoViewId) {
45+
setExpandedView((prev) => ({ ...prev, [scrollIntoViewId]: true }))
3446
}
35-
}, [isLoading, configList])
47+
}, [scrollIntoViewId])
3648

3749
const renderHeaderSelectors = (list: DeploymentConfigDiffSelectPickerProps[]) =>
3850
list.map((configItem, index) => {
@@ -59,22 +71,36 @@ export const DeploymentConfigDiffMain = ({
5971
)
6072
})
6173

62-
const renderSortButton = () => (
63-
<div className="dc__border-left p-12 h-100">
64-
<button
65-
type="button"
66-
className={`dc__unset-button-styles flexbox dc__align-items-center dc__gap-6 ${isLoading ? 'dc__disabled' : ''}`}
67-
onClick={onSortBtnClick}
68-
disabled={isLoading}
69-
>
70-
<ICSortArrowDown
71-
className="fcn-7 rotate"
72-
style={{ ['--rotateBy' as string]: sortOrder === SortingOrder.ASC ? '0deg' : '180deg' }}
73-
/>
74-
<span className="cn-7 fs-13 lh-20 fw-6">Sort keys</span>
75-
</button>
76-
</div>
77-
)
74+
const renderSortButton = () => {
75+
if (sortingConfig) {
76+
const { handleSorting, sortBy, sortOrder } = sortingConfig
77+
78+
return (
79+
<div className="dc__border-left p-12 h-100">
80+
<button
81+
type="button"
82+
className={`dc__unset-button-styles flexbox dc__align-items-center dc__gap-6 ${isLoading ? 'dc__disabled' : ''}`}
83+
onClick={handleSorting}
84+
disabled={isLoading}
85+
>
86+
{sortBy ? (
87+
<ICSortArrowDown
88+
className="fcn-7 rotate"
89+
style={{
90+
['--rotateBy' as string]: sortOrder === SortingOrder.ASC ? '0deg' : '180deg',
91+
}}
92+
/>
93+
) : (
94+
<ICSort className="icon-dim-12 mw-12 scn-7" />
95+
)}
96+
<span className="cn-7 fs-13 lh-20 fw-6">Sort keys</span>
97+
</button>
98+
</div>
99+
)
100+
}
101+
102+
return null
103+
}
78104

79105
const renderDiffs = () =>
80106
configList.map(({ id, isDeploymentTemplate, primaryConfig, secondaryConfig, title, hasDiff }) => {
@@ -97,7 +123,7 @@ export const DeploymentConfigDiffMain = ({
97123
<div className="px-12 py-6">{secondaryHeading}</div>
98124
</div>
99125
<CodeEditor
100-
key={sortOrder}
126+
key={sortingConfig?.sortOrder}
101127
diffView
102128
defaultValue={primaryList.codeEditorValue.value}
103129
value={secondaryList.codeEditorValue.value}
@@ -114,13 +140,13 @@ export const DeploymentConfigDiffMain = ({
114140
<div className="px-12 py-6">{secondaryHeading}</div>
115141
</div>
116142
<DeploymentHistoryDiffView
117-
key={`${id}-${sortOrder}`}
143+
key={`${id}-${sortingConfig?.sortOrder || ''}`}
118144
baseTemplateConfiguration={secondaryList}
119145
currentConfiguration={primaryList}
120146
previousConfigAvailable
121147
rootClassName="m-16 mt-0-imp dc__no-top-radius dc__no-top-border"
122148
comparisonBodyClassName="m-16"
123-
sortOrder={sortOrder}
149+
sortOrder={sortingConfig?.sortOrder}
124150
/>
125151
</>
126152
)}
@@ -139,7 +165,7 @@ export const DeploymentConfigDiffMain = ({
139165
<div className="flex-grow-1 flexbox dc__align-items-center dc__gap-4 p-12">
140166
{renderHeaderSelectors(selectorsConfig.secondaryConfig)}
141167
</div>
142-
{onSortBtnClick && renderSortButton()}
168+
{renderSortButton()}
143169
</div>
144170
</div>
145171
<div className="deployment-config-diff__main-content">

src/Shared/Components/DeploymentConfigDiff/types.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ export interface DeploymentConfigDiffProps {
5050
primaryConfig: DeploymentConfigDiffSelectPickerProps[]
5151
secondaryConfig: DeploymentConfigDiffSelectPickerProps[]
5252
}
53-
sortOrder?: SortingOrder
54-
onSortBtnClick?: () => void
53+
sortingConfig?: {
54+
sortBy: string
55+
sortOrder: SortingOrder
56+
handleSorting: () => void
57+
}
5558
navList: DeploymentConfigDiffNavigationItem[]
5659
collapsibleNavList: DeploymentConfigDiffNavigationCollapsibleItem[]
5760
goBackURL?: string
@@ -68,13 +71,7 @@ export interface DeploymentConfigDiffNavigationProps
6871
export interface DeploymentConfigDiffMainProps
6972
extends Pick<
7073
DeploymentConfigDiffProps,
71-
| 'isLoading'
72-
| 'headerText'
73-
| 'configList'
74-
| 'scrollIntoViewId'
75-
| 'selectorsConfig'
76-
| 'sortOrder'
77-
| 'onSortBtnClick'
74+
'isLoading' | 'headerText' | 'configList' | 'scrollIntoViewId' | 'selectorsConfig' | 'sortingConfig'
7875
> {}
7976

8077
export interface DeploymentConfigDiffAccordionProps {

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const SelectPicker = ({
187187
LoadingIndicator: SelectPickerLoadingIndicator,
188188
DropdownIndicator: SelectPickerDropdownIndicator,
189189
Control: renderControl,
190-
Option: SelectPickerOption,
190+
Option: SelectPickerOption(props),
191191
MenuList: renderMenuList,
192192
ClearIndicator: SelectPickerClearIndicator,
193193
ValueContainer: renderValueContainer,

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,37 @@ export const SelectPickerValueContainer = ({
7575

7676
export const SelectPickerLoadingIndicator = () => <Progressing />
7777

78-
export const SelectPickerOption = (props: OptionProps<SelectPickerOptionType>) => {
79-
const { label, data } = props
80-
const { description, startIcon, endIcon } = data ?? {}
81-
const showDescription = !!description
78+
export const SelectPickerOption =
79+
({ disableDescriptionEllipsis = false }: SelectPickerProps) =>
80+
(props: OptionProps<SelectPickerOptionType>) => {
81+
const { label, data } = props
82+
const { description, startIcon, endIcon } = data ?? {}
83+
const showDescription = !!description
8284

83-
return (
84-
<components.Option {...props}>
85-
<div className={`flex left ${showDescription ? 'top' : ''} dc__gap-8`}>
86-
{startIcon && (
87-
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{startIcon}</div>
88-
)}
89-
<div className="flex-grow-1">
90-
<h4 className="m-0 cn-9 fs-13 fw-4 lh-20 dc__truncate">{label}</h4>
91-
{/* Add support for custom ellipsis if required */}
92-
{showDescription && <p className="m-0 fs-12 fw-4 lh-18 cn-7 dc__truncate">{description}</p>}
85+
return (
86+
<components.Option {...props}>
87+
<div className={`flex left ${showDescription ? 'top' : ''} dc__gap-8`}>
88+
{startIcon && (
89+
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{startIcon}</div>
90+
)}
91+
<div className="flex-grow-1">
92+
<h4 className="m-0 cn-9 fs-13 fw-4 lh-20 dc__truncate">{label}</h4>
93+
{/* Add support for custom ellipsis if required */}
94+
{showDescription && (
95+
<p
96+
className={`m-0 fs-12 fw-4 lh-18 cn-7 ${!disableDescriptionEllipsis ? 'dc__truncate' : ''}`}
97+
>
98+
{description}
99+
</p>
100+
)}
101+
</div>
102+
{endIcon && (
103+
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{endIcon}</div>
104+
)}
93105
</div>
94-
{endIcon && <div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{endIcon}</div>}
95-
</div>
96-
</components.Option>
97-
)
98-
}
106+
</components.Option>
107+
)
108+
}
99109

100110
export const SelectPickerMenuList = ({
101111
renderMenuListFooter,

src/Shared/Components/SelectPicker/type.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,10 @@ export interface SelectPickerProps
102102
* @default SelectPickerVariantType.DEFAULT
103103
*/
104104
variant?: SelectPickerVariantType
105+
/**
106+
* Disables the ellipsis on description, it will be shown in full width, wrapped if required.
107+
*
108+
* @default false
109+
*/
110+
disableDescriptionEllipsis?: boolean
105111
}

0 commit comments

Comments
 (0)