Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb8c07ff

Browse files
authored
feat: Auto select workspace proxy based on lowest latency (#7515)
* feat: Proxy auto select and user selection state* chore: Auto select based on latency* Add extra test for unknown latencies* Mock latencies for unit tests
1 parentf9a97c2 commitb8c07ff

File tree

12 files changed

+589
-144
lines changed

12 files changed

+589
-144
lines changed

‎site/jest.setup.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Blob } from "buffer"
88
importjestFetchMockfrom"jest-fetch-mock"
99
import{ProxyLatencyReport}from"contexts/useProxyLatency"
1010
import{RegionsResponse}from"api/typesGenerated"
11+
import{useMemo}from"react"
1112

1213
jestFetchMock.enableMocks()
1314

@@ -16,20 +17,25 @@ jestFetchMock.enableMocks()
1617
// actual network requests. So just globally mock this hook.
1718
jest.mock("contexts/useProxyLatency",()=>({
1819
useProxyLatency:(proxies?:RegionsResponse)=>{
19-
if(!proxies){
20-
return{}asRecord<string,ProxyLatencyReport>
21-
}
22-
23-
returnproxies.regions.reduce((acc,proxy)=>{
24-
acc[proxy.id]={
25-
accurate:true,
26-
// Return a constant latency of 8ms.
27-
// If you make this random it could break stories.
28-
latencyMS:8,
29-
at:newDate(),
20+
// Must use `useMemo` here to avoid infinite loop.
21+
// Mocking the hook with a hook.
22+
constlatencies=useMemo(()=>{
23+
if(!proxies){
24+
return{}asRecord<string,ProxyLatencyReport>
3025
}
31-
returnacc
32-
},{}asRecord<string,ProxyLatencyReport>)
26+
returnproxies.regions.reduce((acc,proxy)=>{
27+
acc[proxy.id]={
28+
accurate:true,
29+
// Return a constant latency of 8ms.
30+
// If you make this random it could break stories.
31+
latencyMS:8,
32+
at:newDate(),
33+
}
34+
returnacc
35+
},{}asRecord<string,ProxyLatencyReport>)
36+
},[proxies])
37+
38+
returnlatencies
3339
},
3440
}))
3541

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const Template: Story<AppLinkProps> = (args) => (
2626
setProxy:()=>{
2727
return
2828
},
29+
clearProxy:()=>{
30+
return
31+
},
2932
}}
3033
>
3134
<AppLink{...args}/>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ const TemplateFC = (
6565
setProxy:()=>{
6666
return
6767
},
68+
clearProxy:()=>{
69+
return
70+
},
6871
}}
6972
>
7073
<AgentRow{...args}/>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Example.args = {
3030
setProxy:()=>{
3131
return
3232
},
33+
clearProxy:()=>{
34+
return
35+
},
3336
}}
3437
>
3538
<AgentRow
@@ -97,6 +100,9 @@ BunchOfMetadata.args = {
97100
setProxy:()=>{
98101
return
99102
},
103+
clearProxy:()=>{
104+
return
105+
},
100106
}}
101107
>
102108
<AgentRow

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const Template: Story<WorkspaceProps> = (args) => (
4747
proxies:[],
4848
isLoading:false,
4949
isFetched:true,
50+
clearProxy:()=>{
51+
return
52+
},
5053
setProxy:()=>{
5154
return
5255
},

‎site/src/contexts/ProxyContext.test.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp