Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import type { EnvironmentId, EnvironmentMachineKind } from "@t3tools/contracts";
|
|
|
|
import type { SidebarProjectSnapshot } from "~/sidebarProjectGrouping";
|
|
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
|
|
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
|
|
|
/**
|
|
* Machine icon for a project picker row whose group has a member on another
|
|
* environment, with the environment names in a tooltip. Projects that only
|
|
* live on this device render nothing, the rule thread rows use for their
|
|
* machine icon. Callers
|
|
* render it only while the catalog spans environments (see
|
|
* projectGroupsSpanEnvironments), so single-machine users see no change.
|
|
*/
|
|
export function ProjectEnvironmentBadge(props: {
|
|
readonly group: Pick<SidebarProjectSnapshot, "memberProjects">;
|
|
readonly primaryEnvironmentId: EnvironmentId | null;
|
|
readonly machineByEnvironmentId: ReadonlyMap<EnvironmentId, EnvironmentMachineKind>;
|
|
}) {
|
|
// Member order follows registration order and can differ between sessions,
|
|
// so sort by label to keep the icon and tooltip stable.
|
|
const remoteMembers = props.group.memberProjects
|
|
.filter((member) => member.environmentId !== props.primaryEnvironmentId)
|
|
.map((member) => ({ ...member, environmentLabel: member.environmentLabel ?? "Remote" }))
|
|
.sort((a, b) => a.environmentLabel.localeCompare(b.environmentLabel));
|
|
const first = remoteMembers[0];
|
|
if (!first) return null;
|
|
const labels = remoteMembers
|
|
.map((member) => member.environmentLabel)
|
|
.filter((label, index, all) => all.indexOf(label) === index)
|
|
.join(", ");
|
|
const alsoHere = remoteMembers.length < props.group.memberProjects.length;
|
|
const description = `${alsoHere ? "Also on" : "On"} ${labels}`;
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger
|
|
render={
|
|
<span
|
|
role="img"
|
|
aria-label={description}
|
|
className="ml-auto inline-flex shrink-0 items-center text-muted-foreground"
|
|
/>
|
|
}
|
|
>
|
|
<EnvironmentMachineIcon
|
|
aria-hidden
|
|
kind={props.machineByEnvironmentId.get(first.environmentId) ?? "server"}
|
|
className="size-3.5"
|
|
/>
|
|
</TooltipTrigger>
|
|
<TooltipPopup side="top">{description}</TooltipPopup>
|
|
</Tooltip>
|
|
);
|
|
}
|