diff --git a/src/features/dashboard/sandbox/header/ran-for.tsx b/src/features/dashboard/sandbox/header/ran-for.tsx index 52ed9fa90..a587034ef 100644 --- a/src/features/dashboard/sandbox/header/ran-for.tsx +++ b/src/features/dashboard/sandbox/header/ran-for.tsx @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useSandboxContext } from '../context' +import { SANDBOX_LIFECYCLE_EVENT_RESUMED } from '../monitoring/utils/constants' export default function RanFor() { const { sandboxInfo, sandboxLifecycle, isRunning } = useSandboxContext() @@ -10,11 +11,23 @@ export default function RanFor() { const startedAt = sandboxLifecycle?.createdAt const pausedAt = sandboxLifecycle?.pausedAt const endedAt = sandboxLifecycle?.endedAt + const events = sandboxLifecycle?.events + + const lastResumedAt = useMemo(() => { + if (!events) return null + for (let i = events.length - 1; i >= 0; i--) { + const event = events[i] + if (event && event.type === SANDBOX_LIFECYCLE_EVENT_RESUMED) { + return event.timestamp + } + } + return null + }, [events]) - const startDate = useMemo( - () => (startedAt ? new Date(startedAt) : null), - [startedAt] - ) + const startDate = useMemo(() => { + const effectiveStart = lastResumedAt ?? startedAt + return effectiveStart ? new Date(effectiveStart) : null + }, [lastResumedAt, startedAt]) const pausedDate = useMemo( () => (pausedAt ? new Date(pausedAt) : null), [pausedAt]