Skip to content

feat: UI/UX for regions #7283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
26d3497
chore: Allow regular users to query for all workspaces
Emyrk Apr 24, 2023
3203ad7
Begin work on FE to add workspace proxy options to account settings
Emyrk Apr 24, 2023
a9ad485
Take origin file
Emyrk Apr 25, 2023
bde8870
Remove excess diffs
Emyrk Apr 25, 2023
69ce5f0
fixup! Remove excess diffs
Emyrk Apr 25, 2023
1daa32f
Update proxy page for regions endpoint
Emyrk Apr 25, 2023
b2e3efb
Some basic selector for proxies
Emyrk Apr 25, 2023
f78935f
Make hook for preferred proxy
Emyrk Apr 25, 2023
7a2e78e
Make fmt
Emyrk Apr 25, 2023
9b598e8
Typo
Emyrk Apr 25, 2023
17f9b00
Create workspace proxy context
Emyrk Apr 26, 2023
0683412
Use new context
Emyrk Apr 26, 2023
69c5734
fixup! Use new context
Emyrk Apr 26, 2023
9879476
WorkspaceProxy context syncs with coderd on region responses
Emyrk Apr 26, 2023
7d163fd
Make fmt
Emyrk Apr 26, 2023
e400810
Move dashboard provider
Emyrk Apr 26, 2023
02bcb84
Fix authenticated providers
Emyrk Apr 26, 2023
f9446c2
Fix authenticated renders
Emyrk Apr 26, 2023
9281333
Merge remote-tracking branch 'origin/main' into stevenmasley/regions
Emyrk Apr 26, 2023
8cc227f
Make fmt
Emyrk Apr 26, 2023
63dc985
Use auth render
Emyrk Apr 26, 2023
f4b6921
Fix terminal test render
Emyrk Apr 26, 2023
322fda6
Make fmt
Emyrk Apr 26, 2023
89efc57
Fix local storage load
Emyrk Apr 27, 2023
48a0beb
Fix terminals on the frontend to use proxies
Emyrk Apr 27, 2023
77d943f
Remove CSP hole
Emyrk Apr 27, 2023
75b8fd4
Add comment on origin patterns
Emyrk Apr 27, 2023
3391e84
Add unit test for getURLs
Emyrk Apr 27, 2023
4075b92
remove some TODOs
Emyrk Apr 27, 2023
b79b460
Add another store
Emyrk Apr 27, 2023
e879160
Update site/src/components/TerminalLink/TerminalLink.tsx
Emyrk Apr 27, 2023
27ef4a9
Fix stories
Emyrk Apr 27, 2023
eb38e95
Move providers into requrie auth
Emyrk Apr 27, 2023
1f8cae4
Fix imports
Emyrk Apr 27, 2023
6a22181
Fix 2 stories
Emyrk Apr 27, 2023
51bdaa2
Stories did not have subdomains on
Emyrk Apr 27, 2023
909801c
Merge remote-tracking branch 'origin/main' into stevenmasley/regions
Emyrk Apr 27, 2023
836c5a4
Fmt after merge
Emyrk Apr 27, 2023
0d0ed87
Fix port forward story
Emyrk Apr 27, 2023
6ed5fe4
ProxyPageView -> ProxyView
Emyrk Apr 27, 2023
163bbff
PR comment cleanup
Emyrk Apr 27, 2023
7dee309
Fix moon feature flag panic
Emyrk Apr 27, 2023
b7cfb39
Make fmt
Emyrk Apr 27, 2023
6b19118
Fix typo
Emyrk Apr 27, 2023
3fed785
Rename getUrls
Emyrk Apr 28, 2023
5bb44e8
Rename regions to proxies
Emyrk Apr 28, 2023
c868fc9
Only do 1 api call based on experiment
Emyrk Apr 28, 2023
edbe6e4
Cleanup args to take just the selected proxy
Emyrk Apr 28, 2023
eb6493c
Renames regions -> proxies
Emyrk Apr 28, 2023
017b3db
Fix stories
Emyrk Apr 28, 2023
c59a6ba
Move funciton back to bottom
Emyrk Apr 28, 2023
87e0b6d
Fix onSuccess of proxy provider
Emyrk Apr 28, 2023
fef5b00
Make fmt
Emyrk Apr 28, 2023
d33371d
Simplify some ts
Emyrk Apr 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make hook for preferred proxy
  • Loading branch information
