Fix mobile connection selector showing "(Connected)" when not connected (#1029)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: thomasnordquist <7721625+thomasnordquist@users.noreply.github.com>
This commit is contained in:
Copilot
2026-01-26 22:57:37 +01:00
committed by GitHub
parent f079a9239c
commit 9e79d3fa33

View File

@@ -36,6 +36,8 @@ interface Props {
classes: any classes: any
connections: Array<{ id: string; name?: string; host?: string }> connections: Array<{ id: string; name?: string; host?: string }>
currentConnectionId?: string currentConnectionId?: string
isConnected: boolean
currentActiveConnectionId?: string
actions: typeof connectionManagerActions actions: typeof connectionManagerActions
} }
@@ -54,7 +56,7 @@ class MobileConnectionSelector extends React.PureComponent<Props, {}> {
} }
public render() { public render() {
const { classes, connections, currentConnectionId } = this.props const { classes, connections, currentConnectionId, isConnected, currentActiveConnectionId } = this.props
if (!connections || connections.length === 0) { if (!connections || connections.length === 0) {
return null return null
@@ -77,12 +79,19 @@ class MobileConnectionSelector extends React.PureComponent<Props, {}> {
}} }}
> >
{connections.map(conn => { {connections.map(conn => {
const isConnected = conn.id === currentConnectionId // Show "(Connected)" only when:
// 1. This connection is selected in the UI (currentConnectionId)
// 2. There's an active MQTT connection (isConnected)
// 3. The active connection matches this connection (currentActiveConnectionId)
// This prevents showing "Connected" when a connection is selected but not connected,
// or when switching between connections during a disconnect/reconnect cycle.
const showConnectedStatus =
conn.id === currentConnectionId && isConnected && conn.id === currentActiveConnectionId
const displayName = this.getConnectionDisplayName(conn) const displayName = this.getConnectionDisplayName(conn)
return ( return (
<MenuItem key={conn.id} value={conn.id}> <MenuItem key={conn.id} value={conn.id}>
{displayName} {displayName}
{isConnected && ' (Connected)'} {showConnectedStatus && ' (Connected)'}
</MenuItem> </MenuItem>
) )
})} })}
@@ -102,7 +111,8 @@ class MobileConnectionSelector extends React.PureComponent<Props, {}> {
const mapStateToProps = (state: AppState) => { const mapStateToProps = (state: AppState) => {
const connectionManager = state.connectionManager const connectionManager = state.connectionManager
const connections = connectionManager && connectionManager.connections const connections =
connectionManager && connectionManager.connections
? Object.values(connectionManager.connections).map(conn => ({ ? Object.values(connectionManager.connections).map(conn => ({
id: conn.id, id: conn.id,
name: conn.name, name: conn.name,
@@ -113,6 +123,8 @@ const mapStateToProps = (state: AppState) => {
return { return {
connections, connections,
currentConnectionId: state.connectionManager?.selected, currentConnectionId: state.connectionManager?.selected,
isConnected: state.connection.connected,
currentActiveConnectionId: state.connection.connectionId,
} }
} }
@@ -122,4 +134,7 @@ const mapDispatchToProps = (dispatch: any) => {
} }
} }
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(MobileConnectionSelector)) // Using 'as any' here is consistent with other Material-UI + Redux connected components
// in this codebase (see ConnectionSettings.tsx, ProfileList/index.tsx, ChartPanel/index.tsx)
// to work around complex TypeScript type inference issues with the withStyles + connect HOCs
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(MobileConnectionSelector) as any)