Skip to content

Commit 7d163fd

Browse files
committed
Make fmt
1 parent 9879476 commit 7d163fd

File tree

8 files changed

+87
-61
lines changed

8 files changed

+87
-61
lines changed

site/src/components/AppLink/AppLink.tsx

+7-9
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ export interface AppLinkProps {
2323
agent: TypesGen.WorkspaceAgent
2424
}
2525

26-
export const AppLink: FC<AppLinkProps> = ({
27-
app,
28-
workspace,
29-
agent,
30-
}) => {
26+
export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
3127
const { proxy } = useProxy()
3228
const preferredPathBase = proxy.preferredPathAppURL
3329
const appsHost = proxy.preferredWildcardHostname
@@ -46,11 +42,13 @@ export const AppLink: FC<AppLinkProps> = ({
4642

4743
// The backend redirects if the trailing slash isn't included, so we add it
4844
// here to avoid extra roundtrips.
49-
let href = `${preferredPathBase}/@${username}/${workspace.name}.${agent.name
50-
}/apps/${encodeURIComponent(appSlug)}/`
45+
let href = `${preferredPathBase}/@${username}/${workspace.name}.${
46+
agent.name
47+
}/apps/${encodeURIComponent(appSlug)}/`
5148
if (app.command) {
52-
href = `${preferredPathBase}/@${username}/${workspace.name}.${agent.name
53-
}/terminal?command=${encodeURIComponent(app.command)}`
49+
href = `${preferredPathBase}/@${username}/${workspace.name}.${
50+
agent.name
51+
}/terminal?command=${encodeURIComponent(app.command)}`
5452
}
5553

5654
// TODO: @emyrk handle proxy subdomains.

site/src/components/PortForwardButton/PortForwardButton.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export const portForwardURL = (
3535
): string => {
3636
const { location } = window
3737

38-
const subdomain = `${isNaN(port) ? 3000 : port
39-
}--${agentName}--${workspaceName}--${username}`
38+
const subdomain = `${
39+
isNaN(port) ? 3000 : port
40+
}--${agentName}--${workspaceName}--${username}`
4041
return `${location.protocol}//${host}`.replace("*", subdomain)
4142
}
4243

site/src/components/Resources/AgentRow.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,16 @@ export const AgentRow: FC<AgentRowProps> = ({
248248
sshPrefix={sshPrefix}
249249
/>
250250
)}
251-
{proxy.preferredWildcardHostname !== undefined && proxy.preferredWildcardHostname !== "" && (
252-
<PortForwardButton
253-
host={proxy.preferredWildcardHostname}
254-
workspaceName={workspace.name}
255-
agentId={agent.id}
256-
agentName={agent.name}
257-
username={workspace.owner_name}
258-
/>
259-
)}
251+
{proxy.preferredWildcardHostname !== undefined &&
252+
proxy.preferredWildcardHostname !== "" && (
253+
<PortForwardButton
254+
host={proxy.preferredWildcardHostname}
255+
workspaceName={workspace.name}
256+
agentId={agent.id}
257+
agentName={agent.name}
258+
username={workspace.owner_name}
259+
/>
260+
)}
260261
</div>
261262
)}
262263

site/src/components/TerminalLink/TerminalLink.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export const TerminalLink: FC<React.PropsWithChildren<TerminalLinkProps>> = ({
3030
}) => {
3131
const { proxy } = useProxy()
3232

33-
const href = `${proxy.preferredPathAppURL}/@${userName}/${workspaceName}${agentName ? `.${agentName}` : ""
34-
}/terminal`
33+
const href = `${proxy.preferredPathAppURL}/@${userName}/${workspaceName}${
34+
agentName ? `.${agentName}` : ""
35+
}/terminal`
3536

3637
return (
3738
<Link

site/src/contexts/ProxyContext.tsx

+53-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { useQuery } from "@tanstack/react-query"
22
import { getApplicationsHost, getWorkspaceProxies } from "api/api"
33
import { Region } from "api/typesGenerated"
44
import { useDashboard } from "components/Dashboard/DashboardProvider"
5-
import { createContext, FC, PropsWithChildren, useContext, useState } from "react"
5+
import {
6+
createContext,
7+
FC,
8+
PropsWithChildren,
9+
useContext,
10+
useState,
11+
} from "react"
612

713
interface ProxyContextValue {
814
proxy: PreferredProxy
@@ -17,7 +23,7 @@ interface PreferredProxy {
1723
// object. Use the preferred fields.
1824
selectedRegion: Region | undefined
1925
// PreferredPathAppURL is the URL of the proxy or it is the empty string
20-
// to indicte using relative paths. To add a path to this:
26+
// to indicate using relative paths. To add a path to this:
2127
// PreferredPathAppURL + "/path/to/app"
2228
preferredPathAppURL: string
2329
// PreferredWildcardHostname is a hostname that includes a wildcard.
@@ -38,7 +44,10 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
3844

3945
// The initial state is no regions and no selected region.
4046
const [proxy, setProxy] = useState<PreferredProxy>(savedProxy)
41-
const setAndSaveProxy = (regions: Region[], selectedRegion: Region | undefined) => {
47+
const setAndSaveProxy = (
48+
regions: Region[],
49+
selectedRegion: Region | undefined,
50+
) => {
4251
const preferred = getURLs(regions, selectedRegion)
4352
// Save to local storage to persist the user's preference across reloads
4453
// and other tabs.
@@ -51,7 +60,7 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
5160
const { error: regionsError, isLoading: regionsLoading } = useQuery({
5261
queryKey,
5362
queryFn: getWorkspaceProxies,
54-
// This onSucccess ensures the local storage is synchronized with the
63+
// This onSuccess ensures the local storage is synchronized with the
5564
// regions returned by coderd. If the selected region is not in the list,
5665
// then the user selection is removed.
5766
onSuccess: (data) => {
@@ -61,11 +70,15 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
6170

6271
// ******************************* //
6372
// ** This code can be removed **
64-
// ** when the experimental is **
73+
// ** when the experimental is **
6574
// ** dropped ** //
6675
const dashboard = useDashboard()
6776
const appHostQueryKey = ["get-application-host"]
68-
const { data: applicationHostResult, error: appHostError, isLoading: appHostLoading } = useQuery({
77+
const {
78+
data: applicationHostResult,
79+
error: appHostError,
80+
isLoading: appHostLoading,
81+
} = useQuery({
6982
queryKey: appHostQueryKey,
7083
queryFn: getApplicationsHost,
7184
})
@@ -75,19 +88,22 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
7588
const value = getURLs([])
7689

7790
return (
78-
<ProxyContext.Provider value={{
79-
proxy: {
80-
...value,
81-
preferredWildcardHostname: applicationHostResult?.host || value.preferredWildcardHostname,
82-
},
83-
isLoading: appHostLoading,
84-
error: appHostError,
85-
setProxy: () => {
86-
// Does a noop
87-
},
88-
}}>
91+
<ProxyContext.Provider
92+
value={{
93+
proxy: {
94+
...value,
95+
preferredWildcardHostname:
96+
applicationHostResult?.host || value.preferredWildcardHostname,
97+
},
98+
isLoading: appHostLoading,
99+
error: appHostError,
100+
setProxy: () => {
101+
// Does a noop
102+
},
103+
}}
104+
>
89105
{children}
90-
</ProxyContext.Provider >
106+
</ProxyContext.Provider>
91107
)
92108
}
93109
// ******************************* //
@@ -96,16 +112,18 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
96112
// regions list.
97113

98114
return (
99-
<ProxyContext.Provider value={{
100-
proxy: proxy,
101-
isLoading: regionsLoading,
102-
error: regionsError,
103-
// A function that takes the new regions and selected region and updates
104-
// the state with the appropriate urls.
105-
setProxy: setAndSaveProxy,
106-
}}>
115+
<ProxyContext.Provider
116+
value={{
117+
proxy: proxy,
118+
isLoading: regionsLoading,
119+
error: regionsError,
120+
// A function that takes the new regions and selected region and updates
121+
// the state with the appropriate urls.
122+
setProxy: setAndSaveProxy,
123+
}}
124+
>
107125
{children}
108-
</ProxyContext.Provider >
126+
</ProxyContext.Provider>
109127
)
110128
}
111129

@@ -119,23 +137,27 @@ export const useProxy = (): ProxyContextValue => {
119137
return context
120138
}
121139

122-
123140
/**
124141
* getURLs is a helper function to calculate the urls to use for a given proxy configuration. By default, it is
125142
* assumed no proxy is configured and relative paths should be used.
126-
*
143+
*
127144
* @param regions Is the list of regions returned by coderd. If this is empty, default behavior is used.
128145
* @param selectedRegion Is the region the user has selected. If this is undefined, default behavior is used.
129146
*/
130-
const getURLs = (regions: Region[], selectedRegion?: Region): PreferredProxy => {
147+
const getURLs = (
148+
regions: Region[],
149+
selectedRegion?: Region,
150+
): PreferredProxy => {
131151
// By default we set the path app to relative and disable wilcard hostnames.
132152
// We will set these values if we find a proxy we can use that supports them.
133153
let pathAppURL = ""
134154
let wildcardHostname = ""
135155

136156
// If a region is selected, make sure it is in the list of regions. If it is not
137157
// we should default to the primary.
138-
selectedRegion = regions.find((region) => selectedRegion && region.id === selectedRegion.id)
158+
selectedRegion = regions.find(
159+
(region) => selectedRegion && region.id === selectedRegion.id,
160+
)
139161

140162
if (!selectedRegion) {
141163
// If no region is selected, default to the primary region.

site/src/pages/TerminalPage/TerminalPage.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ const TerminalPage: FC<
105105
// handleWebLink handles opening of URLs in the terminal!
106106
const handleWebLink = useCallback(
107107
(uri: string) => {
108-
if (!workspaceAgent || !workspace || !username || !proxy.preferredWildcardHostname) {
108+
if (
109+
!workspaceAgent ||
110+
!workspace ||
111+
!username ||
112+
!proxy.preferredWildcardHostname
113+
) {
109114
return
110115
}
111116

@@ -243,7 +248,7 @@ const TerminalPage: FC<
243248
if (workspaceAgentError instanceof Error) {
244249
terminal.writeln(
245250
Language.workspaceAgentErrorMessagePrefix +
246-
workspaceAgentError.message,
251+
workspaceAgentError.message,
247252
)
248253
}
249254
if (websocketError instanceof Error) {
@@ -291,8 +296,8 @@ const TerminalPage: FC<
291296
<title>
292297
{terminalState.context.workspace
293298
? pageTitle(
294-
`Terminal · ${terminalState.context.workspace.owner_name}/${terminalState.context.workspace.name}`,
295-
)
299+
`Terminal · ${terminalState.context.workspace.owner_name}/${terminalState.context.workspace.name}`,
300+
)
296301
: ""}
297302
</title>
298303
</Helmet>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const WorkspaceProxyPage: FC<PropsWithChildren<unknown>> = () => {
5353
return
5454
}
5555

56-
// Set the fetched regions + the selected proxy
56+
// Set the fetched regions + the selected proxy
5757
setProxy(response ? response.regions : [], proxy)
5858
}}
5959
/>

site/src/pages/UserSettingsPage/WorkspaceProxyPage/hooks.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {
2-
useQuery,
3-
} from "@tanstack/react-query"
1+
import { useQuery } from "@tanstack/react-query"
42
import { getWorkspaceProxies } from "api/api"
53

64
// Loads all workspace proxies

0 commit comments

Comments
 (0)