UI: Avoid duplicate Windows major version in machine OS label (e.g., 'Windows 11 Pro (26100)')

This commit is contained in:
codex-bot 2025-10-21 09:08:59 -03:00
parent 66bf0cd9e1
commit 904c2ef457
2 changed files with 48 additions and 5 deletions

View file

@ -353,6 +353,24 @@ type WindowsOsInfo = {
experience?: string
}
function formatOsVersionDisplay(osName: string | null | undefined, osVersion: string | null | undefined) {
const name = (osName ?? "").trim()
const version = (osVersion ?? "").trim()
if (!version) return ""
// If Windows and version redundantly starts with the same major (e.g., "11 (26100)"), drop leading major
const winMatch = name.match(/^windows\s+(\d+)\b/i)
if (winMatch) {
const major = winMatch[1]
const re = new RegExp(`^\\s*${major}(?:\\b|\\.|-_|\\s)+(.*)$`, "i")
const m = version.match(re)
if (m) {
const rest = (m[1] ?? "").trim()
return rest
}
}
return version
}
function parseWindowsOsInfo(raw: unknown): WindowsOsInfo | null {
if (!raw) return null
const parseRecord = (value: Record<string, unknown>) => {
@ -1581,7 +1599,8 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
const summaryChips = useMemo(() => {
const chips: Array<{ key: string; label: string; value: string; icon: ReactNode; tone?: "warning" | "muted" }> = []
const osName = osNameDisplay || "Sistema desconhecido"
const osVersion = machine?.osVersion ?? windowsVersionLabel ?? ""
const osVersionRaw = machine?.osVersion ?? windowsVersionLabel ?? ""
const osVersion = formatOsVersionDisplay(osNameDisplay, osVersionRaw)
chips.push({
key: "os",
label: "Sistema",
@ -3193,7 +3212,11 @@ function MachineCard({ machine, companyName }: { machine: MachinesQueryItem; com
<CardContent className="flex grow flex-col gap-3 text-sm">
<div className="flex flex-wrap items-center gap-2">
<Badge variant="outline" className="border-slate-300 bg-slate-100 text-xs font-medium text-slate-700">
{machine.osName ?? "SO"} {machine.osVersion ?? ""}
{(() => {
const name = machine.osName ?? "SO"
const ver = formatOsVersionDisplay(machine.osName, machine.osVersion)
return [name, ver].filter(Boolean).join(" ").trim()
})()}
</Badge>
{machine.architecture ? (
<Badge variant="outline" className="border-slate-300 bg-slate-100 text-xs font-medium text-slate-700">