diff --git a/app/pages/project/instances/instance/tabs/ConnectTab.tsx b/app/pages/project/instances/instance/tabs/ConnectTab.tsx index 0e6bdec8f..12a2d523e 100644 --- a/app/pages/project/instances/instance/tabs/ConnectTab.tsx +++ b/app/pages/project/instances/instance/tabs/ConnectTab.tsx @@ -9,11 +9,11 @@ import type { ReactNode } from 'react' import { Link, type LoaderFunctionArgs } from 'react-router-dom' -import { apiQueryClient, useApiQuery } from '~/api' +import { apiQueryClient, usePrefetchedApiQuery } from '~/api' import { EquivalentCliCommand } from '~/components/EquivalentCliCommand' -import { getInstanceSelector, useInstanceSelector, useProjectSelector } from '~/hooks' +import { getInstanceSelector, useInstanceSelector } from '~/hooks' import { buttonStyle } from '~/ui/lib/Button' -import { SettingsGroup } from '~/ui/lib/SettingsGroup' +import { LearnMore, SettingsGroup } from '~/ui/lib/SettingsGroup' import { cliCmd } from '~/util/cli-cmd' import { links } from '~/util/links' import { pb } from '~/util/path-builder' @@ -35,29 +35,14 @@ const InlineCode = ({ children }: { children: ReactNode }) => ( export function ConnectTab() { const { project, instance } = useInstanceSelector() - const { data: externalIps } = useApiQuery('instanceExternalIpList', { + const { data: externalIps } = usePrefetchedApiQuery('instanceExternalIpList', { path: { instance }, query: { project }, }) - const newFloatingIpLink = pb.floatingIpsNew(useProjectSelector()) - const floatingIps = externalIps?.items?.filter((ip) => ip.kind === 'floating') - // default to a floating IP; fall back to ephemeral IP, if it exists - const externalIp = (floatingIps?.[0] || externalIps?.items?.[0])?.ip - const sshCopy = externalIp ? ( -

- If you specified SSH keys when you created this instance, you can connect to it - through an external IP: ssh [username]@{externalIp} -

- ) : ( -

- If you specified SSH keys when you created this instance, you can create an external - IP via the{' '} - - Floating IPs page - {' '} - to connect to your instance via SSH. -

- ) + const floatingIp = externalIps.items.find((ip) => ip.kind === 'floating') + const ephemeralIp = externalIps.items.find((ip) => ip.kind === 'ephemeral') + // prefer floating, fall back to ephemeral + const externalIp = floatingIp?.ip || ephemeralIp?.ip return (
@@ -67,34 +52,47 @@ export function ConnectTab() { Connect to your instance’s serial console - - - Connect - +
+ {/* TODO: CORRECT LINK */} + +
+
+ + + Connect + +
SSH -
- {sshCopy} -

- Read our{' '} +

+ If you specified SSH keys when you created this instance, you can connect to it + through an external IP:{' '} + ssh [username]@{externalIp || '[IP address]'} +

+ {!externalIp && ( +

+ This instance has no external IP address. You can add one on the{' '} - SSH guide + networking {' '} - to learn more. + tab.

-
+ )}
+ +
+ +
+
) diff --git a/app/ui/lib/SettingsGroup.tsx b/app/ui/lib/SettingsGroup.tsx index 62e8d943a..793375f99 100644 --- a/app/ui/lib/SettingsGroup.tsx +++ b/app/ui/lib/SettingsGroup.tsx @@ -10,32 +10,25 @@ import { OpenLink12Icon } from '@oxide/design-system/icons/react' import { classed } from '~/util/classed' -const LearnMore = ({ href, text }: { href: string; text: React.ReactNode }) => ( +export const LearnMore = ({ href, text }: { href: string; text: React.ReactNode }) => ( <> Learn more about{' '} - + {text} ) -type FooterProps = { - /** Link text */ - children: React.ReactNode - docsLink?: { text: string; href: string } -} - /** Use size=sm on buttons and links! */ export const SettingsGroup = { Container: classed.div`w-full max-w-[660px] rounded-lg border text-sans-md text-secondary border-default`, Body: classed.div`p-6`, Title: classed.div`mb-1 text-sans-lg text-default`, - Footer: ({ children, docsLink }: FooterProps) => ( -
- {/* div always present to keep the buttons right-aligned */} -
{docsLink && }
-
{children}
-
- ), + Footer: classed.div`flex items-center justify-between border-t px-6 py-3 border-default h-14`, }