Skip to content

Commit 4fff346

Browse files
Merge pull request #224 from devtron-labs/fix/log-stage-time-status
fix: log stage time status
2 parents 1b39f14 + 39d2d78 commit 4fff346

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.1.11",
3+
"version": "0.1.11-beta-2",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Shared/Components/CICDHistory/LogStageAccordion.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const LogStageAccordion = ({
2828
}
2929
}
3030

31+
const getFormattedTimeDifference = (): string => {
32+
const timeDifference = getTimeDifference(startTime, endTime)
33+
if (timeDifference === '0s') {
34+
return '< 1s'
35+
}
36+
return timeDifference
37+
}
38+
3139
return (
3240
<div className="flexbox-col dc__gap-8">
3341
<button
@@ -50,7 +58,7 @@ const LogStageAccordion = ({
5058
</div>
5159
</div>
5260

53-
{!!endTime && <span className="cn-0 fs-13 fw-4 lh-20">{getTimeDifference(startTime, endTime)}</span>}
61+
{!!endTime && <span className="cn-0 fs-13 fw-4 lh-20">{getFormattedTimeDifference()}</span>}
5462
</button>
5563

5664
{isOpen && (

src/Shared/Components/CICDHistory/LogsRenderer.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ export const LogsRenderer = ({
256256
return lastActionState
257257
}
258258

259+
const areEventsProgressing =
260+
triggerDetails.podStatus === POD_STATUS.PENDING || !!(eventSource && eventSource.readyState <= 1)
261+
259262
/**
260263
* If initially parsedLogs are empty, and initialStatus is Success then would set opened as false on each
261264
* If initialStatus is not success and initial parsedLogs are empty then would set opened as false on each except the last
@@ -297,19 +300,23 @@ export const LogsRenderer = ({
297300
!!targetSearchKey,
298301
)
299302
} else {
303+
const derivedStatus: StageStatusType = areEventsProgressing
304+
? StageStatusType.PROGRESSING
305+
: StageStatusType.FAILURE
306+
300307
acc.push({
301308
stage: stage || `Untitled stage ${index + 1}`,
302309
startTime: startTime || '',
303310
endTime: endTime || '',
304311
// Would be defining the state when we receive the end status, otherwise it is loading and would be open
305312
isOpen: getIsStageOpen(
306-
StageStatusType.PROGRESSING,
313+
derivedStatus,
307314
previousExistingStage.isOpen,
308315
// Wont be present in case of start stage since no logs are present yet
309316
!!searchKeyStatusMap[stage]?.[startTime],
310317
!!targetSearchKey,
311318
),
312-
status: StageStatusType.PROGRESSING,
319+
status: derivedStatus,
313320
logs: [],
314321
})
315322
}
@@ -363,7 +370,7 @@ export const LogsRenderer = ({
363370
setStageList(newStageList)
364371
// NOTE: Not adding searchKey as dependency since on mount we would already have searchKey
365372
// And for other cases we would use handleSearchEnter
366-
}, [streamDataList])
373+
}, [streamDataList, areEventsProgressing])
367374

368375
const handleSearchEnter = (searchText: string) => {
369376
handleSearch(searchText)
@@ -383,9 +390,6 @@ export const LogsRenderer = ({
383390
setStageList(newLogs)
384391
}
385392

386-
const areEventsProgressing =
387-
triggerDetails.podStatus === POD_STATUS.PENDING || (eventSource && eventSource.readyState <= 1)
388-
389393
const renderLogs = () => {
390394
if (areStagesAvailable) {
391395
return (

src/Shared/Helpers.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,16 @@ export const getTimeDifference = (startTime: string, endTime: string): string =>
717717
}
718718

719719
const seconds = moment(endTime).diff(moment(startTime), 'seconds')
720-
const minutes = moment(endTime).diff(moment(startTime), 'minutes') % 60
721-
const hours = moment(endTime).diff(moment(startTime), 'hours', true).toFixed(2)
720+
const minutes = moment(endTime).diff(moment(startTime), 'minutes')
721+
const hours = moment(endTime).diff(moment(startTime), 'hours')
722+
722723
if (seconds < 60) {
723724
return `${seconds}s`
724725
}
725726
if (minutes < 60) {
726727
return `${minutes}m ${seconds % 60}s`
727728
}
728-
return `${hours}h ${minutes % 60}m ${seconds % 60}s`
729+
const leftOverMinutes = minutes - hours * 60
730+
const leftOverSeconds = seconds - minutes * 60
731+
return `${hours}h ${leftOverMinutes}m ${leftOverSeconds}s`
729732
}

0 commit comments

Comments
 (0)