-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAppStatusBody.tsx
More file actions
199 lines (185 loc) · 8.42 KB
/
AppStatusBody.tsx
File metadata and controls
199 lines (185 loc) · 8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { ComponentProps } from 'react'
import { getAIAnalyticsEvents } from '@Common/Helper'
import { Tooltip } from '@Common/Tooltip'
import { ComponentSizeType } from '@Shared/constants'
import { getAppDetailsURL } from '@Shared/Helpers'
import { Button, ButtonComponentType, ButtonVariantType } from '../Button'
import { DeploymentStatusDetailBreakdown } from '../CICDHistory'
import { DEPLOYMENT_STATUS_TEXT_MAP } from '../DeploymentStatusBreakdown'
import { ErrorBar } from '../Error'
import { Icon } from '../Icon'
import { ShowMoreText } from '../ShowMoreText'
import { AppStatus, DeploymentStatus, StatusType } from '../StatusComponent'
import AppStatusContent from './AppStatusContent'
import { APP_STATUS_CUSTOM_MESSAGES } from './constants'
import { AppStatusBodyProps, AppStatusModalTabType, InfoCardItemProps, StatusHeadingContainerProps } from './types'
import { getAppStatusMessageFromAppDetails } from './utils'
const InfoCardItem = ({ heading, value, isLast = false, alignCenter = false }: InfoCardItemProps) => (
<div
className={`py-12 px-16 dc__grid dc__column-gap-16 info-card-item ${alignCenter ? 'dc__align-items-center' : ''} ${!isLast ? 'border__secondary--bottom' : ''}`}
>
<Tooltip content={heading}>
<h3 className="cn-9 fs-13 fw-4 lh-1-5 dc__truncate m-0 dc__no-shrink">{heading}</h3>
</Tooltip>
{typeof value === 'string' ? (
<ShowMoreText
key={`show-more-text-${value}`}
containerClass="mw-720 pr-20"
textClass="cn-9 fs-13 fw-4 lh-1-5"
text={value}
/>
) : (
value
)}
</div>
)
const StatusHeadingContainer = ({ children, type, appId, envId, actionItem }: StatusHeadingContainerProps) => (
<div className="flexbox dc__content-space w-100">
{children}
<div className="flexbox dc__align-items-center dc__gap-8">
{actionItem}
{type === 'release' ? (
<Button
dataTestId="visit-app-details"
component={ButtonComponentType.link}
variant={ButtonVariantType.secondary}
size={ComponentSizeType.xs}
endIcon={<Icon name="ic-arrow-square-out" color={null} />}
text="Visit app"
linkProps={{
to: getAppDetailsURL(appId, envId),
target: '_blank',
rel: 'noopener noreferrer',
}}
/>
) : null}
</div>
</div>
)
export const AppStatusBody = ({
appDetails,
type,
handleShowConfigDriftModal,
deploymentStatusDetailsBreakdownData,
selectedTab,
debugWithAIButton: ExplainWithAIButton,
}: AppStatusBodyProps) => {
const appStatus = appDetails.resourceTree?.status?.toUpperCase() || appDetails.appStatus
const getAppStatusInfoCardItems = (): (Omit<ComponentProps<typeof InfoCardItem>, 'isLast'> & { id: string })[] => {
const message = getAppStatusMessageFromAppDetails(appDetails)
const customMessage =
type === 'stack-manager'
? 'The installation will complete when status for all the below resources become HEALTHY.'
: APP_STATUS_CUSTOM_MESSAGES[appStatus]
const debugNode = appDetails.resourceTree?.nodes?.find(
(node) => node.kind === 'Deployment' || node.kind === 'Rollout',
)
const debugObject = `${debugNode?.kind}/${debugNode?.name}`
return [
{
id: 'app-status-row',
heading: type !== 'stack-manager' ? 'Application Status' : 'Status',
value: (
<StatusHeadingContainer
type={type}
appId={appDetails.appId}
envId={appDetails.environmentId}
actionItem={
ExplainWithAIButton &&
appStatus?.toLowerCase() !== StatusType.HEALTHY.toLowerCase() &&
(debugNode || message) ? (
<ExplainWithAIButton
intelligenceConfig={{
clusterId: appDetails.clusterId,
metadata: {
...(debugNode ? { object: debugObject } : { message }),
namespace: appDetails.namespace,
status: debugNode?.health?.status ?? appStatus,
},
prompt: `Debug ${message || 'error'} ${debugNode ? `of ${debugObject}` : ''} in ${appDetails.namespace}`,
analyticsCategory: getAIAnalyticsEvents('APP_STATUS', appDetails.appType),
}}
/>
) : null
}
>
{appStatus ? <AppStatus status={appStatus} showAnimatedIcon /> : '--'}
</StatusHeadingContainer>
),
},
...(message
? [
{
id: 'app-status-primary-message',
heading: 'Message',
value: message,
},
]
: []),
...(customMessage
? [
{
id: 'app-status-secondary-message',
heading: 'Message',
value: customMessage,
},
]
: []),
]
}
const infoCardItems: ReturnType<typeof getAppStatusInfoCardItems> =
selectedTab === AppStatusModalTabType.APP_STATUS
? getAppStatusInfoCardItems()
: [
{
id: 'deployment-status-row',
heading: 'Deployment Status',
value: (
<StatusHeadingContainer type={type} appId={appDetails.appId} envId={appDetails.environmentId}>
{deploymentStatusDetailsBreakdownData?.deploymentStatus ? (
<DeploymentStatus
status={deploymentStatusDetailsBreakdownData.deploymentStatus}
message={
DEPLOYMENT_STATUS_TEXT_MAP[
deploymentStatusDetailsBreakdownData.deploymentStatus
]
}
showAnimatedIcon
/>
) : (
'--'
)}
</StatusHeadingContainer>
),
},
]
return (
<div className="flexbox-col px-20 dc__gap-16 dc__overflow-auto">
{/* Info card */}
<div className="flexbox-col pt-20">
<div className="flexbox-col br-8 border__primary bg__primary shadow__card--secondary">
{infoCardItems.map((item, index) => (
<InfoCardItem
key={item.id}
heading={item.heading}
value={item.value}
isLast={index === infoCardItems.length - 1}
alignCenter={item.heading !== 'Message'}
/>
))}
</div>
</div>
<ErrorBar appDetails={appDetails} useParentMargin={false} />
{selectedTab === AppStatusModalTabType.APP_STATUS ? (
<AppStatusContent appDetails={appDetails} handleShowConfigDriftModal={handleShowConfigDriftModal} />
) : (
<DeploymentStatusDetailBreakdown
deploymentStatusDetailsBreakdownData={deploymentStatusDetailsBreakdownData}
isVirtualEnvironment={appDetails.isVirtualEnvironment}
appDetails={appDetails}
rootClassName="pb-20"
/>
)}
</div>
)
}