Skip to content

Commit 58141a2

Browse files
committed
refactor: optimize RegistryIcon component and enhance AppStatus rendering logic
1 parent 4f5be7f commit 58141a2

File tree

3 files changed

+48
-54
lines changed

3 files changed

+48
-54
lines changed

src/Shared/Components/RegistryIcon/RegistryIcon.tsx

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,21 @@ import { RegistryType } from '@Shared/types'
33
import { Icon, IconName } from '../Icon'
44
import { RegistryIconProps } from './types'
55

6-
const getRegistryIcon = (registryType: RegistryType): IconName => {
7-
switch (registryType) {
8-
case RegistryType.GIT:
9-
return 'ic-git'
10-
case RegistryType.GITHUB:
11-
return 'ic-github'
12-
case RegistryType.GITLAB:
13-
return 'ic-gitlab'
14-
case RegistryType.BITBUCKET:
15-
return 'ic-bitbucket'
16-
case RegistryType.DOCKER:
17-
case RegistryType.DOCKER_HUB:
18-
return 'ic-dockerhub'
19-
case RegistryType.ACR:
20-
return 'ic-azure'
21-
case RegistryType.QUAY:
22-
return 'ic-quay'
23-
case RegistryType.ECR:
24-
return 'ic-ecr'
25-
case RegistryType.ARTIFACT_REGISTRY:
26-
return 'ic-google-artifact-registry'
27-
case RegistryType.GCR:
28-
return 'ic-google-container-registry'
29-
default:
30-
return 'ic-container'
31-
}
6+
const registryIconMap: Record<RegistryType, IconName> = {
7+
[RegistryType.GIT]: 'ic-git',
8+
[RegistryType.GITHUB]: 'ic-github',
9+
[RegistryType.GITLAB]: 'ic-gitlab',
10+
[RegistryType.BITBUCKET]: 'ic-bitbucket',
11+
[RegistryType.DOCKER]: 'ic-dockerhub',
12+
[RegistryType.DOCKER_HUB]: 'ic-dockerhub',
13+
[RegistryType.ACR]: 'ic-azure',
14+
[RegistryType.QUAY]: 'ic-quay',
15+
[RegistryType.ECR]: 'ic-ecr',
16+
[RegistryType.ARTIFACT_REGISTRY]: 'ic-google-artifact-registry',
17+
[RegistryType.GCR]: 'ic-google-container-registry',
18+
[RegistryType.OTHER]: 'ic-container',
3219
}
3320

3421
export const RegistryIcon = ({ registryType, size = 20 }: RegistryIconProps) => (
35-
<Icon name={getRegistryIcon(registryType)} size={size} color={null} />
22+
<Icon name={registryIconMap[registryType] || 'ic-container'} size={size} color={null} />
3623
)

src/Shared/Components/StatusComponent/AppStatus.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Icon } from '../Icon'
1718
import { AppStatusProps } from './types'
1819
import { StatusComponent } from './StatusComponent'
1920
import { APP_STATUS } from './constants'
@@ -26,5 +27,21 @@ export const AppStatus = ({ status, isJobView = false, isVirtualEnv = false, ...
2627
const notDeployedMessage = isJobView ? APP_STATUS.JOB_VIEW_NOT_DEPLOYED_MESSAGE : APP_STATUS.NOT_DEPLOYED_MESSAGE
2728
const textContent = isNotDeployed ? notDeployedMessage : appStatus
2829

29-
return <StatusComponent status={appStatus} message={textContent} {...restProps} />
30+
return appStatus ? (
31+
<StatusComponent status={appStatus} message={textContent} {...restProps} />
32+
) : (
33+
<div className="flexbox dc__align-items-center dc__gap-6">
34+
<Icon
35+
name="ic-info-outline"
36+
size={restProps.iconSize}
37+
tooltipProps={{
38+
alwaysShowTippyOnHover: true,
39+
placement: 'top',
40+
content: 'To fetch app status for Helm based deployments open the app detail page',
41+
}}
42+
color="N600"
43+
/>
44+
<span className="fs-13 lh-20 cn-6">-</span>
45+
</div>
46+
)
3047
}

src/Shared/Components/StatusComponent/StatusComponent.tsx

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export const StatusComponent = ({
3434
hideIconTooltip = false,
3535
message,
3636
}: StatusComponentProps) => {
37-
const appStatusLowerCase = (status || '').toLowerCase().replace(/ /g, '-')
38-
const textContent = message || status || '-'
37+
const statusLowercase = (status || '').toLowerCase().replace(/ /g, '-')
38+
const textContent = message || status || ''
3939

4040
const renderIcon = () => {
41-
const iconName = getIconName(appStatusLowerCase, showAnimatedIcon)
42-
const iconColor = getIconColor(appStatusLowerCase)
41+
const iconName = getIconName(statusLowercase, showAnimatedIcon)
42+
const iconColor = getIconColor(statusLowercase)
4343

4444
if (iconName) {
4545
return (
@@ -56,30 +56,20 @@ export const StatusComponent = ({
5656
)
5757
}
5858

59-
return (
60-
<Icon
61-
name="ic-info-outline"
62-
size={iconSize}
63-
tooltipProps={{
64-
alwaysShowTippyOnHover: true,
65-
placement: 'top',
66-
content: 'To fetch app status for Helm based deployments open the app detail page',
67-
}}
68-
color="N600"
69-
/>
70-
)
59+
return null
7160
}
7261

73-
const renderMessage = () => (
74-
<Tooltip content={textContent}>
75-
<p
76-
data-testid={`${status || 'status-is-null'}-status`}
77-
className="m-0 dc__ellipsis-right dc__first-letter-capitalize fs-13 lh-20 cn-6"
78-
>
79-
{textContent}
80-
</p>
81-
</Tooltip>
82-
)
62+
const renderMessage = () =>
63+
textContent ? (
64+
<Tooltip content={textContent}>
65+
<p
66+
data-testid={`${status || 'status-is-null'}-status`}
67+
className="m-0 dc__ellipsis-right dc__first-letter-capitalize fs-13 lh-20 cn-6"
68+
>
69+
{textContent}
70+
</p>
71+
</Tooltip>
72+
) : null
8373

8474
return (
8575
<ConditionalWrap condition={!hideIcon && !hideMessage} wrap={statusWrapComponent}>

0 commit comments

Comments
 (0)