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

Commit877c0c9

Browse files
committed
PR feedback
1 parent523e492 commit877c0c9

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const TestingScreen = () => {
146146
<divdata-testid="isLoading"title={isLoading.toString()}></div>
147147
<div
148148
data-testid="preferredProxy"
149-
title={proxy.selectedProxy&&proxy.selectedProxy.id}
149+
title={proxy.proxy&&proxy.proxy.id}
150150
></div>
151151
<divdata-testid="userProxy"title={userProxy&&userProxy.id}></div>
152152
<buttondata-testid="clearProxy"onClick={clearProxy}></button>
@@ -187,7 +187,6 @@ interface ProxyContextSelectionTest {
187187

188188
describe("ProxyContextSelection",()=>{
189189
beforeEach(()=>{
190-
// Object.defineProperty(window, "localStorage", { value: localStorageMock })
191190
window.localStorage.clear()
192191
})
193192

‎site/src/contexts/ProxyContext.tsx‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ export interface ProxyContextValue {
5858
}
5959

6060
interfacePreferredProxy{
61-
//selectedProxy is the preferred proxy being used. It is provided for
61+
//proxy is the proxy being used. It is provided for
6262
// getting the fields such as "display_name" and "id"
6363
// Do not use the fields 'path_app_url' or 'wildcard_hostname' from this
6464
// object. Use the preferred fields.
65-
selectedProxy:Region|undefined
65+
proxy:Region|undefined
6666
// PreferredPathAppURL is the URL of the proxy or it is the empty string
6767
// to indicate using relative paths. To add a path to this:
6868
// PreferredPathAppURL + "/path/to/app"
@@ -86,12 +86,9 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
8686

8787
// As the proxies are being loaded, default to using the saved proxy.
8888
// If the saved proxy is not valid when the async fetch happens, the
89-
// selectedProxy will be updated accordingly.
90-
letdefaultPreferredProxy:PreferredProxy={
91-
selectedProxy:savedProxy,
92-
preferredPathAppURL:savedProxy?.path_app_url.replace(/\/$/,"")||"",
93-
preferredWildcardHostname:savedProxy?.wildcard_hostname||"",
94-
}
89+
// proxy will be updated accordingly.
90+
letdefaultPreferredProxy=computeUsableURLS(savedProxy)
91+
9592
if(!savedProxy){
9693
// If no preferred proxy is saved, then default to using relative paths
9794
// and no subdomain support until the proxies are properly loaded.
@@ -206,12 +203,12 @@ export const useProxy = (): ProxyContextValue => {
206203
}
207204

208205
/**
209-
*getURLs is a helper function to calculate the urls to use for a given proxy configuration. By default, it is
206+
*getPreferredProxy is a helper function to calculate the urls to use for a given proxy configuration. By default, it is
210207
* assumed no proxy is configured and relative paths should be used.
211208
* Exported for testing.
212209
*
213210
*@param proxies Is the list of proxies returned by coderd. If this is empty, default behavior is used.
214-
*@param selectedProxy Is the proxythe user has selected. If this is undefined, default behavior is used.
211+
*@param selectedProxy Is the proxysaved in local storage. If this is undefined, default behavior is used.
215212
*@param latencies If provided, this is used to determine the best proxy to default to.
216213
* If not, `primary` is always the best default.
217214
*/
@@ -220,11 +217,6 @@ export const getPreferredProxy = (
220217
selectedProxy?:Region,
221218
latencies?:Record<string,ProxyLatencyReport>,
222219
):PreferredProxy=>{
223-
// By default we set the path app to relative and disable wildcard hostnames.
224-
// We will set these values if we find a proxy we can use that supports them.
225-
letpathAppURL=""
226-
letwildcardHostname=""
227-
228220
// If a proxy is selected, make sure it is in the list of proxies. If it is not
229221
// we should default to the primary.
230222
selectedProxy=proxies.find(
@@ -263,23 +255,31 @@ export const getPreferredProxy = (
263255
}
264256
}
265257

266-
// Only use healthy proxies.
267-
if(selectedProxy&&selectedProxy.healthy){
258+
returncomputeUsableURLS(selectedProxy)
259+
}
260+
261+
constcomputeUsableURLS=(proxy?:Region):PreferredProxy=>{
262+
if(!proxy){
268263
// By default use relative links for the primary proxy.
269264
// This is the default, and we should not change it.
270-
if(selectedProxy.name!=="primary"){
271-
pathAppURL=selectedProxy.path_app_url
265+
return{
266+
proxy:undefined,
267+
preferredPathAppURL:"",
268+
preferredWildcardHostname:"",
272269
}
273-
wildcardHostname=selectedProxy.wildcard_hostname
274270
}
275271

276-
// TODO:@emyrk Should we notify the user if they had an unhealthy proxy selected?
272+
letpathAppURL=proxy?.path_app_url.replace(/\/$/,"")
273+
// Primary proxy uses relative paths. It's the only exception.
274+
if(proxy.name==="primary"){
275+
pathAppURL=""
276+
}
277277

278278
return{
279-
selectedProxy:selectedProxy,
279+
proxy:proxy,
280280
// Trim trailing slashes to be consistent
281-
preferredPathAppURL:pathAppURL.replace(/\/$/,""),
282-
preferredWildcardHostname:wildcardHostname,
281+
preferredPathAppURL:pathAppURL,
282+
preferredWildcardHostname:proxy.wildcard_hostname,
283283
}
284284
}
285285

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const renderTerminal = () => {
4646
value={{
4747
proxyLatencies:MockProxyLatencies,
4848
proxy:{
49-
selectedProxy:MockPrimaryWorkspaceProxy,
49+
proxy:MockPrimaryWorkspaceProxy,
5050
preferredPathAppURL:"",
5151
preferredWildcardHostname:"",
5252
},

‎site/src/pages/UserSettingsPage/WorkspaceProxyPage/WorkspaceProxyPage.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const WorkspaceProxyPage: FC<PropsWithChildren<unknown>> = () => {
3636
isLoading={proxiesLoading}
3737
hasLoaded={proxiesFetched}
3838
getWorkspaceProxiesError={proxiesError}
39-
preferredProxy={proxy.selectedProxy}
39+
preferredProxy={proxy.proxy}
4040
onSelect={(proxy)=>{
4141
if(!proxy.healthy){
4242
displayError("Please select a healthy workspace proxy.")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp