Skip to content

Commit f06c017

Browse files
committed
refactor: update DEFAULT_CLUSTER_ID type and enhance workflow execution status handling in CICDHistory components
1 parent 062763e commit f06c017

File tree

4 files changed

+186
-83
lines changed

4 files changed

+186
-83
lines changed

src/Shared/Components/CICDHistory/TriggerOutput.tsx

Lines changed: 131 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
terminalStatus,
5959
History,
6060
HistoryLogsProps,
61+
WorkflowStageStatusType,
6162
} from './types'
6263
import { getTagDetails, getTriggerDetails, cancelCiTrigger, cancelPrePostCdTrigger } from './service'
6364
import { DEFAULT_CLUSTER_ID, DEFAULT_ENV, TIMEOUT_VALUE } from './constants'
@@ -72,19 +73,22 @@ import { ConfirmationModal, ConfirmationModalVariantType } from '../Confirmation
7273
import { getWorkerPodBaseUrl, sanitizeWorkflowExecutionStages } from './utils'
7374
import './cicdHistory.scss'
7475

75-
const Finished = React.memo(
76-
({ status, finishedOn, artifact, type }: FinishedType): JSX.Element => (
76+
const Finished = React.memo(({ status, finishedOn, artifact, type, executionInfo }: FinishedType): JSX.Element => {
77+
const finishedOnTime = executionInfo?.finishedOn || finishedOn
78+
const computedStatus = executionInfo?.currentStatus || status
79+
80+
return (
7781
<div className="flexbox pt-12 dc__gap-8 left dc__min-width-fit-content dc__align-items-center">
7882
<div
79-
className={`${status} fs-13 fw-6 ${TERMINAL_STATUS_COLOR_CLASS_MAP[status.toLowerCase()] || 'cn-5'}`}
83+
className={`${computedStatus} fs-13 fw-6 ${TERMINAL_STATUS_COLOR_CLASS_MAP[computedStatus.toLowerCase()] || 'cn-5'}`}
8084
data-testid="deployment-status-text"
8185
>
82-
{status && status.toLowerCase() === 'cancelled' ? 'Aborted' : status}
86+
{computedStatus && computedStatus.toLowerCase() === 'cancelled' ? 'Aborted' : computedStatus}
8387
</div>
8488

85-
{finishedOn && finishedOn !== ZERO_TIME_STRING && (
89+
{finishedOnTime && finishedOnTime !== ZERO_TIME_STRING && (
8690
<time className="dc__vertical-align-middle fs-13">
87-
{moment(finishedOn, 'YYYY-MM-DDTHH:mm:ssZ').format(DATE_TIME_FORMATS.TWELVE_HOURS_FORMAT)}
91+
{moment(finishedOnTime, 'YYYY-MM-DDTHH:mm:ssZ').format(DATE_TIME_FORMATS.TWELVE_HOURS_FORMAT)}
8892
</time>
8993
)}
9094

@@ -95,11 +99,19 @@ const Finished = React.memo(
9599
</>
96100
)}
97101
</div>
98-
),
99-
)
102+
)
103+
})
100104

101105
const WorkerStatus = React.memo(
102-
({ message, podStatus, stage, workerPodName, finishedOn, clusterId }: WorkerStatusType): JSX.Element | null => {
106+
({
107+
message,
108+
podStatus,
109+
stage,
110+
workerPodName,
111+
finishedOn,
112+
clusterId,
113+
namespace,
114+
}: WorkerStatusType): JSX.Element | null => {
103115
if (!message && !podStatus) {
104116
return null
105117
}
@@ -111,8 +123,7 @@ const WorkerStatus = React.memo(
111123
const getViewWorker = () =>
112124
showLink ? (
113125
<NavLink
114-
// TODO: Ask for namespace as well
115-
to={`${getWorkerPodBaseUrl(clusterId)}/${workerPodName}/logs`}
126+
to={`${getWorkerPodBaseUrl(clusterId, namespace)}/${workerPodName}/logs`}
116127
target="_blank"
117128
className="anchor"
118129
>
@@ -145,7 +156,7 @@ const WorkerStatus = React.memo(
145156
},
146157
)
147158

148-
const ProgressingStatus = React.memo(({ status, stage, type }: ProgressingStatusType): JSX.Element => {
159+
const ProgressingStatus = React.memo(({ stage, type }: ProgressingStatusType): JSX.Element => {
149160
const [aborting, setAborting] = useState(false)
150161
const [abortConfirmation, setAbortConfirmation] = useState(false)
151162
const [abortError, setAbortError] = useState<{
@@ -209,7 +220,7 @@ const ProgressingStatus = React.memo(({ status, stage, type }: ProgressingStatus
209220
<>
210221
<div className="flex dc__gap-8 left pt-12">
211222
<div className="dc__min-width-fit-content">
212-
<div className={`${status} fs-14 fw-6 flex left inprogress-status-color`}>In progress</div>
223+
<div className="fs-14 fw-6 flex left inprogress-status-color">In progress</div>
213224
</div>
214225

215226
{abort && (
@@ -278,12 +289,34 @@ const ProgressingStatus = React.memo(({ status, stage, type }: ProgressingStatus
278289
)
279290
})
280291

281-
const CurrentStatus = React.memo(({ status, finishedOn, artifact, stage, type }: CurrentStatusType): JSX.Element => {
282-
if (PROGRESSING_STATUS[status.toLowerCase()]) {
283-
return <ProgressingStatus status={status} stage={stage} type={type} />
284-
}
285-
return <Finished status={status} finishedOn={finishedOn} artifact={artifact} type={type} />
286-
})
292+
const CurrentStatus = React.memo(
293+
({ status, finishedOn, artifact, stage, type, executionInfo }: CurrentStatusType): JSX.Element => {
294+
if (executionInfo) {
295+
if (executionInfo.finishedOn) {
296+
return <Finished executionInfo={executionInfo} artifact={artifact} type={type} />
297+
}
298+
299+
if (executionInfo.currentStatus === WorkflowStageStatusType.RUNNING) {
300+
return <ProgressingStatus stage={stage} type={type} />
301+
}
302+
303+
if (executionInfo.currentStatus === WorkflowStageStatusType.UNKNOWN) {
304+
return (
305+
<div className="flex dc__gap-8 left pt-12">
306+
<span>Unknown status</span>
307+
</div>
308+
)
309+
}
310+
311+
return null
312+
}
313+
314+
if (PROGRESSING_STATUS[status.toLowerCase()]) {
315+
return <ProgressingStatus stage={stage} type={type} />
316+
}
317+
return <Finished status={status} finishedOn={finishedOn} artifact={artifact} type={type} />
318+
},
319+
)
287320

288321
const StartDetails = ({
289322
startedOn,
@@ -308,7 +341,7 @@ const StartDetails = ({
308341
<div className="flexbox dc__gap-8 dc__align-items-center pb-12 flex-wrap">
309342
<div className="flex left dc__gap-4 cn-9 fs-13 fw-6 lh-20">
310343
<div className="flex left dc__no-shrink dc__gap-4" data-testid="deployment-history-start-heading">
311-
<div>Start</div>
344+
<h3 className="m-0 cn-9 fs-13 fw-6 lh-20">Triggered</h3>
312345
{stage && (
313346
<>
314347
<div className="dc__bullet" />
@@ -394,16 +427,39 @@ const StartDetails = ({
394427
)
395428
}
396429

430+
const renderDetailsSuccessIconBlock = () => (
431+
<>
432+
<div className="flex">
433+
<ICSuccess className="icon-dim-20" />
434+
</div>
435+
436+
<div className="flex flex-grow-1">
437+
<div className="dc__border-left--n7 h-100" />
438+
</div>
439+
</>
440+
)
441+
397442
const TriggerDetailsStatusIcon = React.memo(
398-
({ status }: TriggerDetailsStatusIconType): JSX.Element => (
443+
({
444+
status,
445+
renderDeploymentHistoryTriggerMetaText,
446+
triggerMetadata,
447+
executionStartedOn,
448+
}: TriggerDetailsStatusIconType): JSX.Element => (
399449
<div className="flexbox-col">
400-
<div className="flex">
401-
<ICSuccess className="icon-dim-20" />
402-
</div>
450+
{renderDetailsSuccessIconBlock()}
403451

404-
<div className="flex flex-grow-1">
405-
<div className="dc__border-left--n7 h-100" />
406-
</div>
452+
{!!triggerMetadata && (
453+
<>
454+
{renderDeploymentHistoryTriggerMetaText?.(triggerMetadata, true)}
455+
456+
<div className="flex flex-grow-1">
457+
<div className="dc__border-left--n7 h-100" />
458+
</div>
459+
</>
460+
)}
461+
462+
{executionStartedOn && renderDetailsSuccessIconBlock()}
407463

408464
{PULSATING_STATUS_MAP[status] ? (
409465
<ICPulsateStatus />
@@ -446,6 +502,7 @@ export const TriggerDetails = React.memo(
446502
renderDeploymentHistoryTriggerMetaText,
447503
renderTargetConfigInfo,
448504
workflowExecutionStages,
505+
namespace,
449506
}: TriggerDetailsType) => {
450507
const executionInfo = useMemo(
451508
() => sanitizeWorkflowExecutionStages(workflowExecutionStages),
@@ -455,49 +512,62 @@ export const TriggerDetails = React.memo(
455512
return (
456513
<div className="trigger-details flexbox-col pb-12">
457514
<div className="display-grid trigger-details__grid py-12">
458-
{stage === DeploymentStageType.DEPLOY ? (
459-
<>
460-
<div className="flexbox dc__content-center">
461-
<TriggerDetailsStatusIcon status={status?.toLowerCase()} />
462-
</div>
463-
<div className="trigger-details__summary flexbox-col flex-grow-1 lh-20">
464-
<StartDetails
465-
startedOn={startedOn}
466-
triggeredBy={triggeredBy}
467-
triggeredByEmail={triggeredByEmail}
468-
ciMaterials={ciMaterials}
469-
gitTriggers={gitTriggers}
470-
artifact={artifact}
471-
type={type}
472-
environmentName={environmentName}
473-
isJobView={isJobView}
474-
triggerMetadata={triggerMetadata}
475-
renderDeploymentHistoryTriggerMetaText={renderDeploymentHistoryTriggerMetaText}
476-
renderTargetConfigInfo={renderTargetConfigInfo}
477-
stage={stage}
478-
/>
515+
<div className="flexbox dc__content-center">
516+
<TriggerDetailsStatusIcon
517+
status={status?.toLowerCase()}
518+
renderDeploymentHistoryTriggerMetaText={renderDeploymentHistoryTriggerMetaText}
519+
triggerMetadata={triggerMetadata}
520+
executionStartedOn={executionInfo?.executionStartedOn}
521+
/>
522+
</div>
523+
<div className="trigger-details__summary flexbox-col flex-grow-1 lh-20">
524+
<StartDetails
525+
startedOn={executionInfo?.triggeredOn ?? startedOn}
526+
triggeredBy={triggeredBy}
527+
triggeredByEmail={triggeredByEmail}
528+
ciMaterials={ciMaterials}
529+
gitTriggers={gitTriggers}
530+
artifact={artifact}
531+
type={type}
532+
environmentName={environmentName}
533+
isJobView={isJobView}
534+
triggerMetadata={triggerMetadata}
535+
renderDeploymentHistoryTriggerMetaText={renderDeploymentHistoryTriggerMetaText}
536+
renderTargetConfigInfo={renderTargetConfigInfo}
537+
stage={stage}
538+
/>
479539

480-
<CurrentStatus
481-
status={status}
482-
finishedOn={finishedOn}
483-
artifact={artifact}
484-
stage={stage}
485-
type={type}
486-
/>
540+
{executionInfo?.executionStartedOn && (
541+
<div className="w-100 pr-20 flexbox dc__gap-8">
542+
<h3 className="m-0 cn-9 fs-13 fw-6 lh-20">Execution started</h3>
543+
544+
<time className="cn-7 fs-13">
545+
{moment(startedOn, 'YYYY-MM-DDTHH:mm:ssZ').format(
546+
DATE_TIME_FORMATS.TWELVE_HOURS_FORMAT,
547+
)}
548+
</time>
487549
</div>
488-
</>
489-
) : (
490-
<div />
491-
)}
550+
)}
551+
552+
<CurrentStatus
553+
executionInfo={executionInfo}
554+
status={status}
555+
finishedOn={finishedOn}
556+
artifact={artifact}
557+
stage={stage}
558+
type={type}
559+
/>
560+
</div>
492561
</div>
493562

494563
<WorkerStatus
495564
message={executionInfo?.workerDetails?.message ?? message}
496565
podStatus={executionInfo?.workerDetails?.status ?? podStatus}
497566
stage={stage}
498567
finishedOn={executionInfo?.workerDetails?.endTime ?? finishedOn}
499-
clusterId={executionInfo?.workerDetails?.clusterId || +DEFAULT_CLUSTER_ID}
568+
clusterId={executionInfo?.workerDetails?.clusterId || DEFAULT_CLUSTER_ID}
500569
workerPodName={workerPodName}
570+
namespace={namespace}
501571
/>
502572
</div>
503573
)
@@ -858,6 +928,7 @@ const TriggerOutput = ({
858928
environmentName={selectedEnvironmentName}
859929
renderTargetConfigInfo={renderTargetConfigInfo}
860930
workflowExecutionStages={triggerDetails.workflowExecutionStages}
931+
namespace={triggerDetails.namespace}
861932
/>
862933
<ul className="pl-50 pr-20 pt-8 tab-list tab-list--nodes dc__border-bottom dc__position-sticky dc__top-0 bg__primary dc__zi-3">
863934
{triggerDetails.stage === 'DEPLOY' && deploymentAppType !== DeploymentAppTypes.HELM && (

src/Shared/Components/CICDHistory/constants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const POD_STATUS = {
6969

7070
export const TIMEOUT_VALUE = '1' // in hours
7171

72-
export const DEFAULT_CLUSTER_ID = '1'
72+
export const DEFAULT_CLUSTER_ID = 1
7373

7474
export const DEFAULT_ENV = 'devtron-ci'
7575

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ export enum WorkflowStageStatusType {
125125
FAILED = 'FAILED',
126126
ABORTED = 'ABORTED',
127127
TIMEOUT = 'TIMEOUT',
128-
/**
129-
* UI Enum
130-
*/
131128
UNKNOWN = 'UNKNOWN',
132129
}
133130

@@ -216,7 +213,7 @@ export interface ExecutionInfoType {
216213
*/
217214
currentStatus: WorkflowStageStatusType
218215
workerDetails: Pick<PodExecutionStageDTO, 'message' | 'status' | 'endTime'> &
219-
Pick<PodExecutionStageDTO['metadata'], 'clusterId' | 'podName'>
216+
Pick<PodExecutionStageDTO['metadata'], 'clusterId'>
220217
}
221218

222219
export interface DeploymentHistoryResultObject {
@@ -286,6 +283,7 @@ export interface CurrentStatusType {
286283
artifact: string
287284
stage: DeploymentStageType
288285
type: HistoryComponentType
286+
executionInfo: ExecutionInfoType
289287
}
290288

291289
export interface StartDetailsType {
@@ -309,7 +307,7 @@ export interface StartDetailsType {
309307

310308
export interface TriggerDetailsType
311309
extends Pick<StartDetailsType, 'renderTargetConfigInfo'>,
312-
Pick<History, 'workflowExecutionStages'> {
310+
Pick<History, 'workflowExecutionStages' | 'namespace'> {
313311
status: string
314312
startedOn: string
315313
finishedOn: string
@@ -326,31 +324,40 @@ export interface TriggerDetailsType
326324
isJobView?: boolean
327325
workerPodName?: string
328326
triggerMetadata?: string
329-
renderDeploymentHistoryTriggerMetaText: (triggerMetaData: string) => JSX.Element
327+
renderDeploymentHistoryTriggerMetaText: (triggerMetaData: string, onlyRenderIcon?: boolean) => JSX.Element
330328
}
331329

332-
export interface ProgressingStatusType {
333-
status: string
330+
export type ProgressingStatusType = {
334331
stage: DeploymentStageType
335332
type: HistoryComponentType
336333
}
337334

338-
export interface WorkerStatusType extends Pick<ExecutionInfoType['workerDetails'], 'clusterId'> {
335+
export interface WorkerStatusType
336+
extends Pick<ExecutionInfoType['workerDetails'], 'clusterId'>,
337+
Pick<TriggerDetailsType, 'namespace'> {
339338
message: string
340339
podStatus: string
341340
stage: DeploymentStageType
342341
finishedOn?: string
343342
workerPodName?: string
344343
}
345344

346-
export interface FinishedType {
347-
status: string
348-
finishedOn: string
349-
artifact: string
350-
type: HistoryComponentType
351-
}
345+
export type FinishedType = { artifact: string; type: HistoryComponentType } & (
346+
| {
347+
status: string
348+
finishedOn: string
349+
executionInfo?: never
350+
}
351+
| {
352+
executionInfo: ExecutionInfoType
353+
status?: never
354+
finishedOn?: never
355+
}
356+
)
352357

353-
export interface TriggerDetailsStatusIconType {
358+
export interface TriggerDetailsStatusIconType
359+
extends Pick<TriggerDetailsType, 'renderDeploymentHistoryTriggerMetaText' | 'triggerMetadata'>,
360+
Pick<ExecutionInfoType, 'executionStartedOn'> {
354361
status: string
355362
}
356363

0 commit comments

Comments
 (0)