File tree 5 files changed +141
-2
lines changed
5 files changed +141
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,15 @@ module.exports = {
14
14
// addons are official and community plugins to extend Storybook.
15
15
//
16
16
// SEE: https://storybook.js.org/addons
17
- addons : [ "@storybook/addon-links" , "@storybook/addon-essentials" ] ,
17
+ addons : [
18
+ "@storybook/addon-links" ,
19
+ {
20
+ name : "@storybook/addon-essentials" ,
21
+ options : {
22
+ actions : false ,
23
+ } ,
24
+ } ,
25
+ ] ,
18
26
19
27
// Storybook uses babel under the hood, while we currently use ts-loader.
20
28
// Sometimes, you may encounter an error in a Storybook that contains syntax
Original file line number Diff line number Diff line change
1
+ import { Story } from "@storybook/react"
2
+ import { ResourceAgentLatency , ResourceAgentLatencyProps } from "./ResourceAgentLatency"
3
+
4
+ export default {
5
+ title : "components/ResourceAgentLatency" ,
6
+ component : ResourceAgentLatency ,
7
+ }
8
+
9
+ const Template : Story < ResourceAgentLatencyProps > = ( args ) => < ResourceAgentLatency { ...args } />
10
+
11
+ export const Single = Template . bind ( { } )
12
+ Single . args = {
13
+ latency : {
14
+ "Coder DERP" : {
15
+ latency_ms : 100.52 ,
16
+ preferred : true ,
17
+ } ,
18
+ } ,
19
+ }
20
+
21
+ export const Multiple = Template . bind ( { } )
22
+ Multiple . args = {
23
+ latency : {
24
+ Chicago : {
25
+ latency_ms : 22.25551 ,
26
+ preferred : false ,
27
+ } ,
28
+ "New York" : {
29
+ latency_ms : 56.1111 ,
30
+ preferred : true ,
31
+ } ,
32
+ "San Francisco" : {
33
+ latency_ms : 125.11 ,
34
+ preferred : false ,
35
+ } ,
36
+ Tokyo : {
37
+ latency_ms : 255 ,
38
+ preferred : false ,
39
+ } ,
40
+ } ,
41
+ }
Original file line number Diff line number Diff line change
1
+ import { makeStyles } from "@material-ui/core/styles"
2
+ import StarIcon from "@material-ui/icons/Star"
3
+ import React from "react"
4
+ import { WorkspaceAgent } from "../../api/typesGenerated"
5
+ import { HelpTooltip , HelpTooltipText } from "../Tooltips/HelpTooltip"
6
+
7
+ export interface ResourceAgentLatencyProps {
8
+ latency : WorkspaceAgent [ "latency" ]
9
+ }
10
+
11
+ export const ResourceAgentLatency : React . FC < ResourceAgentLatencyProps > = ( props ) => {
12
+ const styles = useStyles ( )
13
+ if ( Object . keys ( props . latency ) . length === 0 ) {
14
+ return null
15
+ }
16
+ return (
17
+ < div className = { styles . root } >
18
+ < div className = { styles . title } >
19
+ < b > Latency</ b >
20
+ < HelpTooltip size = "small" >
21
+ < HelpTooltipText >
22
+ Latency from relay servers, used when connections cannot connect peer-to-peer. Star
23
+ indicates the preferred relay.
24
+ </ HelpTooltipText >
25
+ </ HelpTooltip >
26
+ </ div >
27
+ { Object . keys ( props . latency )
28
+ . sort ( )
29
+ . map ( ( region ) => {
30
+ const value = props . latency [ region ]
31
+ return (
32
+ < div key = { region } className = { styles . region } >
33
+ < b > { region } :</ b > { Math . round ( value . latency_ms * 100 ) / 100 } ms
34
+ { value . preferred && < StarIcon className = { styles . star } /> }
35
+ </ div >
36
+ )
37
+ } ) }
38
+ </ div >
39
+ )
40
+ }
41
+
42
+ const useStyles = makeStyles ( ( ) => ( {
43
+ root : {
44
+ display : "grid" ,
45
+ gap : 6 ,
46
+ } ,
47
+ title : {
48
+ fontSize : "Something" ,
49
+ display : "flex" ,
50
+ alignItems : "center" ,
51
+ // This ensures that the latency aligns with other columns in the grid.
52
+ height : 20 ,
53
+ } ,
54
+ region : {
55
+ display : "flex" ,
56
+ alignItems : "center" ,
57
+ } ,
58
+ star : {
59
+ width : 14 ,
60
+ height : 14 ,
61
+ marginLeft : 4 ,
62
+ } ,
63
+ } ) )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { TerminalLink } from "../TerminalLink/TerminalLink"
20
20
import { AgentHelpTooltip } from "../Tooltips/AgentHelpTooltip"
21
21
import { AgentOutdatedTooltip } from "../Tooltips/AgentOutdatedTooltip"
22
22
import { ResourcesHelpTooltip } from "../Tooltips/ResourcesHelpTooltip"
23
+ import { ResourceAgentLatency } from "./ResourceAgentLatency"
23
24
import { ResourceAvatarData } from "./ResourceAvatarData"
24
25
25
26
const Language = {
@@ -129,6 +130,9 @@ export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
129
130
< span className = { styles . agentVersion } > { displayVersion } </ span >
130
131
< AgentOutdatedTooltip outdated = { outdated } />
131
132
</ div >
133
+ < div className = { styles . dataRow } >
134
+ < ResourceAgentLatency latency = { agent . latency } />
135
+ </ div >
132
136
</ div >
133
137
</ TableCell >
134
138
< TableCell >
@@ -232,6 +236,7 @@ const useStyles = makeStyles((theme) => ({
232
236
gridAutoFlow : "row" ,
233
237
whiteSpace : "nowrap" ,
234
238
gap : theme . spacing ( 0.75 ) ,
239
+ height : "fit-content" ,
235
240
} ,
236
241
237
242
dataRow : {
Original file line number Diff line number Diff line change @@ -311,7 +311,12 @@ export const MockWorkspaceAgent: TypesGen.WorkspaceAgent = {
311
311
status : "connected" ,
312
312
updated_at : "" ,
313
313
version : MockBuildInfo . version ,
314
- latency : { } ,
314
+ latency : {
315
+ "Coder Embedded DERP" : {
316
+ latency_ms : 32.55 ,
317
+ preferred : true ,
318
+ } ,
319
+ } ,
315
320
}
316
321
317
322
export const MockWorkspaceAgentDisconnected : TypesGen . WorkspaceAgent = {
@@ -320,6 +325,7 @@ export const MockWorkspaceAgentDisconnected: TypesGen.WorkspaceAgent = {
320
325
name : "another-workspace-agent" ,
321
326
status : "disconnected" ,
322
327
version : "" ,
328
+ latency : { } ,
323
329
}
324
330
325
331
export const MockWorkspaceAgentOutdated : TypesGen . WorkspaceAgent = {
@@ -328,6 +334,21 @@ export const MockWorkspaceAgentOutdated: TypesGen.WorkspaceAgent = {
328
334
name : "an-outdated-workspace-agent" ,
329
335
version : "v99.999.9998+abcdef" ,
330
336
operating_system : "Windows" ,
337
+ latency : {
338
+ ...MockWorkspaceAgent . latency ,
339
+ Chicago : {
340
+ preferred : false ,
341
+ latency_ms : 95.11 ,
342
+ } ,
343
+ "San Francisco" : {
344
+ preferred : false ,
345
+ latency_ms : 111.55 ,
346
+ } ,
347
+ Paris : {
348
+ preferred : false ,
349
+ latency_ms : 221.66 ,
350
+ } ,
351
+ } ,
331
352
}
332
353
333
354
export const MockWorkspaceAgentConnecting : TypesGen . WorkspaceAgent = {
@@ -336,6 +357,7 @@ export const MockWorkspaceAgentConnecting: TypesGen.WorkspaceAgent = {
336
357
name : "another-workspace-agent" ,
337
358
status : "connecting" ,
338
359
version : "" ,
360
+ latency : { } ,
339
361
}
340
362
341
363
export const MockWorkspaceResource : TypesGen . WorkspaceResource = {
You can’t perform that action at this time.
0 commit comments