Skip to content

Commit 0c33ac3

Browse files
committed
refactor: Artifacts, UserIdentifier - code optimization, remove redundancy
1 parent c88025a commit 0c33ac3

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

src/Shared/Components/CICDHistory/Artifacts.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ export const CIListItem = ({
6969
targetPlatforms,
7070
isDeploymentWithoutApproval,
7171
}: CIListItemType) => {
72-
const headerMetaDataPresent =
73-
!!getIsApprovalPolicyConfigured(userApprovalMetadata?.approvalConfigData) ||
74-
!!appliedFilters?.length ||
75-
!!promotionApprovalMetadata?.promotedFromType
76-
77-
const showCIListHeader = (headerMetaDataPresent || isDeploymentWithoutApproval) && !!renderCIListHeader
72+
const showCIListHeader =
73+
!!renderCIListHeader &&
74+
(!!getIsApprovalPolicyConfigured(userApprovalMetadata?.approvalConfigData) ||
75+
!!appliedFilters?.length ||
76+
!!promotionApprovalMetadata?.promotedFromType ||
77+
isDeploymentWithoutApproval)
7878

7979
return (
8080
<>

src/Shared/Components/UserIdentifier/UserIdentifier.tsx

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,51 @@ export const UserIdentifier = ({
2525
// HOOKS
2626
const { email: currentUserEmail } = useUserEmail()
2727

28+
if (!email) {
29+
return null
30+
}
31+
2832
// CONSTANTS
2933
const isCurrentUser = email === currentUserEmail
34+
const isApiToken = email.startsWith(API_TOKEN_PREFIX)
35+
36+
const renderIcon = () => {
37+
if (isApiToken) {
38+
return <Icon name="ic-key" color="N700" size={20} />
39+
}
40+
41+
return isUserGroup ? (
42+
<Icon name="ic-users" color="N700" size={20} />
43+
) : (
44+
getAlphabetIcon(email, 'dc__no-shrink m-0-imp')
45+
)
46+
}
47+
48+
const renderText = () => {
49+
if (isCurrentUser) {
50+
return 'You'
51+
}
52+
53+
if (isApiToken) {
54+
return email.split(':')?.[1] || '-'
55+
}
56+
57+
return email
58+
}
3059

3160
return (
3261
<div className={`flexbox dc__gap-8 ${rootClassName || ''}`}>
33-
{email.startsWith(API_TOKEN_PREFIX) ? (
34-
<UserIdentifierTooltip tooltipContent={tooltipContent}>
35-
<Icon name="ic-key" color="N700" size={20} />
36-
<div className="flexbox dc__gap-2">
37-
<Tooltip
38-
{...(tooltipContent
39-
? { content: email, alwaysShowTippyOnHover: false }
40-
: { content: email })}
41-
>
42-
<span className="cn-9 fs-13 fw-4 lh-20 dc__truncate">
43-
{isCurrentUser ? 'You' : email.split(':')?.[1] || '-'}
44-
</span>
45-
</Tooltip>
46-
{children}
47-
</div>
48-
</UserIdentifierTooltip>
49-
) : (
50-
<UserIdentifierTooltip tooltipContent={tooltipContent}>
51-
{isUserGroup ? (
52-
<Icon name="ic-users" color="N700" size={20} />
53-
) : (
54-
getAlphabetIcon(email, 'dc__no-shrink m-0-imp')
55-
)}
56-
<div className="flexbox dc__gap-2">
57-
<Tooltip
58-
{...(tooltipContent
59-
? { content: email, alwaysShowTippyOnHover: false }
60-
: { content: email })}
61-
>
62-
<span className="cn-9 fs-13 fw-4 lh-20 dc__truncate">{isCurrentUser ? 'You' : email}</span>
63-
</Tooltip>
64-
{children}
65-
</div>
66-
</UserIdentifierTooltip>
67-
)}
62+
<UserIdentifierTooltip tooltipContent={tooltipContent}>
63+
{renderIcon()}
64+
<div className="flexbox dc__gap-2">
65+
<Tooltip
66+
{...(tooltipContent ? { content: email, alwaysShowTippyOnHover: false } : { content: email })}
67+
>
68+
<span className="cn-9 fs-13 fw-4 lh-20 dc__truncate">{renderText()}</span>
69+
</Tooltip>
70+
{children}
71+
</div>
72+
</UserIdentifierTooltip>
6873
</div>
6974
)
7075
}

0 commit comments

Comments
 (0)