Skip to content

Commit a998574

Browse files
committed
fix: enhance build logs fetching and display logic
1 parent 93598ff commit a998574

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/features/dashboard/build/build-logs-store.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,14 @@ export const createBuildLogsStore = () =>
171171
const cursor =
172172
state.backwardsCursor ?? state.getOldestTimestamp() ?? Date.now()
173173

174-
const result = await state._trpcClient.builds.buildLogsBackwards.query(
175-
{
174+
const result =
175+
await state._trpcClient.builds.buildLogsBackwards.query({
176176
teamIdOrSlug: state._params.teamIdOrSlug,
177177
templateId: state._params.templateId,
178178
buildId: state._params.buildId,
179179
level: state.level ?? undefined,
180180
cursor,
181-
}
182-
)
181+
})
183182

184183
// Ignore stale response if init was called during fetch
185184
if (get()._initVersion !== requestVersion) {
@@ -207,11 +206,7 @@ export const createBuildLogsStore = () =>
207206
fetchMoreForwards: async () => {
208207
const state = get()
209208

210-
if (
211-
!state._trpcClient ||
212-
!state._params ||
213-
state.isLoadingForwards
214-
) {
209+
if (!state._trpcClient || !state._params || state.isLoadingForwards) {
215210
return { logsCount: 0 }
216211
}
217212

@@ -240,15 +235,18 @@ export const createBuildLogsStore = () =>
240235
return { logsCount: 0 }
241236
}
242237

238+
let uniqueLogsCount = 0
239+
243240
set((s) => {
244241
const uniqueNewLogs = deduplicateLogs(s.logs, result.logs)
245-
if (uniqueNewLogs.length > 0) {
242+
uniqueLogsCount = uniqueNewLogs.length
243+
if (uniqueLogsCount > 0) {
246244
s.logs = [...s.logs, ...uniqueNewLogs]
247245
}
248246
s.isLoadingForwards = false
249247
})
250248

251-
return { logsCount: result.logs.length }
249+
return { logsCount: uniqueLogsCount }
252250
} catch {
253251
if (get()._initVersion !== requestVersion) {
254252
return { logsCount: 0 }

src/features/dashboard/build/header-cells.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,24 @@ export function RanFor({
7373
? now - startedAt
7474
: (finishedAt ?? now) - startedAt
7575

76-
if (isBuilding) {
76+
// no timestamp to copy - just show duration
77+
if (isBuilding || !finishedAt) {
7778
return (
7879
<span className="whitespace-nowrap text-fg-tertiary">
7980
{formatDurationCompact(duration)}
8081
</span>
8182
)
8283
}
8384

84-
const iso = finishedAt ? new Date(finishedAt).toISOString() : null
85-
const formattedTimestamp = finishedAt ? formatCompactDate(finishedAt) : null
85+
const iso = new Date(finishedAt).toISOString()
86+
const formattedTimestamp = formatCompactDate(finishedAt)
8687

8788
return (
88-
<CopyButtonInline value={iso ?? ''} className="whitespace-nowrap group/time">
89+
<CopyButtonInline value={iso} className="whitespace-nowrap group/time">
8990
{formatDurationCompact(duration)}{' '}
90-
<span className="text-fg-tertiary group-hover/time:text-current transition-colors">· {formattedTimestamp}</span>
91+
<span className="text-fg-tertiary group-hover/time:text-current transition-colors">
92+
· {formattedTimestamp}
93+
</span>
9194
</CopyButtonInline>
9295
)
9396
}
@@ -100,7 +103,9 @@ export function StartedAt({ timestamp }: { timestamp: number }) {
100103
return (
101104
<CopyButtonInline value={iso} className="whitespace-nowrap group/time">
102105
{formatTimeAgoCompact(elapsed)}{' '}
103-
<span className="text-fg-tertiary group-hover/time:text-current transition-colors">· {formattedTimestamp}</span>
106+
<span className="text-fg-tertiary group-hover/time:text-current transition-colors">
107+
· {formattedTimestamp}
108+
</span>
104109
</CopyButtonInline>
105110
)
106111
}

0 commit comments

Comments
 (0)