Skip to content

Commit

Permalink
fix: [code-1991]: fix status icon for check section (harness#2123)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjlee01 authored and Harness committed Jun 18, 2024
1 parent 98bac50 commit a1b9512
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,69 @@ const ChecksSection = (props: ChecksSectionProps) => {

function generateStatusSummary(checks: TypeCheckData[]) {
// Initialize counts for each status
const statusCounts = { failed: 0, pending: 0, running: 0, succeeded: 0, total: checks?.length || 0 }
const statusCounts = {
failedReq: 0,
pendingReq: 0,
runningReq: 0,
successReq: 0,
failed: 0,
pending: 0,
running: 0,
succeeded: 0,
total: checks?.length || 0
}
if (isEmpty(checks)) {
return { message: '', summary: statusCounts }
}

// Count occurrences of each status
checks.forEach(check => {
const status = check.check.status
const required = check.required
if (status === CheckStatus.FAILURE || status === CheckStatus.ERROR) {
statusCounts.failed += 1
if (required) {
statusCounts.failedReq += 1
} else {
statusCounts.failed += 1
}
} else if (status === CheckStatus.PENDING) {
statusCounts.pending += 1
if (required) {
statusCounts.pendingReq += 1
} else {
statusCounts.pending += 1
}
} else if (status === CheckStatus.RUNNING) {
statusCounts.running += 1
if (required) {
statusCounts.runningReq += 1
} else {
statusCounts.running += 1
}
} else if (status === CheckStatus.SUCCESS) {
statusCounts.succeeded += 1
if (required) {
statusCounts.successReq += 1
} else {
statusCounts.succeeded += 1
}
}
})

// Format the summary string
const summaryParts = []
if (statusCounts.failed > 0) {
summaryParts.push(`${statusCounts.failed} failed`)
if (statusCounts.failed > 0 || statusCounts.failedReq) {
const num = statusCounts.failed + statusCounts.failedReq
summaryParts.push(`${num} failed`)
}
if (statusCounts.pending > 0) {
summaryParts.push(`${statusCounts.pending} pending`)
if (statusCounts.pending > 0 || statusCounts.pendingReq > 0) {
const num = statusCounts.pending + statusCounts.pendingReq
summaryParts.push(`${num} pending`)
}
if (statusCounts.running > 0) {
summaryParts.push(`${statusCounts.running} running`)
if (statusCounts.running > 0 || statusCounts.runningReq) {
const num = statusCounts.running + statusCounts.runningReq
summaryParts.push(`${num} running`)
}
if (statusCounts.succeeded > 0) {
summaryParts.push(`${statusCounts.succeeded} succeeded`)
if (statusCounts.succeeded > 0 || statusCounts.successReq) {
const num = statusCounts.succeeded + statusCounts.successReq
summaryParts.push(`${num} succeeded`)
}

return { message: summaryParts.join(', '), summary: statusCounts }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const StatusCircle = ({
summary: {
message: string
summary: {
failedReq: number
pendingReq: number
runningReq: number
successReq: number
failed: number
pending: number
running: number
Expand All @@ -40,7 +44,15 @@ const StatusCircle = ({
const { getString } = useStrings()
const data = summary.summary
const status =
data.failed > 0
data.failedReq > 0
? ExecutionState.FAILURE
: data.pendingReq > 0
? ExecutionState.PENDING
: data.runningReq > 0
? ExecutionState.RUNNING
: data.successReq > 0
? ExecutionState.SUCCESS
: data.failed > 0
? ExecutionState.FAILURE
: data.pending > 0
? ExecutionState.PENDING
Expand Down

0 comments on commit a1b9512

Please sign in to comment.