From 69ff97a4453416c22419e886256f4a7b77b0ab2f Mon Sep 17 00:00:00 2001 From: Jeremias Date: Wed, 25 Nov 2026 01:44:14 +0100 Subject: [PATCH 1/2] feat(testing-view): categorize messages and add icons --- backend/cmd/setup_vehicle.go | 1 + backend/pkg/broker/topics/message/update.go | 13 ++++++++++++- backend/pkg/vehicle/constructor.go | 7 +++++++ backend/pkg/vehicle/notification.go | 17 ++++++++++++++--- backend/pkg/vehicle/vehicle.go | 1 + .../rightSidebar/sections/MessageItem.tsx | 16 ++++++++++++++-- frontend/testing-view/src/types/data/message.ts | 1 + 7 files changed, 50 insertions(+), 6 deletions(-) diff --git a/backend/cmd/setup_vehicle.go b/backend/cmd/setup_vehicle.go index 64408a66c..0cdaadcad 100644 --- a/backend/cmd/setup_vehicle.go +++ b/backend/cmd/setup_vehicle.go @@ -104,6 +104,7 @@ func configureVehicle( vehicle.SetLogger(loggerHandler) vehicle.SetUpdateFactory(updateFactory) vehicle.SetIpToBoardId(ipToBoardID) + vehicle.SetBoardAddresses(adj.Info.Addresses) vehicle.SetIdToBoardName(idToBoard) vehicle.SetTransport(transp) diff --git a/backend/pkg/broker/topics/message/update.go b/backend/pkg/broker/topics/message/update.go index 40ae5479a..07b0943d7 100644 --- a/backend/pkg/broker/topics/message/update.go +++ b/backend/pkg/broker/topics/message/update.go @@ -103,12 +103,21 @@ func (update *Update) SetAPI(api abstraction.BrokerAPI) { type pushStruct struct { data any boardName string + category string } func Push(data any, boardName string) *pushStruct { return &pushStruct{data: data, boardName: boardName} } +func PushFromBoard(packet *protection.Packet, boardName string) *pushStruct { + category := "protection" + if packet.Kind == protection.WarningKind { + category = "message" + } + return &pushStruct{data: packet, boardName: boardName, category: category} +} + func (push *pushStruct) Topic() abstraction.BrokerTopic { return UpdateName } @@ -117,7 +126,8 @@ func (push *pushStruct) Data(boardName string) wrapper { switch data := push.data.(type) { case *protection.Packet: return wrapper{ - Kind: string(data.Severity()), + Category: push.category, + Kind: string(data.Severity()), Payload: struct { Kind string `json:"kind"` Data any `json:"data"` @@ -143,6 +153,7 @@ func (push *pushStruct) Data(boardName string) wrapper { } type wrapper struct { + Category string `json:"category,omitempty"` Kind string `json:"kind"` Payload any `json:"payload"` Board string `json:"board"` diff --git a/backend/pkg/vehicle/constructor.go b/backend/pkg/vehicle/constructor.go index 8468195f9..bc6595476 100644 --- a/backend/pkg/vehicle/constructor.go +++ b/backend/pkg/vehicle/constructor.go @@ -75,3 +75,10 @@ func (vehicle *Vehicle) SetIpToBoardId(ipToBoardId map[string]abstraction.BoardI vehicle.ipToBoardId = ipToBoardId vehicle.trace.Info().Msg("set ip to board id") } + +func (vehicle *Vehicle) SetBoardAddresses(addresses map[string]string) { + vehicle.ipToBoardName = make(map[string]string, len(addresses)) + for name, ip := range addresses { + vehicle.ipToBoardName[ip] = name + } +} diff --git a/backend/pkg/vehicle/notification.go b/backend/pkg/vehicle/notification.go index 52e4a9948..36d1d145c 100644 --- a/backend/pkg/vehicle/notification.go +++ b/backend/pkg/vehicle/notification.go @@ -3,6 +3,7 @@ package vehicle import ( "errors" "fmt" + "net" "strings" "github.com/HyperloopUPV-H8/h9-backend/pkg/abstraction" @@ -82,8 +83,18 @@ func (vehicle *Vehicle) handlePacketNotification(notification transport.PacketNo } case *protection.Packet: - boardID := vehicle.ipToBoardId[strings.Split(notification.From, ":")[0]] - err := vehicle.broker.Push(message_topic.Push(p, vehicle.idToBoardName[p.Id()])) + ip, _, err := net.SplitHostPort(notification.From) + if err != nil { + ip = notification.From + } + boardName := vehicle.ipToBoardName[ip] + if boardName == "" { + boardName = vehicle.idToBoardName[p.Id()] + } + if boardName == "" { + boardName = ip + } + err = vehicle.broker.Push(message_topic.PushFromBoard(p, boardName)) if err != nil { vehicle.trace.Error().Stack().Err(err).Msg("broker push") return errors.Join(fmt.Errorf("update protection to frontend (%s protection with id %d and kind %d from %s to %s)", p.Severity(), p.Id(), p.Kind, notification.From, notification.To), err) @@ -92,7 +103,7 @@ func (vehicle *Vehicle) handlePacketNotification(notification transport.PacketNo // Log protection err = vehicle.logger.PushRecord(&protection_logger.Record{ Packet: p, - BoardId: boardID, + BoardId: vehicle.ipToBoardId[ip], From: notification.From, To: notification.To, Timestamp: notification.Timestamp, diff --git a/backend/pkg/vehicle/vehicle.go b/backend/pkg/vehicle/vehicle.go index 65fbfdd81..4bc7c73f8 100644 --- a/backend/pkg/vehicle/vehicle.go +++ b/backend/pkg/vehicle/vehicle.go @@ -31,6 +31,7 @@ type Vehicle struct { updateFactory *update_factory.UpdateFactory idToBoardName map[abstraction.PacketId]string ipToBoardId map[string]abstraction.BoardId + ipToBoardName map[string]string BlcuId abstraction.BoardId trace zerolog.Logger diff --git a/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx b/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx index 65b1e0aa2..4866d9331 100644 --- a/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx +++ b/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx @@ -6,6 +6,7 @@ import { } from "@hyperloopupv/frontend-kit"; import { ChevronDown } from "@hyperloopupv/frontend-kit/icons"; import { cn } from "@hyperloopupv/frontend-kit/lib"; +import { Rows3, Shield, type LucideIcon } from "lucide-react"; import { useState } from "react"; import { MESSAGE_KIND_COLORS } from "../../../../../constants/messageKindColors"; import { formatTimestamp } from "../../../../../lib/utils"; @@ -18,6 +19,16 @@ interface MessageItemProps { export const MessageItem = ({ message }: MessageItemProps) => { const [isOpen, setIsOpen] = useState(false); + let label = "BACKEND (backend)"; + let Icon: LucideIcon | undefined = Rows3; + if (message.category === "protection") { + label = `PROTECTION (${message.board})`; + Icon = Shield; + } else if (message.category === "message") { + label = `MESSAGE (${message.board})`; + Icon = undefined; + } + const renderMessageContent = (payload: any) => { // 1. Simple string (Info messages) if (typeof payload === "string") return payload; @@ -62,9 +73,10 @@ export const MessageItem = ({ message }: MessageItemProps) => { - {message.board} + {Icon && diff --git a/frontend/testing-view/src/types/data/message.ts b/frontend/testing-view/src/types/data/message.ts index 45cbe70e7..419bc876b 100644 --- a/frontend/testing-view/src/types/data/message.ts +++ b/frontend/testing-view/src/types/data/message.ts @@ -40,6 +40,7 @@ export type DetailedPayload = * Definition of a MessagePacket as it arrives from the backend. */ export type MessagePacket = { + category?: "protection" | "message" | "backend"; /** Message type */ kind: "info" | "warning" | "fault" | "ok"; /** For `info` messages, the payload is a string. From 73da1a60ec25156de547da5603149eb9cd000fd3 Mon Sep 17 00:00:00 2001 From: Jeremias Date: Wed, 25 Nov 2026 18:57:53 +0100 Subject: [PATCH 2/2] feat(testing-view): color message badges by kind and new panic kind --- .../src/constants/messageKindColors.ts | 10 ++++ .../rightSidebar/sections/MessageItem.tsx | 54 ++++++++++++------- .../testing-view/src/types/data/message.ts | 3 +- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/frontend/testing-view/src/constants/messageKindColors.ts b/frontend/testing-view/src/constants/messageKindColors.ts index d7d6e6123..78cf35e06 100644 --- a/frontend/testing-view/src/constants/messageKindColors.ts +++ b/frontend/testing-view/src/constants/messageKindColors.ts @@ -5,5 +5,15 @@ export const MESSAGE_KIND_COLORS: Record = { info: "border-blue-500 hover:bg-blue-500/5", warning: "border-yellow-500 hover:bg-yellow-500/5", fault: "border-red-500 hover:bg-red-500/5", + panic: "border-purple-500 hover:bg-purple-500/5", ok: "border-green-500 hover:bg-green-500/5", }; + +/** Colors for the informative badges in the messages section. */ +export const MESSAGE_KIND_BADGES: Record = { + info: "bg-blue-500 text-white", + warning: "bg-yellow-500 text-black", + fault: "bg-red-500 text-white", + panic: "bg-purple-500 text-white", + ok: "bg-green-500 text-white", +}; \ No newline at end of file diff --git a/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx b/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx index 4866d9331..aa12bdd89 100644 --- a/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx +++ b/frontend/testing-view/src/features/workspace/components/rightSidebar/sections/MessageItem.tsx @@ -8,7 +8,7 @@ import { ChevronDown } from "@hyperloopupv/frontend-kit/icons"; import { cn } from "@hyperloopupv/frontend-kit/lib"; import { Rows3, Shield, type LucideIcon } from "lucide-react"; import { useState } from "react"; -import { MESSAGE_KIND_COLORS } from "../../../../../constants/messageKindColors"; +import { MESSAGE_KIND_BADGES, MESSAGE_KIND_COLORS } from "../../../../../constants/messageKindColors"; import { formatTimestamp } from "../../../../../lib/utils"; import type { Message } from "../../../../../types/data/message"; @@ -19,13 +19,13 @@ interface MessageItemProps { export const MessageItem = ({ message }: MessageItemProps) => { const [isOpen, setIsOpen] = useState(false); - let label = "BACKEND (backend)"; + let label = "Backend"; let Icon: LucideIcon | undefined = Rows3; if (message.category === "protection") { - label = `PROTECTION (${message.board})`; + label = `${message.board}`; Icon = Shield; } else if (message.category === "message") { - label = `MESSAGE (${message.board})`; + label = `${message.board}`; Icon = undefined; } @@ -66,18 +66,18 @@ export const MessageItem = ({ message }: MessageItemProps) => { )} > -
+
{formatTimestamp(message.timestamp)} - - - {Icon && + + + {label} + + {message.name} @@ -91,14 +91,30 @@ export const MessageItem = ({ message }: MessageItemProps) => { />
- -
e.stopPropagation()}> -
+ {/* Block (not flex) so the floated icon sits under the time and the + expanded text flows to its right, then wraps underneath it. */} +
+ {Icon && ( + // Same font as the timestamp, so 8ch = width of "HH:MM:SS" + + + )} + +
e.stopPropagation()}> {/* If it's a detailed message, showing the sub-kind can be helpful */} {message.payload && typeof message.payload === "object" && message.payload.kind && ( - + {message.payload.kind.replace("_", " ")} )} @@ -106,8 +122,8 @@ export const MessageItem = ({ message }: MessageItemProps) => { {renderMessageContent(message.payload)}

-
- + +
); diff --git a/frontend/testing-view/src/types/data/message.ts b/frontend/testing-view/src/types/data/message.ts index 419bc876b..5f4fb695f 100644 --- a/frontend/testing-view/src/types/data/message.ts +++ b/frontend/testing-view/src/types/data/message.ts @@ -42,9 +42,10 @@ export type DetailedPayload = export type MessagePacket = { category?: "protection" | "message" | "backend"; /** Message type */ - kind: "info" | "warning" | "fault" | "ok"; + kind: "info" | "warning" | "fault" | "ok" | "panic"; /** For `info` messages, the payload is a string. * For `warning`, `fault` and `ok` messages, the payload is a DetailedPayload. + * For `panic` it's to be defined. */ payload: string | DetailedPayload; board: BoardName;