Skip to content

Commit d52d179

Browse files
committed
Pass refetch funtion up the context stack
1 parent 771d41f commit d52d179

File tree

7 files changed

+23
-1
lines changed

7 files changed

+23
-1
lines changed

site/src/components/AppLink/AppLink.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const Template: Story<AppLinkProps> = (args) => (
2929
clearProxy: () => {
3030
return
3131
},
32+
refetchProxyLatencies: () => {
33+
return
34+
},
3235
}}
3336
>
3437
<AppLink {...args} />

site/src/components/Navbar/NavbarView.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const proxyContextValue: ProxyContextValue = {
1919
isFetched: true,
2020
setProxy: jest.fn(),
2121
clearProxy: action("clearProxy"),
22+
refetchProxyLatencies: jest.fn(),
2223
proxyLatencies: {},
2324
}
2425

site/src/components/Resources/AgentRow.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ const TemplateFC = (
6868
clearProxy: () => {
6969
return
7070
},
71+
refetchProxyLatencies: () => {
72+
return
73+
},
7174
}}
7275
>
7376
<AgentRow {...args} />

site/src/components/Resources/ResourceCard.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Example.args = {
3333
clearProxy: () => {
3434
return
3535
},
36+
refetchProxyLatencies: () => {
37+
return
38+
},
3639
}}
3740
>
3841
<AgentRow
@@ -103,6 +106,9 @@ BunchOfMetadata.args = {
103106
clearProxy: () => {
104107
return
105108
},
109+
refetchProxyLatencies: () => {
110+
return
111+
},
106112
}}
107113
>
108114
<AgentRow

site/src/components/Workspace/Workspace.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const Template: Story<WorkspaceProps> = (args) => (
5353
setProxy: () => {
5454
return
5555
},
56+
refetchProxyLatencies: () => {
57+
return
58+
},
5659
}}
5760
>
5861
<Workspace {...args} />

site/src/contexts/ProxyContext.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export interface ProxyContextValue {
4545
// then the latency has not been fetched yet. Calculations happen async for each proxy in the list.
4646
// Refer to the returned report for a given proxy for more information.
4747
proxyLatencies: Record<string, ProxyLatencyReport>
48+
// refetchProxyLatencies will trigger refreshing of the proxy latencies. By default the latencies
49+
// are loaded once.
50+
refetchProxyLatencies: () => void
4851
// setProxy is a function that sets the user's selected proxy. This function should
4952
// only be called if the user is manually selecting a proxy. This value is stored in local
5053
// storage and will persist across reloads and tabs.
@@ -101,7 +104,8 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
101104

102105
// Every time we get a new proxiesResponse, update the latency check
103106
// to each workspace proxy.
104-
const { proxyLatencies } = useProxyLatency(proxiesResp)
107+
const { proxyLatencies, refetch: refetchProxyLatencies } =
108+
useProxyLatency(proxiesResp)
105109

106110
// updateProxy is a helper function that when called will
107111
// update the proxy being used.
@@ -128,6 +132,7 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
128132
<ProxyContext.Provider
129133
value={{
130134
proxyLatencies,
135+
refetchProxyLatencies,
131136
userProxy: userSavedProxy,
132137
proxy: experimentEnabled
133138
? proxy

site/src/pages/TerminalPage/TerminalPage.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const renderTerminal = () => {
5555
isLoading: false,
5656
setProxy: jest.fn(),
5757
clearProxy: jest.fn(),
58+
refetchProxyLatencies: jest.fn(),
5859
}}
5960
>
6061
<TerminalPage renderer="dom" />

0 commit comments

Comments
 (0)