File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -87,12 +87,40 @@ const ResizableArea: React.FC = () => {
87
87
) ;
88
88
} ;
89
89
90
+
91
+ const WebSocketStatus : React . FC = ( ) => {
92
+ const enabled = useSelector ( selectors . websocketFeatureFlagEnabled ) ;
93
+ const status = useSelector ( selectors . websocketStatusSelector ) ;
94
+
95
+ if ( ! enabled ) { return null ; }
96
+
97
+ const style : React . CSSProperties = {
98
+ position : 'absolute' ,
99
+ left : '1em' ,
100
+ bottom : '1em' ,
101
+ zIndex : '1' ,
102
+ } ;
103
+
104
+ switch ( status . state ) {
105
+ case 'connected' :
106
+ style . color = 'green' ;
107
+ return < div style = { style } > ⬤</ div > ;
108
+ case 'disconnected' :
109
+ style . color = 'grey' ;
110
+ return < div style = { style } > ⬤</ div > ;
111
+ case 'error' :
112
+ style . color = 'red' ;
113
+ return < div style = { style } title = { status . error } > ⬤</ div > ;
114
+ }
115
+ }
116
+
90
117
const Playground : React . FC = ( ) => {
91
118
const showNotifications = useSelector ( selectors . anyNotificationsToShowSelector ) ;
92
119
93
120
return (
94
121
< >
95
122
< div className = { styles . container } >
123
+ < WebSocketStatus />
96
124
< Header />
97
125
< ResizableArea />
98
126
</ div >
Original file line number Diff line number Diff line change @@ -343,3 +343,17 @@ export const useWebsocketSelector = createSelector(
343
343
websocket ,
344
344
( ws ) => ws . connected && ws . featureFlagEnabled ,
345
345
) ;
346
+
347
+ export type WebSocketStatus =
348
+ { state : 'disconnected' } |
349
+ { state : 'connected' } |
350
+ { state : 'error' , error : string } ;
351
+
352
+ export const websocketStatusSelector = createSelector (
353
+ websocket ,
354
+ ( ws ) : WebSocketStatus => {
355
+ if ( ws . error ) { return { state : 'error' , error : ws . error } ; }
356
+ if ( ws . connected ) { return { state : 'connected' } ; }
357
+ return { state : 'disconnected' } ;
358
+ }
359
+ ) ;
You can’t perform that action at this time.
0 commit comments