File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed
modules/workspaces/WorkspaceTiming Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ import type {
9
9
AgentScriptTiming ,
10
10
ProvisionerTiming ,
11
11
} from "api/typesGenerated" ;
12
- import sortBy from "lodash/sortBy" ;
13
- import uniqBy from "lodash/uniqBy" ;
14
12
import { type FC , useState } from "react" ;
15
13
import { type TimeRange , calcDuration , mergeTimeRanges } from "./Chart/utils" ;
16
14
import { ResourcesChart , isCoderResource } from "./ResourcesChart" ;
@@ -44,16 +42,9 @@ export const WorkspaceTimings: FC<WorkspaceTimingsProps> = ({
44
42
defaultIsOpen = false ,
45
43
} ) => {
46
44
const [ view , setView ] = useState < TimingView > ( { name : "default" } ) ;
47
- // This is a workaround to deal with the BE returning multiple timings for a
48
- // single agent script when it should return only one. Reference:
49
- // https://github.com/coder/coder/issues/15413#issuecomment-2493663571
50
- const uniqScriptTimings = uniqBy (
51
- sortBy ( agentScriptTimings , ( t ) => new Date ( t . started_at ) . getTime ( ) * - 1 ) ,
52
- ( t ) => t . display_name ,
53
- ) ;
54
45
const timings = [
55
46
...provisionerTimings ,
56
- ...uniqScriptTimings ,
47
+ ...agentScriptTimings ,
57
48
...agentConnectionTimings ,
58
49
] . sort ( ( a , b ) => {
59
50
return new Date ( a . started_at ) . getTime ( ) - new Date ( b . started_at ) . getTime ( ) ;
Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog";
37
37
import { Workspace } from "./Workspace" ;
38
38
import { WorkspaceDeleteDialog } from "./WorkspaceDeleteDialog" ;
39
39
import type { WorkspacePermissions } from "./permissions" ;
40
+ import sortBy from "lodash/sortBy" ;
41
+ import uniqBy from "lodash/uniqBy" ;
40
42
41
43
interface WorkspaceReadyPageProps {
42
44
template : TypesGen . Template ;
@@ -163,6 +165,21 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
163
165
// Fetch build timings only when the build job is completed.
164
166
enabled : Boolean ( workspace . latest_build . job . completed_at ) ,
165
167
168
+ // This is a workaround to deal with the BE returning multiple timings for a
169
+ // single agent script when it should return only one. Reference:
170
+ // https://github.com/coder/coder/issues/15413#issuecomment-2493663571
171
+ select : ( data ) => {
172
+ return {
173
+ ...data ,
174
+ agent_script_timings : uniqBy (
175
+ sortBy ( data . agent_script_timings , ( t ) =>
176
+ new Date ( t . started_at ) . getTime ( ) ,
177
+ ) ,
178
+ ( t ) => t . display_name ,
179
+ ) ,
180
+ } ;
181
+ } ,
182
+
166
183
// Sometimes, the timings can be fetched before the agent script timings are
167
184
// done or saved in the database so we need to conditionally refetch the
168
185
// timings. To refetch the timings, I found the best way was to compare the
You can’t perform that action at this time.
0 commit comments