Skip to content

Commit 72bf7d4

Browse files
committed
refactor: Update ImageChipCell component to toggle expand state and use it in TriggerDetails
1 parent e2e3bf4 commit 72bf7d4

File tree

3 files changed

+54
-36
lines changed

3 files changed

+54
-36
lines changed

src/Shared/Components/CICDHistory/DeploymentHistoryDiff/DeploymentHistoryConfigList.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const DeploymentHistoryConfigList = ({
6262
setFullScreenView(false)
6363
}}
6464
data-testid={`configuration-link-option-${index}`}
65-
className="bcb-1 dc__no-decor bcn-0 cn-9 pl-16 pr-16 pt-12 pb-12 br-4 en-2 bw-1 mb-12 flex dc__content-space cursor lh-20"
65+
className="bcb-1 dc__no-decor bcn-0 cn-9 pl-16 pr-16 pt-12 pb-12 br-4 en-2 bw-1 flex dc__content-space cursor lh-20"
6666
>
6767
{childComponentName || currentComponent.DISPLAY_NAME}
6868
<ICChevron className="icon-dim-20 fcn-6 dc__flip-270" />
@@ -87,7 +87,7 @@ const DeploymentHistoryConfigList = ({
8787
<div className="px-20 pt-20 fs-13 cn-9" key={`history-list__${index}`}>
8888
{historicalComponent.childList?.length > 0 ? (
8989
<>
90-
<div className="fs-14 fw-6">
90+
<div className="fs-14 fw-6 mb-12">
9191
{DEPLOYMENT_HISTORY_CONFIGURATION_LIST_MAP[historicalComponent.name].DISPLAY_NAME}
9292
</div>
9393
{historicalComponent.childList.map((historicalComponentName, childIndex) =>

src/Shared/Components/ImageChipCell/ImageChipCell.component.tsx

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

17+
import { useState } from 'react'
1718
import Tippy from '@tippyjs/react'
18-
import { noop } from '@Common/Helper'
1919
import { ReactComponent as DockerIcon } from '../../../Assets/Icon/ic-docker.svg'
2020
import { ImageChipCellProps } from './types'
2121
import './imageChipCell.scss'
2222

2323
const ImageChipCell = ({
2424
imagePath,
2525
registryType,
26-
handleClick = noop,
27-
isExpanded = false,
26+
handleClick,
27+
isExpanded: isExpandedProp,
2828
placement = 'auto',
29-
}: ImageChipCellProps) => (
30-
<div className="cn-7 fs-14 lh-20 flexbox">
31-
<Tippy content={imagePath} className="default-tt" placement={placement} arrow={false}>
32-
<button
33-
type="button"
34-
className={`display-grid dc__align-items-center image-chip-cell__container ${isExpanded ? 'image-chip-cell__container--expanded' : ''} bcn-1 br-6 dc__transparent py-0 px-6 cursor max-w-100`}
35-
onClick={handleClick}
36-
>
37-
{registryType ? (
38-
<div className={`h-14 w-14 dc__registry-icon ${registryType} br-8 dc__no-shrink`} />
39-
) : (
40-
<DockerIcon className="icon-dim-14 mw-14" />
41-
)}
42-
{isExpanded ? (
43-
<div className="mono dc__ellipsis-left direction-left">{imagePath}</div>
44-
) : (
45-
<>
46-
<div></div>
47-
<div className="mono dc__ellipsis-left direction-left text-overflow-clip">
48-
{imagePath.split(':').slice(-1)[0] ?? ''}
49-
</div>
50-
</>
51-
)}
52-
</button>
53-
</Tippy>
54-
</div>
55-
)
29+
}: ImageChipCellProps) => {
30+
const [isExpandedState, setIsExpandedState] = useState<boolean>(false)
31+
32+
const handleToggleExpand = () => {
33+
setIsExpandedState((prev) => !prev)
34+
}
35+
36+
const isExpanded = isExpandedProp ?? isExpandedState
37+
38+
return (
39+
<div className="cn-7 fs-14 lh-20 flexbox">
40+
<Tippy content={imagePath} className="default-tt" placement={placement} arrow={false}>
41+
<button
42+
type="button"
43+
className={`display-grid dc__align-items-center dc__select-text image-chip-cell__container ${isExpanded ? 'image-chip-cell__container--expanded' : ''} bcn-1 br-6 dc__transparent py-0 px-6 cursor max-w-100`}
44+
onClick={handleClick || handleToggleExpand}
45+
>
46+
{registryType ? (
47+
<div className={`h-14 w-14 dc__registry-icon ${registryType} br-8 dc__no-shrink`} />
48+
) : (
49+
<DockerIcon className="icon-dim-14 mw-14" />
50+
)}
51+
{isExpanded ? (
52+
<div className="mono dc__ellipsis-left direction-left">{imagePath}</div>
53+
) : (
54+
<>
55+
<div></div>
56+
<div className="mono dc__ellipsis-left direction-left text-overflow-clip">
57+
{imagePath.split(':').slice(-1)[0] ?? ''}
58+
</div>
59+
</>
60+
)}
61+
</button>
62+
</Tippy>
63+
</div>
64+
)
65+
}
5666

5767
export default ImageChipCell

src/Shared/Components/ImageChipCell/types.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ import Tippy from '@tippyjs/react'
1717
import { ComponentProps, SyntheticEvent } from 'react'
1818
import { RegistryType } from '../../types'
1919

20-
export interface ImageChipCellProps {
20+
type ImageChipCellButtonActionProps =
21+
| {
22+
handleClick: (e: SyntheticEvent) => void
23+
isExpanded: boolean
24+
}
25+
| {
26+
handleClick?: never
27+
isExpanded?: never
28+
}
29+
30+
export type ImageChipCellProps = {
2131
imagePath: string
22-
isExpanded?: boolean
23-
handleClick?: (e: SyntheticEvent) => void
2432
registryType?: RegistryType
2533
placement?: ComponentProps<typeof Tippy>['placement']
26-
}
34+
} & ImageChipCellButtonActionProps

0 commit comments

Comments
 (0)