Skip to content

Commit ac50070

Browse files
authored
fix: Add omitempty for proper latency type (#3850)
This was causing an error on the frontend, because this value can be nil!
1 parent 2e1db6c commit ac50070

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

codersdk/workspaceresources.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type WorkspaceAgent struct {
5959
Version string `json:"version"`
6060
Apps []WorkspaceApp `json:"apps"`
6161
// DERPLatency is mapped by region name (e.g. "New York City", "Seattle").
62-
DERPLatency map[string]DERPRegion `json:"latency"`
62+
DERPLatency map[string]DERPRegion `json:"latency,omitempty"`
6363
}
6464

6565
type WorkspaceAgentResourceMetadata struct {

site/src/api/typesGenerated.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ export interface WorkspaceAgent {
536536
readonly directory?: string
537537
readonly version: string
538538
readonly apps: WorkspaceApp[]
539-
readonly latency: Record<string, DERPRegion>
539+
readonly latency?: Record<string, DERPRegion>
540540
}
541541

542542
// From codersdk/workspaceagents.go

site/src/components/Resources/ResourceAgentLatency.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ export interface ResourceAgentLatencyProps {
1010

1111
export const ResourceAgentLatency: React.FC<ResourceAgentLatencyProps> = (props) => {
1212
const styles = useStyles()
13+
if (!props.latency) {
14+
return null
15+
}
1316
if (Object.keys(props.latency).length === 0) {
1417
return null
1518
}
19+
const latency = props.latency
1620
return (
1721
<div className={styles.root}>
1822
<div className={styles.title}>
@@ -24,10 +28,10 @@ export const ResourceAgentLatency: React.FC<ResourceAgentLatencyProps> = (props)
2428
</HelpTooltipText>
2529
</HelpTooltip>
2630
</div>
27-
{Object.keys(props.latency)
31+
{Object.keys(latency)
2832
.sort()
2933
.map((region) => {
30-
const value = props.latency[region]
34+
const value = latency[region]
3135
return (
3236
<div key={region} className={styles.region}>
3337
<b>{region}:</b>&nbsp;{Math.round(value.latency_ms * 100) / 100} ms

0 commit comments

Comments
 (0)