TypeScript
feat(web): show a newly created pairing link without expanding the client list (#30498)
Julius Marminge322f6544dfad
diff --git a/apps/web/src/components/settings/AuthorizedClientsSettings.tsx b/apps/web/src/components/settings/AuthorizedClientsSettings.tsxindex 61fa056cff6..171bdeab60f 100644--- a/apps/web/src/components/settings/AuthorizedClientsSettings.tsx+++ b/apps/web/src/components/settings/AuthorizedClientsSettings.tsx@@ -123,6 +123,7 @@ function endpointRowClassName(isAvailable: boolean) {type PairingLinkListRowProps = {pairingLink: ServerPairingLinkRecord;credential: string | undefined;+ defaultShareOpen: boolean;endpointUrl: string | null | undefined;endpoints: ReadonlyArray<AdvertisedEndpoint>;defaultEndpointKey: string | null;@@ -134,6 +135,7 @@ type PairingLinkListRowProps = {const PairingLinkListRow = memo(function PairingLinkListRow({pairingLink,credential,+ defaultShareOpen,endpointUrl,endpoints,defaultEndpointKey,@@ -144,7 +146,7 @@ const PairingLinkListRow = memo(function PairingLinkListRow({const nowMs = useNowSecond();const expiresAtMs = new Date(pairingLink.expiresAt).getTime();const [isRevealDialogOpen, setIsRevealDialogOpen] = useState(false);- const [isQrPanelOpen, setIsQrPanelOpen] = useState(false);+ const [isQrPanelOpen, setIsQrPanelOpen] = useState(defaultShareOpen);const [qrEndpointId, setQrEndpointId] = useState<string | null>(null);const qrPanelId = useId();@@ -791,6 +793,7 @@ type PairingClientsListProps = {isLoading: boolean;pairingLinks: ReadonlyArray<ServerPairingLinkRecord>;createdPairingCredentials: ReadonlyMap<string, string>;+ sharedPairingLinkId: string | null;clientSessions: ReadonlyArray<ServerClientSessionRecord>;revokingPairingLinkId: string | null;revokingClientSessionId: string | null;@@ -806,6 +809,7 @@ export const PairingClientsList = memo(function PairingClientsList({isLoading,pairingLinks,createdPairingCredentials,+ sharedPairingLinkId,clientSessions,revokingPairingLinkId,revokingClientSessionId,@@ -820,6 +824,7 @@ export const PairingClientsList = memo(function PairingClientsList({key={pairingLink.id}pairingLink={pairingLink}credential={createdPairingCredentials.get(pairingLink.id)}+ defaultShareOpen={pairingLink.id === sharedPairingLinkId}endpointUrl={endpointUrl}endpoints={endpoints}defaultEndpointKey={defaultEndpointKey}diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsxindex 8df75864623..5409f6ec530 100644--- a/apps/web/src/components/settings/ConnectionsSettings.tsx+++ b/apps/web/src/components/settings/ConnectionsSettings.tsx@@ -226,8 +226,10 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |const [createdPairingCredentials, setCreatedPairingCredentials] = useState<ReadonlyMap<string, string>>(() => new Map());+ const [newestPairingLinkId, setNewestPairingLinkId] = useState<string | null>(null);const handlePairingLinkCreated = (created: AuthPairingCredentialResult) => {setCreatedPairingCredentials((current) => new Map(current).set(created.id, created.credential));+ setNewestPairingLinkId(created.id);};const [revokingDesktopPairingLinkId, setRevokingDesktopPairingLinkId] = useState<string | null>(null,@@ -928,6 +930,29 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |managed={tailscaleHttpsEndpoint?.status === "available" ? undefined : remoteClientsDenial}/>);+ const newestPairingLink = visibleDesktopPairingLinks.find(+ (pairingLink) => pairingLink.id === newestPairingLinkId,+ );+ const renderPairingClientsList = (+ pairingLinks: typeof visibleDesktopPairingLinks,+ clientSessions: typeof desktopClientSessions,+ ) => (+ <PairingClientsList+ endpointUrl={desktopServerExposureState?.endpointUrl}+ endpoints={visibleDesktopAdvertisedEndpoints}+ defaultEndpointKey={defaultDesktopAdvertisedEndpointKey}+ isLoading={isLoadingDesktopAccessManagement}+ pairingLinks={pairingLinks}+ createdPairingCredentials={createdPairingCredentials}+ sharedPairingLinkId={newestPairingLinkId}+ clientSessions={clientSessions}+ revokingPairingLinkId={revokingDesktopPairingLinkId}+ revokingClientSessionId={revokingDesktopClientSessionId}+ onRevokePairingLink={handleRevokeDesktopPairingLink}+ onRevokeClientSession={handleRevokeDesktopClientSession}+ canRevoke={canWriteAccess}+ />+ );const renderAuthorizedClients = () => (<>{desktopAccessManagementError ? (@@ -935,20 +960,7 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |<p className="text-xs text-destructive">{desktopAccessManagementError}</p></div>) : null}- <PairingClientsList- endpointUrl={desktopServerExposureState?.endpointUrl}- endpoints={visibleDesktopAdvertisedEndpoints}- defaultEndpointKey={defaultDesktopAdvertisedEndpointKey}- isLoading={isLoadingDesktopAccessManagement}- pairingLinks={visibleDesktopPairingLinks}- createdPairingCredentials={createdPairingCredentials}- clientSessions={desktopClientSessions}- revokingPairingLinkId={revokingDesktopPairingLinkId}- revokingClientSessionId={revokingDesktopClientSessionId}- onRevokePairingLink={handleRevokeDesktopPairingLink}- onRevokeClientSession={handleRevokeDesktopClientSession}- canRevoke={canWriteAccess}- />+ {renderPairingClientsList(visibleDesktopPairingLinks, desktopClientSessions)}</>);const renderNetworkAccessRow = () => (@@ -1153,6 +1165,11 @@ export function ConnectionsSettings({ view }: { readonly view: "environments" |<FoldedSettingsSectionid="authorized-clients"title="Authorized clients"+ collapsedContent={+ canReadAccess && newestPairingLink+ ? renderPairingClientsList([newestPairingLink], [])+ : undefined+ }summary={summarizeAuthorizedClients(desktopClientSessions,visibleDesktopPairingLinks,diff --git a/apps/web/src/components/settings/FoldedSettingsSection.tsx b/apps/web/src/components/settings/FoldedSettingsSection.tsxindex ce68f5bedb1..dd9c6e5de15 100644--- a/apps/web/src/components/settings/FoldedSettingsSection.tsx+++ b/apps/web/src/components/settings/FoldedSettingsSection.tsx@@ -12,6 +12,7 @@ export function FoldedSettingsSection({summary,control,headerPlacement = "inside",+ collapsedContent,children,}: {readonly id: string;@@ -19,6 +20,8 @@ export function FoldedSettingsSection({readonly summary?: string | null;readonly control?: ReactNode;readonly headerPlacement?: "inside" | "outside";+ /** Shown under the header only while folded. */+ readonly collapsedContent?: ReactNode;readonly children: ReactNode;}) {const [open, setOpen] = useState(false);@@ -82,6 +85,9 @@ export function FoldedSettingsSection({</CollapsibleTrigger>{control ? <div className="flex shrink-0 items-center">{control}</div> : null}</div>+ {!open && collapsedContent ? (+ <div className="border-t border-border/50 empty:hidden">{collapsedContent}</div>+ ) : null}<CollapsiblePanel><div className="border-t border-border/50 [&>*+*]:border-t [&>*+*]:border-border/50">{children}