Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type DesktopWslState, EnvironmentId } from "@t3tools/contracts";
import { describe, expect, it, vi } from "vite-plus/test";
import {
applyWslEnableSelection,
linkedEnvironmentsSectionLabel,
resolveAccessEnvironmentId,
resolveTailscaleServeBaseUrl,
selectQrEndpointOption,
Expand Down Expand Up @@ -201,3 +202,18 @@ describe("resolveAccessEnvironmentId", () => {
);
});
});

describe("linkedEnvironmentsSectionLabel", () => {
it.each([
{ label: "leaves the only environment unnamed", environmentCount: 1, expected: null },
{
label: "names the host when another known environment offers no links",
environmentCount: 2,
expected: "Laptop",
},
])("$label", ({ environmentCount, expected }) => {
expect(linkedEnvironmentsSectionLabel({ hostLabel: "Laptop", environmentCount })).toBe(
expected,
);
});
});
8 changes: 8 additions & 0 deletions apps/web/src/components/settings/ConnectionsSettings.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ export function endpointShareHint(endpoint: AdvertisedEndpoint, url: string): st
}
}

/** Counts every environment the client knows, not only link hosts, since the page lists them all. */
export function linkedEnvironmentsSectionLabel(input: {
readonly hostLabel: string;
readonly environmentCount: number;
}): string | null {
return input.environmentCount > 1 ? input.hostLabel : null;
}

/** An explicit choice while it is listed, else the primary, else a connected environment. */
export function resolveAccessEnvironmentId(input: {
readonly primaryEnvironmentId: EnvironmentId | null;
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/settings/ConnectionsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { isLocalEnvironmentDisabled } from "../../localEnvironment";
import {
applyWslEnableSelection,
isWslSettingsRowVisible,
linkedEnvironmentsSectionLabel,
missingTailscaleEndpointDescription,
resolveAccessEnvironmentId,
resolveLocalVersionStatusLabel,
Expand Down Expand Up @@ -1650,7 +1651,10 @@ function ConnectionsSettingsContent({
<LinkedEnvironmentsSettings
key={environment.environmentId}
environmentId={environment.environmentId}
environmentLabel={peerLinkHosts.length > 1 ? environment.label : null}
environmentLabel={linkedEnvironmentsSectionLabel({
hostLabel: environment.label,
environmentCount: environments.length,
})}
isSearchTarget={index === 0}
/>
))}
Expand Down
Loading