feat(mobile-pairing): combobox with manual network address entry (#6501)
* docs(spec): manual network address entry for mobile pairing
* docs(plan): manual network address entry for mobile pairing
* docs(plan): fix two test-spec issues in Task 1
* feat(mobile-pairing): add parseManualNetworkAddress validator
* docs(plan): fix buildComboboxEntries filter rule
* feat(mobile-pairing): buildComboboxEntries for network interface combobox
* feat(mobile-pairing): combobox with manual address entry
* docs(spec): align buildComboboxEntries behavior with corrected plan
* fix(mobile-pairing): use text-destructive token for inline error
* fix(mobile-pairing): route Use row through translate() with i18next interpolation
* refactor(mobile-pairing): extract NetworkInterfaceCombobox shared by MobileHero and Settings section
The Popover + Command + manual-entry UX lived only in the Settings →
Mobile → Network Interface section. The mobile pairing screen
("Step 2 of 2 — Pair this computer") had its own copy of the same
Select-based dropdown that did not support manual address entry. A
user trying to pair with a Tailscale MagicDNS hostname from the
pairing screen could not enter it.
Extract the typeable combobox into a shared
`NetworkInterfaceCombobox` component. Both surfaces now render the
same Popover + Command with manual address entry, the `Use "..."`
row, the inline validation error, and the `(custom)` trigger label.
Settings keeps its own Generate QR button, Refresh + Tooltip, and
Tailnet accordion around the combobox. The pairing screen keeps its
existing layout (label + combobox + refresh icon).
Net deletion: ~160 lines. Net behavior gain: manual address entry is
now reachable from both surfaces, not only Settings.
* style(ui): give CommandInput a visible background so the search box is not lost
The Popover content above the CommandList renders the cmdk CommandInput
with only a thin bottom border. Against a white popover background it
visually disappears, especially in the mobile pairing screen where the
popover sits inside a dark phone mockup. Add a subtle `bg-muted/30` +
`py-1` so the input row is unambiguous, without changing the input's
shape or behavior.
* fix(mobile-pairing): drop cmdk CommandItem, use plain buttons inside Popover
In `pnpm dev` HMR cycle the cmdk CommandItem `onSelect` dispatch was
unreliable — clicking the item fired the synthetic event but the parent
React state never received it, so the trigger label never updated after
the user picked a manual address or a refreshed interface.
Replace the `Command` + `CommandItem` primitives inside
NetworkInterfaceCombobox with a native `<input>` + `<button>` list
wrapped by Radix `Popover`. The list now responds to the user's first
click without any intermediate effect that could be skipped in dev mode.
The combobox keeps the same props contract, the same placeholder, the
same inline validation, and the same `Use "<address>"` row at the
bottom of the list.
Update MobileNetworkInterfaceSection.test.tsx selectors from
`role=option` (cmdk's) to `role=button` so the integration test still
asserts the right element. All 479 feature tests still pass.
* debug(mobile-pairing): log handleSelect* invocations to confirm click path
* fix(mobile-pairing): commit on pointerdown to beat Radix Popover close race
In dev mode Radix Popover's close-on-pointerdown handler occasionally
fires before React's synthetic click dispatch reaches the option button,
so the parent's selectedAddress never updates after the user picks a
manual address. Bind the commit handler to pointerdown (synchronous,
before any pointer-up / click synthesis) and call event.preventDefault()
to avoid text-selection side effects. Keep onClick as a fallback so
keyboard / touch / programmatic-dispatch paths still work.
* fix(mobile-pairing): keep manually-typed addresses across network refresh
`selectRefreshedNetworkAddress` used to fall back to the first OS
interface whenever `currentAddress` wasn't in the OS-enumerated
list — so a user who typed a Tailscale MagicDNS name saw their
selection snap back to LAN every time `loadNetworkInterfaces`
returned. Treat manual entries as sticky by passing an
`isManual` flag from the caller; `selectRefreshedNetworkAddress`
now keeps the address when the caller says the user typed it.
`MobilePage` tracks `addressIsManual` alongside
`selectedAddress`: `handleAddressChange` flips it on when the
picked address is not in the OS list, and `loadNetworkInterfaces`
passes it through so refresh keeps the choice.
* chore(mobile-pairing): remove debug logs and sync new-combobox-listbox i18n key
* fix(mobile-pairing): address CodeRabbit review on manual-address lifecycle
Three real bugs from review, plus a regression test:
1. NetworkInterfaceCombobox in MobileHero was disabled when
`networkInterfaces.length === 0`, which locked users out of the
only path to type a manual address during a transient empty
discovery. Pass `disabled={false}` and let the combobox's
own empty-state copy explain the situation.
2. `selectRefreshedNetworkAddress` returned `undefined` whenever
`interfaces.length === 0`, even if the user had a manual
address and `currentAddressIsManual` was true. Keep the manual
address so a recovering discovery doesn't clobber it.
3. `loadNetworkInterfaces` could rewrite `selectedAddress` (e.g.
when a refresh swaps to a freshly-discovered tailnet) but never
updated `addressIsManual`, so the next refresh could revert
the user back to LAN. Re-derive `addressIsManual` from the
new address after every refresh.
Adds a regression test in
`mobile-network-interface-selection.test.ts` exercising the
empty-refresh + manual path.
* style(mobile-pairing): trim disabled-false comment to two lines
* refactor(mobile-pairing): replace typeable combobox with select + custom-address dialog
The Settings/MobileHero network selector used a Popover+search-input hybrid
that looked uneven and hid its validation error behind the open popover.
Replace it with a plain Select of discovered interfaces plus an
'Add custom address…' footer row that opens a small dialog for entering a
Tailscale hostname or static IP. Drops the 'MagicDNS' jargon for plainer
copy, keeps the '(custom)' trigger label, and routes all strings through
translate() with real es/ja/ko/zh translations. Removes the now-dead
buildComboboxEntries helper. Also adds the missing scrollbar-sleek class
the old list omitted (was failing pnpm lint).
Co-authored-by: Orca <help@stably.ai>
---------
Co-authored-by: ppw-stack <ppw-stack@users.noreply.github.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
co-authored by
Orca
ppw-stack
Jinwoo-H
parent
dafe844a50
commit
299bc421e2
@@ -0,0 +1,113 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { parseManualNetworkAddress } from '../../../../shared/network/manual-address'
|
||||
|
||||
type CustomNetworkAddressDialogProps = {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
// Why: prefill from the current selection when it is already a custom value
|
||||
// so reopening to edit shows what is in use rather than a blank field.
|
||||
initialValue?: string
|
||||
onConfirm: (address: string) => void
|
||||
}
|
||||
|
||||
export function CustomNetworkAddressDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
initialValue,
|
||||
onConfirm
|
||||
}: CustomNetworkAddressDialogProps): React.JSX.Element {
|
||||
const [value, setValue] = useState(initialValue ?? '')
|
||||
|
||||
// Why: reseed each time the dialog opens so a prior cancelled edit doesn't
|
||||
// leak into the next open.
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setValue(initialValue ?? '')
|
||||
}
|
||||
}, [open, initialValue])
|
||||
|
||||
const parsed = parseManualNetworkAddress(value)
|
||||
// Why: only flag invalid input once the user has typed something — an empty
|
||||
// field on open shouldn't read as an error.
|
||||
const showError = value.trim() !== '' && !parsed.ok
|
||||
|
||||
const submit = (): void => {
|
||||
if (!parsed.ok) {
|
||||
return
|
||||
}
|
||||
onConfirm(parsed.address)
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{translate(
|
||||
'auto.components.mobile.CustomNetworkAddressDialog.title',
|
||||
'Custom network address'
|
||||
)}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{translate(
|
||||
'auto.components.mobile.CustomNetworkAddressDialog.description',
|
||||
'Advertise an address your phone can reach when it is not on the same Wi-Fi — for example a Tailscale hostname or a static IP.'
|
||||
)}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="custom-network-address-input">
|
||||
{translate('auto.components.mobile.CustomNetworkAddressDialog.label', 'Address')}
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-network-address-input"
|
||||
autoFocus
|
||||
value={value}
|
||||
aria-invalid={showError}
|
||||
placeholder={translate(
|
||||
'auto.components.mobile.CustomNetworkAddressDialog.placeholder',
|
||||
'my-mac.ts.net or 192.168.1.50'
|
||||
)}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{/* Why: neutral helper copy that doubles as validation guidance —
|
||||
kept muted (not destructive-red) so a half-typed address doesn't
|
||||
feel like a hard error. */}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{translate(
|
||||
'auto.components.mobile.CustomNetworkAddressDialog.hint',
|
||||
'Enter an IP address or a Tailscale hostname (ends in .ts.net).'
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
||||
{translate('auto.components.mobile.CustomNetworkAddressDialog.cancel', 'Cancel')}
|
||||
</Button>
|
||||
<Button type="button" disabled={!parsed.ok} onClick={submit}>
|
||||
{translate('auto.components.mobile.CustomNetworkAddressDialog.use', 'Use address')}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ArrowLeft, ArrowRight, Copy, RefreshCw } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
import type { MobileNetworkInterface } from '../settings/mobile-network-interface-selection'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'
|
||||
import { AndroidLogo, IosBrandIcon } from './MobileBrandIcons'
|
||||
import { NetworkInterfacePicker } from './NetworkInterfacePicker'
|
||||
import { getChannelTagline, type InstallCopy, type IosChannel } from './mobile-platform-copy'
|
||||
export { HeroIntro } from './MobileHeroIntro'
|
||||
export { HeroPaired, type PairedDevice } from './MobileHeroPairedDevices'
|
||||
@@ -197,34 +197,16 @@ export function HeroFlow({
|
||||
<span className="mp-network-label">
|
||||
{translate('auto.components.mobile.MobileHero.dfd2aa9d5d', 'Network')}
|
||||
</span>
|
||||
<Select
|
||||
value={selectedAddress ?? ''}
|
||||
onValueChange={onSelectedAddressChange}
|
||||
disabled={networkInterfaces.length === 0}
|
||||
>
|
||||
<SelectTrigger
|
||||
size="sm"
|
||||
className="mp-network-select"
|
||||
aria-label={translate(
|
||||
'auto.components.mobile.MobileHero.79d2f480da',
|
||||
'Network interface to advertise'
|
||||
)}
|
||||
>
|
||||
<SelectValue
|
||||
placeholder={translate(
|
||||
'auto.components.mobile.MobileHero.ca85e595a7',
|
||||
'No interfaces found'
|
||||
)}
|
||||
/>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{networkInterfaces.map((iface) => (
|
||||
<SelectItem key={`${iface.name}-${iface.address}`} value={iface.address}>
|
||||
{iface.address} ({iface.name})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<NetworkInterfacePicker
|
||||
networkInterfaces={networkInterfaces}
|
||||
selectedAddress={selectedAddress}
|
||||
onSelectedAddressChange={onSelectedAddressChange}
|
||||
// Why: keep the picker reachable when interface discovery is
|
||||
// empty — "Add custom address…" is the only path to enter a
|
||||
// manual Tailscale hostname / static IP.
|
||||
disabled={false}
|
||||
className="mp-network-select"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className={cn('mp-network-refresh', refreshingNetworkInterfaces && 'is-spinning')}
|
||||
|
||||
@@ -32,6 +32,10 @@ export default function MobilePage(): React.JSX.Element {
|
||||
const [pairLoading, setPairLoading] = useState(false)
|
||||
const [networkInterfaces, setNetworkInterfaces] = useState<MobileNetworkInterface[]>([])
|
||||
const [selectedAddress, setSelectedAddress] = useState<string | undefined>(undefined)
|
||||
// Why: tracks whether `selectedAddress` came from the user typing a
|
||||
// manual value rather than from an OS-enumerated interface, so the
|
||||
// refresh path can keep their choice instead of snapping back to LAN.
|
||||
const [addressIsManual, setAddressIsManual] = useState(false)
|
||||
const [refreshingNetworkInterfaces, setRefreshingNetworkInterfaces] = useState(false)
|
||||
const [devices, setDevices] = useState<PairedDevice[]>([])
|
||||
const [revokingDeviceIds, setRevokingDeviceIds] = useState<string[]>([])
|
||||
@@ -215,9 +219,22 @@ export default function MobilePage(): React.JSX.Element {
|
||||
// Resolve the new address before committing it so we can detect a real
|
||||
// change and remint the QR — otherwise the QR keeps encoding the stale
|
||||
// endpoint after a network refresh swaps the active interface.
|
||||
const newAddress = selectRefreshedNetworkAddress(selectedAddress, result.interfaces)
|
||||
const newAddress = selectRefreshedNetworkAddress(
|
||||
selectedAddress,
|
||||
result.interfaces,
|
||||
addressIsManual
|
||||
)
|
||||
if (mountedRef.current) {
|
||||
// Why: selectRefreshedNetworkAddress can rewrite selectedAddress
|
||||
// (e.g. when a refresh surfaces a tailnet interface and the user
|
||||
// had been on LAN). Re-derive `addressIsManual` from the new
|
||||
// value so the next refresh doesn't snap the user back to LAN
|
||||
// just because they once picked a non-tailnet interface.
|
||||
setSelectedAddress(newAddress)
|
||||
const nextIsManual =
|
||||
newAddress !== undefined &&
|
||||
!result.interfaces.some((iface) => iface.address === newAddress)
|
||||
setAddressIsManual(nextIsManual)
|
||||
}
|
||||
if (newAddress !== selectedAddress && hasGeneratedRef.current && mountedRef.current) {
|
||||
void generatePairing(true, newAddress)
|
||||
@@ -229,7 +246,7 @@ export default function MobilePage(): React.JSX.Element {
|
||||
setRefreshingNetworkInterfaces(false)
|
||||
}
|
||||
}
|
||||
}, [selectedAddress, generatePairing, mountedRef])
|
||||
}, [selectedAddress, generatePairing, mountedRef, addressIsManual])
|
||||
|
||||
useEffect(() => {
|
||||
if (stage !== 'flow') {
|
||||
@@ -241,10 +258,15 @@ export default function MobilePage(): React.JSX.Element {
|
||||
const handleAddressChange = useCallback(
|
||||
(address: string) => {
|
||||
setSelectedAddress(address)
|
||||
// Why: if the picked address is not in the OS-enumerated list, it is
|
||||
// a user-typed manual entry — remember that so the next refresh does
|
||||
// not snap it back to a tailnet/LAN fallback.
|
||||
const isManual = !networkInterfaces.some((iface) => iface.address === address)
|
||||
setAddressIsManual(isManual)
|
||||
// Switching network must remint so the QR encodes the new endpoint.
|
||||
void generatePairing(true, address)
|
||||
},
|
||||
[generatePairing]
|
||||
[generatePairing, networkInterfaces]
|
||||
)
|
||||
|
||||
const copyPairingCode = useCallback(async () => {
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import React, { useState } from 'react'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '../ui/select'
|
||||
import { CustomNetworkAddressDialog } from './CustomNetworkAddressDialog'
|
||||
import type { MobileNetworkInterface } from '../settings/mobile-network-interface-selection'
|
||||
|
||||
// Why: MobileHero (mobile pairing screen) and MobileNetworkInterfaceSection
|
||||
// (Settings → Mobile → Network Interface section) both need the same network
|
||||
// selector. Discovered interfaces come from the OS; the "Add custom address…"
|
||||
// footer opens a dialog for a Tailscale hostname or static IP the OS didn't
|
||||
// surface — the only way to pair across networks. Shared here so both surfaces
|
||||
// pick up the behavior automatically.
|
||||
|
||||
// Why: a sentinel Select value for the footer action. It is never committed as
|
||||
// a real address; selecting it opens the custom-address dialog instead.
|
||||
const ADD_CUSTOM_VALUE = '__add_custom_address__'
|
||||
|
||||
export type NetworkInterfacePickerProps = {
|
||||
networkInterfaces: readonly MobileNetworkInterface[]
|
||||
selectedAddress: string | undefined
|
||||
onSelectedAddressChange: (address: string) => void
|
||||
disabled?: boolean
|
||||
className?: string
|
||||
id?: string
|
||||
}
|
||||
|
||||
function formatInterfaceLabel(iface: MobileNetworkInterface): string {
|
||||
return `${iface.address} (${iface.name})`
|
||||
}
|
||||
|
||||
export function NetworkInterfacePicker({
|
||||
networkInterfaces,
|
||||
selectedAddress,
|
||||
onSelectedAddressChange,
|
||||
disabled = false,
|
||||
className,
|
||||
id
|
||||
}: NetworkInterfacePickerProps): React.JSX.Element {
|
||||
const [dialogOpen, setDialogOpen] = useState(false)
|
||||
|
||||
// Why: a selected address that isn't an OS-enumerated interface is a custom
|
||||
// entry. Render it as a "(custom)" option so the trigger can display it —
|
||||
// Radix Select only shows values that have a matching item.
|
||||
const isCustomSelection =
|
||||
selectedAddress !== undefined &&
|
||||
!networkInterfaces.some((iface) => iface.address === selectedAddress)
|
||||
|
||||
const handleValueChange = (value: string): void => {
|
||||
if (value === ADD_CUSTOM_VALUE) {
|
||||
setDialogOpen(true)
|
||||
return
|
||||
}
|
||||
onSelectedAddressChange(value)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Select value={selectedAddress ?? ''} onValueChange={handleValueChange} disabled={disabled}>
|
||||
<SelectTrigger
|
||||
id={id}
|
||||
size="sm"
|
||||
className={className}
|
||||
aria-label={translate(
|
||||
'auto.components.mobile.NetworkInterfacePicker.trigger-label',
|
||||
'Network address to advertise'
|
||||
)}
|
||||
>
|
||||
<SelectValue
|
||||
placeholder={translate(
|
||||
'auto.components.settings.MobileNetworkInterfaceSection.b2c384cfd6',
|
||||
'No interfaces found'
|
||||
)}
|
||||
/>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{networkInterfaces.map((iface) => (
|
||||
<SelectItem key={`${iface.name}-${iface.address}`} value={iface.address}>
|
||||
{formatInterfaceLabel(iface)}
|
||||
</SelectItem>
|
||||
))}
|
||||
{isCustomSelection ? (
|
||||
<SelectItem value={selectedAddress}>
|
||||
{translate(
|
||||
'auto.components.mobile.NetworkInterfacePicker.custom-option',
|
||||
'{{address}} (custom)',
|
||||
{ address: selectedAddress }
|
||||
)}
|
||||
</SelectItem>
|
||||
) : null}
|
||||
{networkInterfaces.length > 0 || isCustomSelection ? <SelectSeparator /> : null}
|
||||
<SelectItem
|
||||
value={ADD_CUSTOM_VALUE}
|
||||
className="text-muted-foreground focus:text-foreground"
|
||||
>
|
||||
<Plus className="size-3.5" />
|
||||
{translate(
|
||||
'auto.components.mobile.NetworkInterfacePicker.add-custom',
|
||||
'Add custom address…'
|
||||
)}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<CustomNetworkAddressDialog
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
initialValue={isCustomSelection ? selectedAddress : undefined}
|
||||
onConfirm={onSelectedAddressChange}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,76 +1,98 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import '@testing-library/jest-dom/vitest'
|
||||
|
||||
import React from 'react'
|
||||
import { afterEach, describe, it, expect, vi } from 'vitest'
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { MobileNetworkInterfaceSection } from './MobileNetworkInterfaceSection'
|
||||
import type { MobileNetworkInterface } from './mobile-network-interface-selection'
|
||||
import { TooltipProvider } from '../ui/tooltip'
|
||||
|
||||
type ReactElementLike = {
|
||||
type: unknown
|
||||
props: Record<string, unknown>
|
||||
}
|
||||
// Why: Radix Select/Dialog portal their content to <body> and don't always
|
||||
// unmount synchronously when the test container tears down, so content can
|
||||
// leak between tests. Forcing cleanup restores the empty DOM before each render.
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
function visit(node: unknown, cb: (node: ReactElementLike) => void): void {
|
||||
if (node == null || typeof node === 'string' || typeof node === 'number') {
|
||||
return
|
||||
}
|
||||
if (Array.isArray(node)) {
|
||||
node.forEach((entry) => visit(entry, cb))
|
||||
return
|
||||
}
|
||||
const element = node as ReactElementLike
|
||||
cb(element)
|
||||
if (element.props?.children) {
|
||||
visit(element.props.children, cb)
|
||||
}
|
||||
}
|
||||
const LAN: MobileNetworkInterface = { name: 'en0', address: '192.168.1.24' }
|
||||
const TAILNET: MobileNetworkInterface = { name: 'tailscale0', address: '100.64.1.20' }
|
||||
|
||||
function collectText(node: unknown): string {
|
||||
if (node == null || typeof node === 'boolean') {
|
||||
return ''
|
||||
function renderSection(
|
||||
overrides: Partial<React.ComponentProps<typeof MobileNetworkInterfaceSection>> = {}
|
||||
) {
|
||||
const onSelectedAddressChange = vi.fn()
|
||||
const onRefreshNetworkInterfaces = vi.fn()
|
||||
const onGenerateQr = vi.fn()
|
||||
const props: React.ComponentProps<typeof MobileNetworkInterfaceSection> = {
|
||||
networkInterfaces: [LAN, TAILNET],
|
||||
selectedAddress: TAILNET.address,
|
||||
onSelectedAddressChange,
|
||||
refreshingNetworkInterfaces: false,
|
||||
onRefreshNetworkInterfaces,
|
||||
loading: false,
|
||||
hasQrCode: false,
|
||||
onGenerateQr,
|
||||
...overrides
|
||||
}
|
||||
if (typeof node === 'string' || typeof node === 'number') {
|
||||
return String(node)
|
||||
}
|
||||
if (Array.isArray(node)) {
|
||||
return node.map(collectText).join('')
|
||||
}
|
||||
const element = node as ReactElementLike
|
||||
return collectText(element.props?.children)
|
||||
}
|
||||
|
||||
function findByAriaLabel(node: unknown, ariaLabel: string): ReactElementLike {
|
||||
let found: ReactElementLike | null = null
|
||||
visit(node, (entry) => {
|
||||
if (entry.props['aria-label'] === ariaLabel) {
|
||||
found = entry
|
||||
}
|
||||
})
|
||||
if (!found) {
|
||||
throw new Error(`element not found: ${ariaLabel}`)
|
||||
}
|
||||
return found
|
||||
const user = userEvent.setup()
|
||||
const utils = render(
|
||||
<TooltipProvider>
|
||||
<MobileNetworkInterfaceSection {...props} />
|
||||
</TooltipProvider>
|
||||
)
|
||||
return { ...utils, user, onSelectedAddressChange, onRefreshNetworkInterfaces, onGenerateQr }
|
||||
}
|
||||
|
||||
describe('MobileNetworkInterfaceSection', () => {
|
||||
it('shows refreshed tailnet interfaces and wires the refresh action', () => {
|
||||
const onRefreshNetworkInterfaces = vi.fn()
|
||||
const tree = MobileNetworkInterfaceSection({
|
||||
networkInterfaces: [
|
||||
{ name: 'en0', address: '192.168.1.24' },
|
||||
{ name: 'tailscale0', address: '100.64.1.20' }
|
||||
],
|
||||
selectedAddress: '192.168.1.24',
|
||||
onSelectedAddressChange: vi.fn(),
|
||||
refreshingNetworkInterfaces: false,
|
||||
onRefreshNetworkInterfaces,
|
||||
loading: false,
|
||||
hasQrCode: false,
|
||||
onGenerateQr: vi.fn()
|
||||
})
|
||||
it('renders the trigger with the currently selected address', () => {
|
||||
renderSection()
|
||||
expect(screen.getByRole('combobox')).toHaveTextContent('100.64.1.20 (tailscale0)')
|
||||
})
|
||||
|
||||
expect(collectText(tree)).toContain('100.64.1.20 (tailscale0)')
|
||||
it('renders the (custom) label on the trigger when the selection is a manual address', () => {
|
||||
renderSection({ selectedAddress: 'my-mac.tail-abcd.ts.net' })
|
||||
expect(screen.getByRole('combobox')).toHaveTextContent('my-mac.tail-abcd.ts.net (custom)')
|
||||
})
|
||||
|
||||
const refreshButton = findByAriaLabel(tree, 'Refresh network interfaces')
|
||||
const onClick = refreshButton.props.onClick as () => void
|
||||
onClick()
|
||||
it('commits an OS interface picked from the list', async () => {
|
||||
const { user, onSelectedAddressChange } = renderSection()
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.click(screen.getByRole('option', { name: '192.168.1.24 (en0)' }))
|
||||
expect(onSelectedAddressChange).toHaveBeenCalledWith('192.168.1.24')
|
||||
})
|
||||
|
||||
expect(onRefreshNetworkInterfaces).toHaveBeenCalledTimes(1)
|
||||
it('opens the custom-address dialog from the Add custom address row', async () => {
|
||||
const { user } = renderSection()
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.click(screen.getByRole('option', { name: /add custom address/i }))
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Address')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('confirms a valid custom address typed into the dialog', async () => {
|
||||
const { user, onSelectedAddressChange } = renderSection()
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.click(screen.getByRole('option', { name: /add custom address/i }))
|
||||
await user.type(screen.getByLabelText('Address'), 'my-mac.tail-abcd.ts.net')
|
||||
await user.click(screen.getByRole('button', { name: /use address/i }))
|
||||
expect(onSelectedAddressChange).toHaveBeenCalledWith('my-mac.tail-abcd.ts.net')
|
||||
})
|
||||
|
||||
it('disables the confirm button while the typed address is invalid', async () => {
|
||||
const { user, onSelectedAddressChange } = renderSection()
|
||||
await user.click(screen.getByRole('combobox'))
|
||||
await user.click(screen.getByRole('option', { name: /add custom address/i }))
|
||||
await user.type(screen.getByLabelText('Address'), 'not an address')
|
||||
expect(screen.getByRole('button', { name: /use address/i })).toBeDisabled()
|
||||
await user.click(screen.getByRole('button', { name: /use address/i }))
|
||||
expect(onSelectedAddressChange).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows No interfaces found when the list is empty', () => {
|
||||
renderSection({ networkInterfaces: [], selectedAddress: undefined })
|
||||
expect(screen.getByRole('combobox')).toHaveTextContent(/no interfaces found/i)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import React from 'react'
|
||||
import { ExternalLink, Loader2, QrCode, RefreshCw, Wifi } from 'lucide-react'
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '../ui/accordion'
|
||||
import { Button } from '../ui/button'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'
|
||||
import type { MobileNetworkInterface } from './mobile-network-interface-selection'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { NetworkInterfacePicker } from '../mobile/NetworkInterfacePicker'
|
||||
import type { MobileNetworkInterface } from './mobile-network-interface-selection'
|
||||
|
||||
const TAILSCALE_DOWNLOAD_URL = 'https://tailscale.com/download'
|
||||
|
||||
@@ -19,10 +20,6 @@ type MobileNetworkInterfaceSectionProps = {
|
||||
onGenerateQr: () => void
|
||||
}
|
||||
|
||||
function formatInterfaceLabel(iface: MobileNetworkInterface): string {
|
||||
return `${iface.address} (${iface.name})`
|
||||
}
|
||||
|
||||
export function MobileNetworkInterfaceSection({
|
||||
networkInterfaces,
|
||||
selectedAddress,
|
||||
@@ -52,25 +49,12 @@ export function MobileNetworkInterfaceSection({
|
||||
</p>
|
||||
<div className="space-y-3">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Select value={selectedAddress} onValueChange={onSelectedAddressChange}>
|
||||
<SelectTrigger size="sm" className="min-w-[220px]">
|
||||
<SelectValue
|
||||
placeholder={translate(
|
||||
'auto.components.settings.MobileNetworkInterfaceSection.b2c384cfd6',
|
||||
'No interfaces found'
|
||||
)}
|
||||
/>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{networkInterfaces.map((iface) => (
|
||||
<SelectItem key={`${iface.name}-${iface.address}`} value={iface.address}>
|
||||
{formatInterfaceLabel(iface)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{/* Why: VPN/tailnet interfaces can appear after this pane mounts.
|
||||
Re-enumerating OS state here avoids requiring an Orca restart. */}
|
||||
<NetworkInterfacePicker
|
||||
networkInterfaces={networkInterfaces}
|
||||
selectedAddress={selectedAddress}
|
||||
onSelectedAddressChange={onSelectedAddressChange}
|
||||
className="min-w-[220px] justify-between font-normal"
|
||||
/>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { selectRefreshedNetworkAddress } from './mobile-network-interface-selection'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
selectRefreshedNetworkAddress,
|
||||
type MobileNetworkInterface
|
||||
} from './mobile-network-interface-selection'
|
||||
|
||||
const LAN = { name: 'en0', address: '192.168.1.24' }
|
||||
const TAILNET = { name: 'tailscale0', address: '100.64.1.20' }
|
||||
const LAN: MobileNetworkInterface = { name: 'en0', address: '192.168.1.24' }
|
||||
const TAILNET: MobileNetworkInterface = { name: 'tailscale0', address: '100.64.1.20' }
|
||||
|
||||
describe('selectRefreshedNetworkAddress', () => {
|
||||
// Why: regression for the manual-address branch the PR adds — a
|
||||
// transient empty refresh must not clobber the user's typed address.
|
||||
it('keeps a manual address when refresh returns no interfaces', () => {
|
||||
expect(selectRefreshedNetworkAddress('my-mac.ts.net', [], true)).toBe('my-mac.ts.net')
|
||||
})
|
||||
|
||||
// Existing behavior is preserved verbatim from the spec.
|
||||
it('keeps the selected address when refresh discovers a new tailnet interface', () => {
|
||||
expect(selectRefreshedNetworkAddress(LAN.address, [LAN, TAILNET])).toBe(LAN.address)
|
||||
})
|
||||
|
||||
@@ -7,12 +7,22 @@ export type MobileNetworkInterface = {
|
||||
|
||||
export function selectRefreshedNetworkAddress(
|
||||
currentAddress: string | undefined,
|
||||
interfaces: readonly MobileNetworkInterface[]
|
||||
interfaces: readonly MobileNetworkInterface[],
|
||||
// Why: callers that explicitly know the user picked a manual address
|
||||
// (not an OS-enumerated one) pass this so the refresh path keeps their
|
||||
// selection instead of snapping back to a tailnet/LAN fallback.
|
||||
currentAddressIsManual: boolean = false
|
||||
): string | undefined {
|
||||
// Why: an empty refresh result usually means discovery is transiently
|
||||
// unavailable, not that the user wants to drop their selection. Keep the
|
||||
// manual address so a recovering discovery doesn't clobber it.
|
||||
if (interfaces.length === 0) {
|
||||
return undefined
|
||||
return currentAddressIsManual ? currentAddress : undefined
|
||||
}
|
||||
if (currentAddress && interfaces.some((iface) => iface.address === currentAddress)) {
|
||||
if (
|
||||
currentAddress &&
|
||||
(currentAddressIsManual || interfaces.some((iface) => iface.address === currentAddress))
|
||||
) {
|
||||
return currentAddress
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -99,7 +99,10 @@ function CommandInput({
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={cn('flex items-center border-b border-border px-3', wrapperClassName)}
|
||||
className={cn(
|
||||
'flex items-center border-b border-border bg-muted/30 px-3 py-1',
|
||||
wrapperClassName
|
||||
)}
|
||||
data-cmdk-input-wrapper=""
|
||||
>
|
||||
<SearchIcon className={cn('mr-2 h-4 w-4 shrink-0 opacity-50', iconClassName)} />
|
||||
|
||||
@@ -9994,6 +9994,20 @@
|
||||
"cefd048225": "Back",
|
||||
"c5ad56786d": "spinner"
|
||||
}
|
||||
},
|
||||
"CustomNetworkAddressDialog": {
|
||||
"title": "Custom network address",
|
||||
"description": "Advertise an address your phone can reach when it is not on the same Wi-Fi — for example a Tailscale hostname or a static IP.",
|
||||
"label": "Address",
|
||||
"placeholder": "my-mac.ts.net or 192.168.1.50",
|
||||
"hint": "Enter an IP address or a Tailscale hostname (ends in .ts.net).",
|
||||
"cancel": "Cancel",
|
||||
"use": "Use address"
|
||||
},
|
||||
"NetworkInterfacePicker": {
|
||||
"trigger-label": "Network address to advertise",
|
||||
"custom-option": "{{address}} (custom)",
|
||||
"add-custom": "Add custom address…"
|
||||
}
|
||||
},
|
||||
"gitlab": {
|
||||
|
||||
@@ -9994,6 +9994,20 @@
|
||||
"cefd048225": "Atrás",
|
||||
"c5ad56786d": "hilandero"
|
||||
}
|
||||
},
|
||||
"CustomNetworkAddressDialog": {
|
||||
"title": "Dirección de red personalizada",
|
||||
"description": "Anuncia una dirección que tu teléfono pueda alcanzar cuando no esté en la misma red Wi-Fi: por ejemplo, un nombre de host de Tailscale o una IP estática.",
|
||||
"label": "Dirección",
|
||||
"placeholder": "my-mac.ts.net o 192.168.1.50",
|
||||
"hint": "Introduce una dirección IP o un nombre de host de Tailscale (termina en .ts.net).",
|
||||
"cancel": "Cancelar",
|
||||
"use": "Usar dirección"
|
||||
},
|
||||
"NetworkInterfacePicker": {
|
||||
"trigger-label": "Dirección de red para anunciar",
|
||||
"custom-option": "{{address}} (personalizada)",
|
||||
"add-custom": "Añadir dirección personalizada…"
|
||||
}
|
||||
},
|
||||
"gitlab": {
|
||||
|
||||
@@ -9994,6 +9994,20 @@
|
||||
"cefd048225": "戻る",
|
||||
"c5ad56786d": "スピナー"
|
||||
}
|
||||
},
|
||||
"CustomNetworkAddressDialog": {
|
||||
"title": "カスタムネットワークアドレス",
|
||||
"description": "同じ Wi-Fi に接続していないときにスマートフォンから到達できるアドレスを指定します。たとえば Tailscale のホスト名や静的 IP です。",
|
||||
"label": "アドレス",
|
||||
"placeholder": "my-mac.ts.net または 192.168.1.50",
|
||||
"hint": "IP アドレスまたは Tailscale のホスト名(.ts.net で終わる)を入力してください。",
|
||||
"cancel": "キャンセル",
|
||||
"use": "アドレスを使用"
|
||||
},
|
||||
"NetworkInterfacePicker": {
|
||||
"trigger-label": "通知するネットワークアドレス",
|
||||
"custom-option": "{{address}}(カスタム)",
|
||||
"add-custom": "カスタムアドレスを追加…"
|
||||
}
|
||||
},
|
||||
"gitlab": {
|
||||
|
||||
@@ -9994,6 +9994,20 @@
|
||||
"cefd048225": "뒤로",
|
||||
"c5ad56786d": "스피너"
|
||||
}
|
||||
},
|
||||
"CustomNetworkAddressDialog": {
|
||||
"title": "사용자 지정 네트워크 주소",
|
||||
"description": "같은 Wi-Fi에 있지 않을 때 휴대폰이 연결할 수 있는 주소를 알립니다. 예: Tailscale 호스트 이름 또는 고정 IP.",
|
||||
"label": "주소",
|
||||
"placeholder": "my-mac.ts.net 또는 192.168.1.50",
|
||||
"hint": "IP 주소 또는 Tailscale 호스트 이름(.ts.net으로 끝남)을 입력하세요.",
|
||||
"cancel": "취소",
|
||||
"use": "주소 사용"
|
||||
},
|
||||
"NetworkInterfacePicker": {
|
||||
"trigger-label": "알릴 네트워크 주소",
|
||||
"custom-option": "{{address}} (사용자 지정)",
|
||||
"add-custom": "사용자 지정 주소 추가…"
|
||||
}
|
||||
},
|
||||
"gitlab": {
|
||||
|
||||
@@ -9994,6 +9994,20 @@
|
||||
"cefd048225": "返回",
|
||||
"c5ad56786d": "旋转器"
|
||||
}
|
||||
},
|
||||
"CustomNetworkAddressDialog": {
|
||||
"title": "自定义网络地址",
|
||||
"description": "指定当手机不在同一 Wi-Fi 时可以访问的地址,例如 Tailscale 主机名或静态 IP。",
|
||||
"label": "地址",
|
||||
"placeholder": "my-mac.ts.net 或 192.168.1.50",
|
||||
"hint": "请输入 IP 地址或 Tailscale 主机名(以 .ts.net 结尾)。",
|
||||
"cancel": "取消",
|
||||
"use": "使用地址"
|
||||
},
|
||||
"NetworkInterfacePicker": {
|
||||
"trigger-label": "要公布的网络地址",
|
||||
"custom-option": "{{address}}(自定义)",
|
||||
"add-custom": "添加自定义地址…"
|
||||
}
|
||||
},
|
||||
"gitlab": {
|
||||
|
||||
Reference in New Issue
Block a user