Skip to content

Commit 7b3a2ff

Browse files
committed
feat: add commit chip cell in trigger details
1 parent 72bf7d4 commit 7b3a2ff

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

src/Shared/Components/CICDHistory/TriggerOutput.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import moment from 'moment'
2121
import { toast } from 'react-toastify'
2222
import { ReactComponent as ICLines } from '@Icons/ic-lines.svg'
2323
import { ShowMoreText } from '@Shared/Components/ShowMoreText'
24+
import { getHandleOpenURL } from '@Shared/Helpers'
25+
import { ImageChipCell } from '@Shared/Components/ImageChipCell'
26+
import { CommitChipCell } from '@Shared/Components/CommitChipCell'
2427
import {
2528
ConfirmationDialog,
2629
DATE_TIME_FORMATS,
@@ -65,7 +68,6 @@ import { DeploymentHistoryDetailedView, DeploymentHistoryConfigList } from './De
6568
import { GitChanges, Scroller } from './History.components'
6669
import Artifacts from './Artifacts'
6770
import { statusColor as colorMap, EMPTY_STATE_STATUS, PULSATING_STATUS_MAP } from '../../constants'
68-
import { ImageChipCell } from '../ImageChipCell'
6971
import './cicdHistory.scss'
7072

7173
const Finished = React.memo(
@@ -284,6 +286,7 @@ const StartDetails = ({
284286
}: StartDetailsType): JSX.Element => {
285287
const { url } = useRouteMatch()
286288
const { pathname } = useLocation()
289+
287290
return (
288291
<div className="pb-12 w-100 pr-20 flex column left dc__border-bottom-n1">
289292
<div className="flexbox dc__gap-8 dc__align-items-center">
@@ -313,24 +316,25 @@ const StartDetails = ({
313316
const gitDetail: GitTriggers = gitTriggers[ciMaterial.id]
314317
return gitDetail ? (
315318
<React.Fragment key={ciMaterial.id}>
316-
{ciMaterial.type !== 'WEBHOOK' && (
317-
<a
318-
target="_blank"
319-
rel="noopener noreferrer"
320-
href={createGitCommitUrl(ciMaterial.url, gitDetail.Commit)}
321-
className="dc__app-commit__hash bcn-1 cn-7"
322-
>
323-
{gitDetail.Commit?.substr(0, 7)}
324-
</a>
319+
{ciMaterial.type !== 'WEBHOOK' && gitDetail.Commit && (
320+
<CommitChipCell
321+
commits={[gitDetail.Commit]}
322+
handleClick={getHandleOpenURL(
323+
createGitCommitUrl(ciMaterial.url, gitDetail.Commit),
324+
)}
325+
/>
325326
)}
326327
{ciMaterial.type === 'WEBHOOK' &&
327328
gitDetail.WebhookData &&
328-
gitDetail.WebhookData.Data && (
329-
<span className="dc__app-commit__hash">
330-
{gitDetail.WebhookData.EventActionType === 'merged'
331-
? gitDetail.WebhookData.Data['target checkout']?.substr(0, 7)
332-
: gitDetail.WebhookData.Data['target checkout']}
333-
</span>
329+
gitDetail.WebhookData.Data &&
330+
gitDetail.WebhookData.Data['target checkout'] && (
331+
<CommitChipCell
332+
commits={
333+
gitDetail.WebhookData.EventActionType === 'merged'
334+
? gitDetail.WebhookData.Data['target checkout'].substr(0, 7)
335+
: gitDetail.WebhookData.Data['target checkout']
336+
}
337+
/>
334338
)}
335339
</React.Fragment>
336340
) : null
@@ -413,12 +417,12 @@ export const TriggerDetails = React.memo(
413417
triggerMetadata,
414418
renderDeploymentHistoryTriggerMetaText,
415419
}: TriggerDetailsType): JSX.Element => (
416-
<div className="trigger-details flexbox-col pb-4">
420+
<div className="trigger-details flexbox-col pb-12">
417421
<div className="display-grid trigger-details__grid py-12">
418422
<div className="flexbox dc__content-center">
419423
<TriggerDetailsStatusIcon status={status?.toLowerCase()} />
420424
</div>
421-
<div className="trigger-details__summary flexbox-col flex-grow-1">
425+
<div className="trigger-details__summary flexbox-col flex-grow-1 lh-20">
422426
<StartDetails
423427
startedOn={startedOn}
424428
triggeredBy={triggeredBy}

src/Shared/Components/CommitChipCell/CommitChipCell.tsx

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

17+
import { noop } from '@Common/Helper'
1718
import { ReactComponent as CommitIcon } from '../../../Assets/Icon/ic-code-commit.svg'
1819
import { CommitChipCellProps } from './types'
1920

20-
const CommitChipCell = ({ handleClick, commits }: CommitChipCellProps) =>
21+
const CommitChipCell = ({ handleClick = noop, commits }: CommitChipCellProps) =>
2122
commits?.length > 0 ? (
2223
<div className="flexbox">
2324
<button
2425
type="button"
25-
className="dc__transparent p-0 flexbox dc__gap-4 fs-14 lh-20 cb-5 dc__ellipsis-right mono cursor"
26+
className="dc__transparent p-0 flexbox dc__gap-4 fs-14 lh-20 cb-5 dc__truncate mono cursor"
2627
onClick={handleClick}
2728
>
2829
<span className="flex dc__gap-4 br-4 pl-6 pr-6 bcb-1">

src/Shared/Components/CommitChipCell/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
import { SyntheticEvent } from 'react'
1818

1919
export interface CommitChipCellProps {
20-
handleClick: (e: SyntheticEvent) => void
20+
handleClick?: (e: SyntheticEvent) => void
2121
commits?: string[]
2222
}

src/Shared/Helpers.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,3 +747,11 @@ export const getFileNameFromHeaders = (headers: Headers) =>
747747
?.find((n) => n.includes('filename='))
748748
?.replace('filename=', '')
749749
.trim()
750+
751+
/**
752+
* @description - Function to open a new tab with the given url
753+
* @param url - url to be opened in new tab
754+
*/
755+
export const getHandleOpenURL = (url: string) => () => {
756+
window.open(url, '_blank', 'noreferrer')
757+
}

0 commit comments

Comments
 (0)