Emyrk committed Apr 25, 2023
commit f78935fbdfaa0b95ff8bb0f0589928e08966b29b
32 changes: 19 additions & 13 deletions site/src/components/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as TypesGen from "../../api/typesGenerated"
import { generateRandomString } from "../../utils/random"
import { BaseIcon } from "./BaseIcon"
import { ShareIcon } from "./ShareIcon"
import { usePreferredProxy } from "hooks/usePreferredProxy"

const Language = {
appTitle: (appName: string, identifier: string): string =>
Expand All @@ -29,6 +30,11 @@ export const AppLink: FC<AppLinkProps> = ({
workspace,
agent,
}) => {
const preferredProxy = usePreferredProxy()
const preferredPathBase = preferredProxy ? preferredProxy.path_app_url : ""
// Use the proxy host subdomain if it's configured.
appsHost = preferredProxy ? preferredProxy.wildcard_hostname : appsHost

const styles = useStyles()
const username = workspace.owner_name

Expand All @@ -43,14 +49,14 @@ export const AppLink: FC<AppLinkProps> = ({

// The backend redirects if the trailing slash isn't included, so we add it
// here to avoid extra roundtrips.
let href = `/@${username}/${workspace.name}.${
agent.name
}/apps/${encodeURIComponent(appSlug)}/`
let href = `${preferredPathBase}/@${username}/${workspace.name}.${agent.name
}/apps/${encodeURIComponent(appSlug)}/`
if (app.command) {
href = `/@${username}/${workspace.name}.${
agent.name
}/terminal?command=${encodeURIComponent(app.command)}`
href = `${preferredPathBase}/@${username}/${workspace.name}.${agent.name
}/terminal?command=${encodeURIComponent(app.command)}`
}

// TODO: @emyrk handle proxy subdomains.
if (appsHost && app.subdomain) {
const subdomain = `${appSlug}--${agent.name}--${workspace.name}--${username}`
href = `${window.location.protocol}//${appsHost}/`.replace("*", subdomain)
Expand Down Expand Up @@ -104,13 +110,13 @@ export const AppLink: FC<AppLinkProps> = ({
onClick={
canClick
? (event) => {
event.preventDefault()
window.open(
href,
Language.appTitle(appDisplayName, generateRandomString(12)),
"width=900,height=600",
)
}
event.preventDefault()
window.open(
href,
Language.appTitle(appDisplayName, generateRandomString(12)),
"width=900,height=600",
)
}
: undefined
}
>
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/DeploySettingsLayout/Badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const NotHealthyBadge: FC = () => {
const styles = useStyles()
return (
<span className={combineClasses([styles.badge, styles.errorBadge])}>
Error
Unhealthy
</span>
)
}
Expand Down
12 changes: 7 additions & 5 deletions site/src/components/PortForwardButton/PortForwardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ export const portForwardURL = (
): string => {
const { location } = window

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

const TooltipView: React.FC<PortForwardButtonProps> = (props) => {
const { host, workspaceName, agentName, agentId, username } = props
const preferredProxy = usePreferredProxy()
const portHost = preferredProxy ? preferredProxy.wildcard_hostname : host

const styles = useStyles()
const [port, setPort] = useState("3000")
const urlExample = portForwardURL(
host,
portHost,
parseInt(port),
agentName,
workspaceName,
Expand Down Expand Up @@ -104,7 +106,7 @@ const TooltipView: React.FC<PortForwardButtonProps> = (props) => {
{ports &&
ports.map((p, i) => {
const url = portForwardURL(
host,
portHost,
p.port,
agentName,
workspaceName,
Expand Down
17 changes: 10 additions & 7 deletions site/src/components/SettingsLayout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { combineClasses } from "utils/combineClasses"
import AccountIcon from "@material-ui/icons/Person"
import SecurityIcon from "@material-ui/icons/LockOutlined"
import PublicIcon from '@material-ui/icons/Public';
import { useDashboard } from "components/Dashboard/DashboardProvider"

const SidebarNavItem: FC<
PropsWithChildren<{ href: string; icon: ReactNode }>
Expand Down Expand Up @@ -42,6 +43,7 @@ const SidebarNavItemIcon: React.FC<{ icon: ElementType }> = ({

export const Sidebar: React.FC<{ user: User }> = ({ user }) => {
const styles = useStyles()
const dashboard = useDashboard()

return (
<nav className={styles.sidebar}>
Expand Down Expand Up @@ -77,13 +79,14 @@ export const Sidebar: React.FC<{ user: User }> = ({ user }) => {
>
Tokens
</SidebarNavItem>
{/* TODO: @emyrk this should only be shown if the 'moons' experiment is enabled */}
<SidebarNavItem
href="workspace-proxies"
icon={<SidebarNavItemIcon icon={PublicIcon} />}
>
Workspace Proxy
</SidebarNavItem>
{
dashboard.experiments.includes("moons") && <SidebarNavItem
href="workspace-proxies"
icon={<SidebarNavItemIcon icon={PublicIcon} />}
>
Workspace Proxy
</SidebarNavItem>
}
</nav>
)
}
Expand Down
9 changes: 6 additions & 3 deletions site/src/components/TerminalLink/TerminalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SecondaryAgentButton } from "components/Resources/AgentButton"
import { FC } from "react"
import * as TypesGen from "../../api/typesGenerated"
import { generateRandomString } from "../../utils/random"
import { usePreferredProxy } from "hooks/usePreferredProxy"

export const Language = {
linkText: "Terminal",
Expand All @@ -27,9 +28,11 @@ export const TerminalLink: FC<React.PropsWithChildren<TerminalLinkProps>> = ({
userName = "me",
workspaceName,
}) => {
const href = `/@${userName}/${workspaceName}${
agentName ? `.${agentName}` : ""
}/terminal`
const preferredProxy = usePreferredProxy()
const preferredPathBase = preferredProxy ? preferredProxy.path_app_url : ""

const href = `${preferredPathBase}/@${userName}/${workspaceName}${agentName ? `.${agentName}` : ""
}/terminal`

return (
<Link
Expand Down
20 changes: 20 additions & 0 deletions site/src/hooks/usePreferredProxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Region } from "api/typesGenerated"
import { useDashboard } from "components/Dashboard/DashboardProvider"

export const usePreferredProxy = (): Region | undefined => {
const dashboard = useDashboard()
// Only use preferred proxy if the user has the moons experiment enabled
if(!dashboard?.experiments.includes("moons")) {
return undefined
}

const str = localStorage.getItem("preferred-proxy")
if (str === undefined || str === null) {
return undefined
}
const proxy = JSON.parse(str)
if (proxy.id === undefined || proxy.id === null) {
return undefined
}
return proxy
}
19 changes: 0 additions & 19 deletions site/src/i18n/en/proxyPage.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC, PropsWithChildren, useState } from "react"
import { Section } from "components/SettingsLayout/Section"
import { WorkspaceProxyPageView } from "./WorkspaceProxyView"
import makeStyles from "@material-ui/core/styles/makeStyles"
import { useTranslation, Trans } from "react-i18next"
import { Trans } from "react-i18next"
import { useWorkspaceProxiesData } from "./hooks"
import { Region } from "api/typesGenerated"
import { displayError } from "components/GlobalSnackbar/utils"
Expand All @@ -15,10 +15,9 @@ import { displayError } from "components/GlobalSnackbar/utils"

export const WorkspaceProxyPage: FC<PropsWithChildren<unknown>> = () => {
const styles = useStyles()
const { t } = useTranslation("proxyPage")

const description = (
<Trans t={t} i18nKey="description" values={{}}>
<Trans values={{}}>
Workspace proxies are used to reduce the latency of connections to a workspace.
To get the best experience, choose the workspace proxy that is closest located to
you.
Expand All @@ -37,7 +36,7 @@ export const WorkspaceProxyPage: FC<PropsWithChildren<unknown>> = () => {
return (
<>
<Section
title={t("title")}
title="Workspace Proxies"
className={styles.section}
description={description}
layout="fluid"
Expand All @@ -53,8 +52,15 @@ export const WorkspaceProxyPage: FC<PropsWithChildren<unknown>> = () => {
displayError("Please select a healthy workspace proxy.")
return
}
savePreferredProxy(proxy)
setPreffered(proxy)
// normProxy is a normalized proxy to
const normProxy = {
...proxy,
// Trim trailing slashes to be consistent
path_app_url: proxy.path_app_url.replace(/\/$/, ''),
}

savePreferredProxy(normProxy)
setPreffered(normProxy)
}}
/>
</Section>
Expand All @@ -72,9 +78,6 @@ const useStyles = makeStyles((theme) => ({
borderRadius: 2,
},
},
tokenActions: {
marginBottom: theme.spacing(1),
},
}))

export default WorkspaceProxyPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ProxyStatus: FC<{

const useStyles = makeStyles((theme) => ({
preferredrow: {
// TODO: What color should I put here?
// TODO: What is the best way to show what proxy is currently being used?
backgroundColor: theme.palette.secondary.main,
outline: `3px solid ${theme.palette.secondary.light}`,
outlineOffset: -3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useTheme } from "@material-ui/core/styles"
import Table from "@material-ui/core/Table"
import TableBody from "@material-ui/core/TableBody"
import TableCell from "@material-ui/core/TableCell"
Expand All @@ -11,7 +10,6 @@ import { TableEmpty } from "components/TableEmpty/TableEmpty"
import { TableLoader } from "components/TableLoader/TableLoader"
import { FC } from "react"
import { AlertBanner } from "components/AlertBanner/AlertBanner"
import { useTranslation } from "react-i18next"
import { Region } from "api/typesGenerated"
import { ProxyRow } from "./WorkspaceProxyRow"

Expand All @@ -38,8 +36,6 @@ export const WorkspaceProxyPageView: FC<
selectProxyError,
preferredProxy,
}) => {
const { t } = useTranslation("proxyPage")

return (
<Stack>
{Boolean(getWorkspaceProxiesError) && (
Expand All @@ -52,9 +48,9 @@ export const WorkspaceProxyPageView: FC<
<Table>
<TableHead>
<TableRow>
<TableCell width="40%">{t("table.icon")}</TableCell>
<TableCell width="30%">{t("table.url")}</TableCell>
<TableCell width="10%">{t("table.status")}</TableCell>
<TableCell width="40%">Proxy</TableCell>
<TableCell width="30%">URL</TableCell>
<TableCell width="10%">Status</TableCell>
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -63,11 +59,11 @@ export const WorkspaceProxyPageView: FC<
<TableLoader />
</Cond>
<Cond condition={hasLoaded && proxies?.length === 0}>
<TableEmpty message={t("emptyState")} />
<TableEmpty message="No workspace proxies found" />
</Cond>
<Cond>
{proxies?.map((proxy) => (
<ProxyRow
< ProxyRow
key={proxy.id}
proxy={proxy}
onSelectRegion={onSelect}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Story } from "@storybook/react"
import { makeMockApiError, MockRegions } from "testHelpers/entities"
import { WorkspaceProxyPageView, WorkspaceProxyPageViewProps } from "./WorkspaceProxyView"

export default {
title: "components/WorkspaceProxyPageView",
component: WorkspaceProxyPageView,
args: {
onRegenerateClick: { action: "Submit" },
},
}

const Template: Story<WorkspaceProxyPageViewProps> = (args: WorkspaceProxyPageViewProps) => (
<WorkspaceProxyPageView {...args} />
)

export const Example = Template.bind({})
Example.args = {
isLoading: false,
hasLoaded: true,
proxies: MockRegions,
preferredProxy: MockRegions[0],
onSelect: () => {
return Promise.resolve()
},
}

export const Loading = Template.bind({})
Loading.args = {
...Example.args,
isLoading: true,
hasLoaded: false,
}

export const Empty = Template.bind({})
Empty.args = {
...Example.args,
proxies: [],
}

export const WithProxiesError = Template.bind({})
WithProxiesError.args = {
...Example.args,
hasLoaded: false,
getWorkspaceProxiesError: makeMockApiError({
message: "Failed to get proxies.",
}),
}

export const WithSelectProxyError = Template.bind({})
WithSelectProxyError.args = {
...Example.args,
hasLoaded: false,
selectProxyError: makeMockApiError({
message: "Failed to select proxy.",
}),
}
Loading